Skip to content

noise: restrict persisted config permissions - #127

Merged
benma merged 1 commit into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/restrict-noise-config-permissions
Jul 27, 2026
Merged

noise: restrict persisted config permissions#127
benma merged 1 commit into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/restrict-noise-config-permissions

Conversation

@benma-agent

@benma-agent benma-agent commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Create new Noise config files with mode 0600 on Unix and tighten permissions on
existing files. Apply permissions before truncating existing configs so failures
preserve pairing data. Leave symlinks and their targets untouched.

Document that callers must create the config directory themselves, with mode 0700
recommended on Unix.

@benma
benma requested a review from NickeZ July 18, 2026 10:03

@NickeZ NickeZ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Medium — The permission check has a pathname race. Between symlink_metadata() and set_permissions() at
    src/noise.rs:62, an actor able to modify the directory can replace bitbox.json. set_permissions() may
    then follow a new symlink and chmod an unrelated target, while the originally opened file remains
    permissive. Use handle-based permission changes and a no-follow open.

  • Low — A permission error destroys the existing config. src/noise.rs:118 truncates the file before
    permission enforcement. If chmod subsequently fails, store_config() returns an error but the previous
    pairing data is already gone. Open without truncation, validate permissions first, then truncate/write;
    an atomic temporary-file replacement would be stronger.

Should we also emit a warning/error if the config directory is not 0700, like ssh does for .ssh?

@benma

benma commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
  • Medium — The permission check has a pathname race. Between symlink_metadata() and set_permissions() at
    src/noise.rs:62, an actor able to modify the directory can replace bitbox.json. set_permissions() may
    then follow a new symlink and chmod an unrelated target, while the originally opened file remains
    permissive. Use handle-based permission changes and a no-follow open.
  • Low — A permission error destroys the existing config. src/noise.rs:118 truncates the file before
    permission enforcement. If chmod subsequently fails, store_config() returns an error but the previous
    pairing data is already gone. Open without truncation, validate permissions first, then truncate/write;
    an atomic temporary-file replacement would be stronger.

Should we also emit a warning/error if the config directory is not 0700, like ssh does for .ssh?

Emit the warning where/how?

I'd avoid an error, could be breaking downstream apps or be bad if someone has different needs.

Edit: fixed the "low" issue. For medium issue, codex added the "libc" dep and said it's not easy without it. I don't think that issue is a realistic concern anyway, imo we can ignore it.

@benma-agent
benma-agent force-pushed the benma-agent/restrict-noise-config-permissions branch from 1e87fb1 to 9a33fa9 Compare July 27, 2026 09:09
@NickeZ

NickeZ commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

I guess you want to avoid printing to stderr/stdout. I agree, but since we are writing files the library is already doing I/O so we are already kind of not following best practice.

I think a better design would be for the library to just take a file handle and let the consumer of the app handle opening/closing of files.

@NickeZ NickeZ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@benma

benma commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I agree, but since we are writing files the library is already doing I/O so we are already kind of not following best practice.

It is following best practice, as it's behind a trait, so an app can plug in whatever storage backend for the noise data they want too - the PersistedNoiseConfig is a convenience impl.

Create new Noise config files with mode 0600 on Unix and tighten permissions on
existing files. Apply permissions before truncating existing configs so failures
preserve pairing data. Leave symlinks and their targets untouched.

Document that callers must create the config directory themselves, with mode 0700
recommended on Unix.
@benma-agent
benma-agent force-pushed the benma-agent/restrict-noise-config-permissions branch from 9a33fa9 to 5009eb5 Compare July 27, 2026 10:04
@benma
benma merged commit c79dee2 into BitBoxSwiss:master Jul 27, 2026
3 checks passed
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.

3 participants