Skip to content

fix: apply workspace lints to every crate; random serve token - #1

Open
StephanSchipal wants to merge 1 commit into
sandraschi:mainfrom
StephanSchipal:fix/lints-and-serve-token
Open

StephanSchipal wants to merge 1 commit into
sandraschi:mainfrom
StephanSchipal:fix/lints-and-serve-token

Conversation

@StephanSchipal

Copy link
Copy Markdown

Summary

Two small hardening fixes.

1. Workspace lints now apply to every crate

Cargo.toml declares [workspace.lints.clippy], which denies unwrap_used, expect_used, panic, unimplemented and todo. A workspace lint table only takes effect in crates that opt in with [lints] workspace = true, and none did. So only devcraft-app, through its own #![deny(...)] in main.rs, enforced the rules. devcraft-core and devcraft-mcp weren't checked.

Proof: a temporary pub fn probe() -> u32 { "1".parse().unwrap() } in devcraft-core passed cargo clippy -p devcraft-core -- -D warnings on main. With this change it fails with used unwrap() on a Result value. The probe isn't committed.

  • [lints] workspace = true added to all three crates.
  • New root clippy.toml with allow-unwrap-in-tests, allow-expect-in-tests and allow-panic-in-tests, so test code keeps its unwraps.
  • No existing non-test code needed a change. cargo clippy --workspace --all-targets -- -D warnings passes.

2. devcraft-mcp serve: token from OS randomness, compared without an early exit

mobile_token() created the token as format!("{:x}{:x}", nanos_since_epoch, pid). Anyone who can estimate when the companion first started only has to search a narrow range of timestamps times the possible PIDs. The token gates /api/* on the Tailnet port 11259.

  • new_token() returns 32 bytes from the OS random source as 64 hex characters. It uses getrandom 0.4, which is already in the dependency tree, so this adds no new crate to the build.
  • token_eq() compares the presented token without stopping at the first differing byte, and authorized() uses it for both ?token= and Authorization: Bearer.
  • An existing .devcraft/mobile.token is kept, so current bookmarks keep working. Deleting the file rotates the token; the new URL is printed at serve start-up as before.

Not changed here: the token still travels in the query string (?token=) for the iPad Safari links, so it can end up in browser history.

Observation, not changed

Cargo warns that devcraft-core doesn't use databasecraft-store, thiserror or tokio; those warnings are already on main. No source file in devcraft-core references databasecraft_store. If that holds, dropping the dependency would also let CI and new contributors skip checking out the databasecraft sibling repo.

Test plan

  • New tests in serve.rs: new_token_is_long_random_hex, mobile_token_is_created_random_then_reused (fails on main: 20-character token), token_eq_compares_the_whole_value, authorized_needs_the_exact_token_in_query_or_bearer.
  • cargo test --workspace: 138 passed, 1 ignored (the Today pixel test, ignored on Windows as designed). That's the baseline's 134 plus the 4 new tests.
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all --check
  • Built on Windows against current main of craft-biz, databasecraft and egui_gantt, checked out as siblings.

🤖 Generated with Claude Code

Workspace lints: Cargo.toml declares [workspace.lints.clippy] (deny
unwrap_used, expect_used, panic, unimplemented, todo), but no crate had
`[lints] workspace = true`, so the table applied nowhere. Only
devcraft-app enforced the rules through its own #![deny]. An unwrap()
added to devcraft-core passed `cargo clippy -D warnings`; with this
change it is rejected. A root clippy.toml allows unwrap, expect and
panic in tests. No existing code needed a change.

Serve token: `devcraft-mcp serve` created .devcraft/mobile.token as
hex(nanos since epoch) + hex(pid), which narrows to a small search space
for anyone who can guess when the companion first ran. It is now 32
bytes from the OS random source (getrandom 0.4, already in the tree),
64 hex characters. authorized() compares tokens without an early exit.
An existing token file is kept; deleting it rotates the token.

Tests: new_token shape and uniqueness, mobile_token create-then-reuse,
token_eq, authorized() for query and Bearer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant