Skip to content

Local hardening: agent data folder and discovery file checks, full database URL redaction, patch updates - #44

Open
Skyfuller1303 wants to merge 3 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:local-security-hardening
Open

Skyfuller1303 wants to merge 3 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:local-security-hardening

Conversation

@Skyfuller1303

Copy link
Copy Markdown

Merge after: none. Independent of the other PRs; based on main. Diff against main.

Local hardening of the agent and the server's configuration, plus patch updates of four dependencies. None of it changes a documented behaviour for a normal single-user install.

What

  • The agent checks its data folder before using it. An existing data folder, and the discovery file local-api.json the app reads to find the agent, are used only if no other user can write to them (on Unix: owner, mode and the folders above). The app's client applies the same check to the discovery file before it connects. If a folder or file does not pass, the agent or the client refuses with a message that names the path and what is wrong, instead of using it. On Windows the check is not applied (the per-user profile already restricts access); the Unix checks cannot run on the Windows development machine and are covered by the Linux and macOS CI jobs.
  • Database URLs are redacted completely. The Debug output of DatabaseConfig hid only the credentials before the last @; the query string, which can carry a user and a password for some drivers, was printed. The whole URL is now hidden, including passwords that contain ? or #.
  • Dependency patch updates in Cargo.lock: rustls 0.23.46, rustls-webpki 0.103.16, webpki-root-certs 1.0.10, tokio 1.53.3 and ctutils. No Cargo.toml change.
  • Tests that write the discovery file now write it the way the agent does; the private.rs tests use a plain cfg(test) so clippy's allow-unwrap-in-tests applies on Linux and macOS.

Testing

  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings pass at this head.
  • cargo test --workspace --locked --no-fail-fast: 966 passed, 0 failed, 2 ignored. The run ends with exit code 101 only because craft-cloud-desktop --lib crashes on Windows (STATUS_ACCESS_VIOLATION). Pristine main crashes the same way (the wgpu problem fixed by Desktop tests: share one wgpu device (fixes a crash in parallel runs on Windows) #35), so it is unrelated to this change.
  • The Unix permission checks were also run in WSL (Linux); Linux and macOS CI jobs cover the rest.

…them, redact the whole database URL

An existing data folder was used as it was: another user who could write to it (or to a folder above it without the sticky bit, or who had put a link there) could replace local-api.json and point apps at a listener of their own. On Unix the agent now refuses a data folder that is a link, belongs to someone else, or can be written by group or others, and apps do not read local-api.json, or send its token anywhere, unless the folder and the file pass the same checks. Windows keeps the %LOCALAPPDATA% rule; std has no owner check there.

DatabaseConfig's Debug output hid only the credentials before the last @; the query string (which can carry user and password) and fragment are now hidden too.

Cargo.lock: patch updates of rustls 0.23.46, rustls-webpki 0.103.16, webpki-root-certs 1.0.10, tokio 1.53.3 and ctutils 0.4.4 for RUSTSEC-2026-0346 to 0349, 0382, 0383, 0385 and 0386.
… whose password holds ? or #, keep the old error for a file at the data path on Windows

old_agent_blobs and recents wrote local-api.json with the umask's mode, which the client now refuses on Unix; they write it 0600. redact_url cut at the first ? or # before it looked for the @, so postgres://cc:pa#ss@db/cc showed the user and the start of the password; the credentials now end at the last @ of the authority, wherever a ? or # sits. DataDir::create treats a file or a dangling link at the data path as an error again on Windows.
…in-tests applies on Unix

The test module was gated by cfg(all(test, unix)); clippy only treats a plain cfg(test) as test code, so Linux and macOS
clippy rejected its unwrap() calls (the Windows build never compiles the module). Mechanical repair of the merge of
fix/local-security-hardening.
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