Skip to content

🛡️ Sentinel: [CRITICAL] Fix symlink attack vulnerability in atomic file writes#85

Closed
himattm wants to merge 1 commit intomainfrom
sentinel/fix-atomic-write-symlink-17060932732088299257
Closed

🛡️ Sentinel: [CRITICAL] Fix symlink attack vulnerability in atomic file writes#85
himattm wants to merge 1 commit intomainfrom
sentinel/fix-atomic-write-symlink-17060932732088299257

Conversation

@himattm
Copy link
Copy Markdown
Owner

@himattm himattm commented May 4, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The use of predictable temporary file names (appending .tmp to the original path) during atomic writes opens a window for a symlink attack. An attacker with write access to the temporary directory could pre-create a symlink with the predictable name, causing arbitrary files to be overwritten when the temporary file is created.
🎯 Impact: Local privilege escalation or arbitrary file overwrite.
🔧 Fix: Replaced predictable temporary file creation with os.CreateTemp, ensuring unpredictable names. Permissions are explicitly set and the file descriptor is closed before the atomic rename to ensure cross-platform compatibility.
✅ Verification: Tested atomic write patterns via standard library tools. Confirmed successful test runs go test ./....


PR created automatically by Jules for task 17060932732088299257 started by @himattm

…le writes

Co-authored-by: himattm <6266621+himattm@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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the security of atomic file writes in the burnrate and sparkline packages by replacing predictable temporary file names with os.CreateTemp, mitigating potential symlink attacks. The review feedback suggests further enhancing security by removing the explicit Chmod calls to maintain the default secure permissions (0600) and adding Sync() calls to ensure data durability before renaming the temporary files.

Comment on lines +73 to +77
if err := tmpFile.Chmod(0644); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return nil, false, err
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The temporary file is created in the system's temporary directory (/tmp). Using 0644 permissions allows any local user to read the snapshot data, which contains session-specific information. Since os.CreateTemp already creates the file with secure 0600 permissions (owner read/write only), it is recommended to remove this Chmod call unless world-readability is explicitly required for other processes.

Comment on lines +79 to 83
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return nil, false, err
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure the atomic write is durable, tmpFile.Sync() should be called before closing the file. This guarantees that the data is flushed to stable storage before the rename operation occurs, preventing data loss or corruption in the event of a system crash.

Suggested change
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return nil, false, err
}
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return nil, false, err
}
if err := tmpFile.Sync(); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return nil, false, err
}

Comment on lines +147 to +151
if err := tmpFile.Chmod(0644); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The temporary file is created in the system's temporary directory. Using 0644 permissions allows any local user to read the sparkline data. Since os.CreateTemp already creates the file with secure 0600 permissions, it is recommended to remove this Chmod call unless world-readability is explicitly required.

Comment on lines +153 to +157
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure the atomic write is durable, tmpFile.Sync() should be called before closing the file. This guarantees that the data is flushed to stable storage before the rename operation occurs, preventing data loss or corruption in the event of a system crash.

Suggested change
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return
}
if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return
}
if err := tmpFile.Sync(); err != nil {
tmpFile.Close()
os.Remove(tmpPath)
return
}

@himattm
Copy link
Copy Markdown
Owner Author

himattm commented May 7, 2026

Closing as superseded by direct commit 42f3149 on main, which consolidated the burnrate/sparkline predictable-temp-file fixes and also preserved PR #82's updater temp-file hardening without the generated .jules note.

@himattm himattm closed this May 7, 2026
@himattm himattm deleted the sentinel/fix-atomic-write-symlink-17060932732088299257 branch May 7, 2026 15:34
@google-labs-jules
Copy link
Copy Markdown
Contributor

Closing as superseded by direct commit 42f3149 on main, which consolidated the burnrate/sparkline predictable-temp-file fixes and also preserved PR #82's updater temp-file hardening without the generated .jules note.

Understood. Acknowledging that this work is superseded and stopping work on this task.

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