Skip to content

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
masterfrom
fix/cli-config-enforce-0600-on-the-config-file
Open

fix(cli/config): enforce 0600 on the config file even when it pre-exists (CWE-732)#82
gadievron wants to merge 2 commits into
masterfrom
fix/cli-config-enforce-0600-on-the-config-file

Conversation

@gadievron

Copy link
Copy Markdown
Collaborator

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).

…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>
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