Skip to content

🛡️ Sentinel: [HIGH] Fix predictable temp file names#51

Closed
himattm wants to merge 1 commit intomainfrom
sentinel-fix-temp-files-9138451665521596298
Closed

🛡️ Sentinel: [HIGH] Fix predictable temp file names#51
himattm wants to merge 1 commit intomainfrom
sentinel-fix-temp-files-9138451665521596298

Conversation

@himattm
Copy link
Copy Markdown
Owner

@himattm himattm commented Apr 17, 2026

🚨 Severity: HIGH
💡 Vulnerability: Predictable temporary file names were used (path + ".tmp") with os.WriteFile in shared temporary directories. Since os.WriteFile follows existing symlinks, this creates a vulnerability where an attacker could pre-create a symlink at the predicted path to overwrite arbitrary files that the user running the application has write access to.
🎯 Impact: Local attacker with access to the shared temp directory could conduct a symlink attack to overwrite sensitive files.
🔧 Fix: Replaced predictable .tmp file paths with os.CreateTemp to generate random, unpredictable temporary file names. Ensured temporary files are closed before renaming to avoid cross-platform locking issues, and restored correct file permissions (0644).
✅ Verification: Review the changes in internal/burnrate/burnrate.go and internal/sparkline/sparkline.go to confirm os.CreateTemp is utilized. Run go test ./... to ensure all functionality remains correct.


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

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 addresses a security vulnerability by replacing predictable temporary file names with os.CreateTemp in internal/burnrate/burnrate.go and internal/sparkline/sparkline.go. Feedback was provided to improve the robustness of these changes by checking for errors during f.Close() to ensure data integrity before renaming and utilizing defer os.Remove() for more reliable cleanup of temporary files.

Comment on lines +71 to 82
tmpPath := f.Name()
if _, err := f.Write(data); err != nil {
f.Close()
os.Remove(tmpPath)
return nil, false, err
}
f.Close()
os.Chmod(tmpPath, 0644)

if err := os.Rename(tmpPath, path); err != nil {
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

The errors from f.Close() and os.Chmod() are currently ignored. Checking the error from f.Close() is critical because it can reveal issues like disk full or I/O errors that occurred during the final flush. If Close fails, the file on disk might be incomplete, and proceeding to os.Rename would replace the target file with corrupted data. Additionally, using defer os.Remove(tmpPath) simplifies the logic by ensuring the temporary file is cleaned up on any failure path.

	tmpPath := f.Name()
	defer os.Remove(tmpPath)
	if _, err := f.Write(data); err != nil {
		f.Close()
		return nil, false, err
	}
	if err := f.Chmod(0644); err != nil {
		f.Close()
		return nil, false, err
	}
	if err := f.Close(); err != nil {
		return nil, false, err
	}

	if err := os.Rename(tmpPath, path); err != nil {
		return nil, false, err
	}

Comment on lines +146 to +157
tmp := f.Name()
if _, err := f.Write(data); err != nil {
f.Close()
os.Remove(tmp)
return
}
os.Rename(tmp, path)
f.Close()
os.Chmod(tmp, 0644)

if err := os.Rename(tmp, path); err != nil {
os.Remove(tmp)
}
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

Similar to the changes in burnrate.go, the error from f.Close() should be checked to ensure data integrity before renaming the file. Even though this function does not return an error, checking f.Close() ensures that we don't overwrite the existing cache with potentially corrupted data if the write/flush failed. Using defer os.Remove(tmp) also provides a cleaner way to handle temporary file cleanup across all error paths.

	tmp := f.Name()
	defer os.Remove(tmp)
	if _, err := f.Write(data); err != nil {
		f.Close()
		return
	}
	f.Chmod(0644)
	if err := f.Close(); err != nil {
		return
	}

	if err := os.Rename(tmp, path); err != nil {
		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-temp-files-9138451665521596298 branch May 7, 2026 15:36
@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 now 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