Skip to content

πŸ›‘οΈ Sentinel: [HIGH] Fix TOCTOU vulnerability in state snapshots#116

Open
bdqnghi wants to merge 4 commits into
mainfrom
sentinel-fix-snapshot-toctou-13766765161458642849
Open

πŸ›‘οΈ Sentinel: [HIGH] Fix TOCTOU vulnerability in state snapshots#116
bdqnghi wants to merge 4 commits into
mainfrom
sentinel-fix-snapshot-toctou-13766765161458642849

Conversation

@bdqnghi
Copy link
Copy Markdown
Contributor

@bdqnghi bdqnghi commented May 4, 2026

🚨 Severity: HIGH
πŸ’‘ Vulnerability: Insecure temporary file creation and incorrect default permissions in state_snapshot.rs. Writing state snapshots using std::fs::write or without restricted creation permissions leaves a brief TOCTOU window and exposes sensitive session data to other users on the system via the default umask. Predictable filenames like .json.tmp also invite symlink attacks.
🎯 Impact: A malicious local user could exploit the symlink attack to overwrite arbitrary files, or simply read the sensitive snapshot data due to the missing permission constraints.
πŸ”§ Fix: Implemented atomic secure file creation using std::fs::OpenOptions with .create_new(true) and .mode(0o600) (on Unix) to enforce strict ownership and prevent TOCTOU race conditions. Filenames are also now randomized using uuid::Uuid::new_v4().
βœ… Verification: Run cargo test --workspace to ensure snapshots continue to function, and verify logic correctly leverages uuid for randomization and atomic rename.


PR created automatically by Jules for task 13766765161458642849 started by @bdqnghi

Replaces the predictable .json.tmp file paths in `state_snapshot.rs` with randomized ones using `uuid::Uuid::new_v4()`, and enforces secure `0o600` file permissions on creation (`O_EXCL`) to mitigate TOCTOU and symlink exploitation vectors.

Co-authored-by: bdqnghi <11867551+bdqnghi@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 3 commits May 4, 2026 16:40
Addresses clippy failures in CI that blocked the previous state snapshots fix PR.
Used `sort_by_key` with `std::cmp::Reverse` instead of `sort_by`, and leveraged the `?` operator for cleaner `Option` unwrapping to satisfy `-D warnings`.

Co-authored-by: bdqnghi <11867551+bdqnghi@users.noreply.github.com>
Addresses clippy failures in CI that blocked the previous state snapshots fix PR.
Used `sort_by_key` with `std::cmp::Reverse` instead of `sort_by`, and leveraged the `?` operator for cleaner `Option` unwrapping to satisfy `-D warnings`.

Co-authored-by: bdqnghi <11867551+bdqnghi@users.noreply.github.com>
Addresses clippy failures in CI that blocked the previous state snapshots fix PR.
Used `sort_by_key` with `std::cmp::Reverse` instead of `sort_by`, and leveraged the `?` operator for cleaner `Option` unwrapping to satisfy `-D warnings`.

Co-authored-by: bdqnghi <11867551+bdqnghi@users.noreply.github.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