fix(cli/config): enforce 0600 on the config file even when it pre-exists (CWE-732)#82
Open
gadievron wants to merge 2 commits into
Open
fix(cli/config): enforce 0600 on the config file even when it pre-exists (CWE-732)#82gadievron wants to merge 2 commits into
gadievron wants to merge 2 commits into
Conversation
…sts (CWE-732) config.Save() wrote the config (which may hold an API key) with os.WriteFile(path, data, 0600). os.WriteFile only applies the mode when it CREATES the file; if config.json already existed with looser permissions (e.g. 0644), the secret stayed world/group-readable after Save(). Enforce 0600 explicitly via os.Chmod after the write (CWE-732, insecure permissions for a secret-bearing file). Tests: internal/config/config_perms_test.go (a pre-existing 0644 secret config becomes 0600 after Save). RED 1 failed (0644) -> GREEN; go test ./internal/config/ ok; gofmt + go vet clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
TestSaveEnforcesRestrictivePermsOnPreexistingFile asserts 0600 file-mode bits, which Windows does not enforce (got 0666). Guard the test with a runtime.GOOS == windows skip so the CWE-732 0600 enforcement check still runs on Unix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
config.Save() wrote the config (which may hold an API key) with
os.WriteFile(path, data, 0600). os.WriteFile only applies the mode when it
CREATES the file; if config.json already existed with looser permissions
(e.g. 0644), the secret stayed world/group-readable after Save(). Enforce 0600
explicitly via os.Chmod after the write (CWE-732, insecure permissions for a
secret-bearing file).
Tests: internal/config/config_perms_test.go (a pre-existing 0644 secret config
becomes 0600 after Save). RED 1 failed (0644) -> GREEN; go test
./internal/config/ ok; gofmt + go vet clean.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Coordination
Touches a file also modified by in-flight PR #69 (region-disjoint; textual merge only).