fix(browser): write network cache file with 0o600 owner-only permissions#1766
Open
Benjamin-eecs wants to merge 1 commit into
Open
fix(browser): write network cache file with 0o600 owner-only permissions#1766Benjamin-eecs wants to merge 1 commit into
Benjamin-eecs wants to merge 1 commit into
Conversation
951c4c2 to
1428dec
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens the on-disk browser network cache to reduce the risk of leaking sensitive captured response data (auth tokens / PII) by ensuring cache files are written with owner-only permissions.
Changes:
- Write the cache file via an explicit file descriptor and apply
0o600permissions before writing. - Add non-Windows tests asserting the cache file is created/tightened to
0o600.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/browser/network-cache.ts | Writes cache files with owner-only permissions using openSync + fchmodSync + writeFileSync(fd, ...). |
| src/browser/network-cache.test.ts | Adds POSIX-only tests for 0o600 permissions and tightening an existing file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+68
to
+72
| let fd: number | undefined; | ||
| try { | ||
| fd = fs.openSync(target, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC, 0o600); | ||
| fs.fchmodSync(fd, 0o600); | ||
| fs.writeFileSync(fd, JSON.stringify(payload), 'utf8'); |
Comment on lines
+70
to
+72
| fd = fs.openSync(target, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC, 0o600); | ||
| fs.fchmodSync(fd, 0o600); | ||
| fs.writeFileSync(fd, JSON.stringify(payload), 'utf8'); |
| // bodies. fchmod before writing also tightens a pre-existing broad file. | ||
| let fd: number | undefined; | ||
| try { | ||
| fd = fs.openSync(target, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC, 0o600); |
Captured response bodies can leak auth tokens; apply the openSync + fchmod pattern from jackwener#1742. Fixes jackwener#1765
1428dec to
0ffd9b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
saveNetworkCacheinsrc/browser/network-cache.tswrites the browser network cache viafs.writeFileSync(target, JSON.stringify(payload), 'utf-8')with nomodeoption. The kernel applies the process umask, so the file lands as0644and is readable by any local user. The file at~/.opencli/cache/browser-network/<session>.jsonstores up to a day ofentries[].bodypayloads from every browser-backed adapter call, which routinely include auth tokens, session cookies, and PII. This is the same class of leak that #1742 fixed inexportCookiesToNetscape; apply the samefs.openSync+fs.fchmodSyncpattern so new files are owner-only and pre-existing broad-permission files are tightened on rewrite.Related issue: fixes #1765 (this is the same defense-in-depth thread continued from #1742; the larger Finding 5 in #847 about capture-by-default behavior is separate and not addressed here).
Type of Change
Checklist
Screenshots / Output
Two tests added next to existing siblings in
src/browser/network-cache.test.ts, mirroring the #1742 layout:writes the cache file with 0o600 owner-only permissionscovers the new-file casetightens an existing cache file before rewriting itpre-creates a 0o644 file and asserts the rewrite drops it to 0o600 while preserving round-trip vialoadNetworkCacheBoth skipped on Windows via
it.skipIf(process.platform === 'win32')since POSIX mode bits do not apply there. Full suite: 511/511 pass on this branch.