Skip to content

Forbid unsafe code - #16

Merged
monorkin merged 3 commits into
mainfrom
forbid-unsafe
Nov 25, 2026
Merged

monorkin merged 3 commits into
mainfrom
forbid-unsafe

Conversation

@monorkin

Copy link
Copy Markdown
Collaborator

Sets unsafe_code = "forbid" for the whole crate, tests included, and removes the two places that used it:

  • SIGPIPE is reset with the sigpipe crate instead of calling libc::signal, so writebook … | head still exits quietly. libc is dropped.
  • On Windows, sign-in files and folders are limited to the current user with icacls <path> /inheritance:r /grant:r *<SID>:(OI)(CI)F (no (OI)(CI) for files), taking the SID from whoami /user. windows-sys is dropped.

The Windows job's keeps_sign_ins_in_a_folder_only_you_can_read checks the resulting access list is protected and names only the current user with full control.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Windows permission restriction leaves explicit grants to other principals intact, so an existing configuration directory can remain accessible to others despite reporting success.

1 open issue
What changed in this PR

This PR forbids unsafe code throughout the crate, including tests, and replaces the two direct platform API implementations with safe alternatives.

Changes:

  • Use sigpipe::reset() to preserve quiet exits on closed Unix pipes.
  • Use icacls and whoami for Windows sign-in file and folder permissions.
  • Enable unsafe_code = "forbid" and update dependencies.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
src/​main.rs Replace the unsafe SIGPIPE reset with sigpipe::reset().
src/​fsutil/​owner_only.rs Replace Win32 calls with command-based permission handling and cached SID lookup.
Cargo.toml Forbid unsafe code, add sigpipe, and remove direct libc and windows-sys dependencies.
Cargo.lock Record sigpipe and update the crate’s dependency list.

Review effort: Balanced

Comment thread src/fsutil/owner_only.rs Resolved
@monorkin
monorkin merged commit 822a26c into main Nov 25, 2026
12 checks passed
@monorkin
monorkin deleted the forbid-unsafe branch November 25, 2026 20:12
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.

2 participants