fix(core): restrict global directory permissions#28645
Open
xmh1011 wants to merge 1 commit into
Open
Conversation
0fbf1b6 to
44bca31
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.
Issue for this PR
Closes #28421
Type of change
What does this PR do?
OpenCode creates several managed directories under the user data, cache, config, state, and temp roots. On Unix-like systems those directories could be created with permissions widened by the process umask, or existing directories could remain at
0755, making user-specific files readable by other local users.This PR centralizes global directory creation through
ensurePrivateDir(), creates each managed directory with mode0700, and then applieschmod 0700so existing directories are tightened as well. It also includes the cache root in the module-load initialization list, sincebinlives under it.The regression test imports
src/global.tsin a fresh process with isolated XDG roots and verifies the data, cache, config, state, temp, log, bin, and repos directories are all0700, including an existing data directory that starts as0755.How did you verify your code works?
npx -y bun@1.3.14 test test/global.test.tsfrompackages/corenpx -y bun@1.3.14 typecheckfrompackages/coregit diff --checknpx -y prettier@3.6.2 --check packages/core/src/global.ts packages/core/test/global.test.tsScreenshots / recordings
N/A - filesystem permissions change with automated test coverage.
Checklist