Skip to content

🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in config file creation - #135

Merged
ffalcinelli merged 3 commits into
mainfrom
sentinel-secure-file-creation-7628173361031299379
Aug 30, 2026
Merged

🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in config file creation#135
ffalcinelli merged 3 commits into
mainfrom
sentinel-secure-file-creation-7628173361031299379

Conversation

@ffalcinelli

Copy link
Copy Markdown
Owner

🚨 Severity: HIGH
💡 Vulnerability: Time-of-Check to Time-of-Use (TOCTOU) file permission race condition. When creating or modifying the .pinner.toml file, the tool originally wrote the configuration using std::fs::write (which creates files with default, often globally readable permissions) and later restricted the file's access via fs::set_permissions. This left a brief window during which the sensitive configuration—potentially containing GitHub/GitLab tokens or OCI registry passwords—was exposed to unauthorized read access by other users on the system.
🎯 Impact: Potential leakage of sensitive API keys and registry passwords to unprivileged users on multi-user systems.
🔧 Fix: Replaced the standard file writing logic with explicit file opening operations using std::fs::OpenOptions combined with std::os::unix::fs::OpenOptionsExt's .mode(0o600) function on Unix platforms. This guarantees that the configuration file is created with restricted read/write-only owner access right from the start, completely closing the TOCTOU window.
Verification: Code compiles cleanly via cargo check and cargo clippy, and passes all existing automated test cases via cargo test. Appropriate conditional compilation boundaries (#[cfg(unix)] and #[cfg(not(unix))]) were utilized to ensure Windows cross-compatibility. Recorded learning in .Jules/sentinel.md.


PR created automatically by Jules for task 7628173361031299379 started by @ffalcinelli

Updated `src/pipeline/init.rs` and `src/pipeline/scan.rs` to use `std::fs::OpenOptions` combined with `std::os::unix::fs::OpenOptionsExt::mode(0o600)` on Unix platforms when creating the `.pinner.toml` file. This securely sets the permissions directly upon file creation and prevents a Time-of-Check to Time-of-Use (TOCTOU) vulnerability where sensitive data (such as API tokens or OCI passwords) could be temporarily exposed as globally readable before `fs::set_permissions` is called.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@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 2 commits August 30, 2026 04:52
Updated `src/pipeline/init.rs` and `src/pipeline/scan.rs` to use `std::fs::OpenOptions` combined with `std::os::unix::fs::OpenOptionsExt::mode(0o600)` on Unix platforms when creating the `.pinner.toml` file. This securely sets the permissions directly upon file creation and prevents a Time-of-Check to Time-of-Use (TOCTOU) vulnerability where sensitive data (such as API tokens or OCI passwords) could be temporarily exposed as globally readable before `fs::set_permissions` is called.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
Updated `src/pipeline/init.rs` and `src/pipeline/scan.rs` to use `std::fs::OpenOptions` combined with `std::os::unix::fs::OpenOptionsExt::mode(0o600)` on Unix platforms when creating the `.pinner.toml` file. This securely sets the permissions directly upon file creation and prevents a Time-of-Check to Time-of-Use (TOCTOU) vulnerability where sensitive data (such as API tokens or OCI passwords) could be temporarily exposed as globally readable before `fs::set_permissions` is called. Also updated `chacha20` to 0.10.2 to fix a CI failure caused by a yanked crate.

Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.43%. Comparing base (07ac008) to head (b3c0b9c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
- Coverage   88.51%   88.43%   -0.08%     
==========================================
  Files          28       28              
  Lines        2646     2646              
==========================================
- Hits         2342     2340       -2     
- Misses        304      306       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ffalcinelli
ffalcinelli merged commit 767193b into main Aug 30, 2026
4 checks passed
@ffalcinelli
ffalcinelli deleted the sentinel-secure-file-creation-7628173361031299379 branch August 30, 2026 09:54
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