Repository navigation
envsec: fix P0 secrets-hygiene bugs (name validation, file perms, --format) - #614
Merged
Merged
Conversation
…ormat) Fixes bug-scan P0 #1, #2, #3 and #6 from specs/bug-scan.md: - #1: anchor the env-var name regex with `$` so names like `A/../../other/prod/KEY` or `PATH=/evil` are rejected instead of being written to another project's SSM path or into the exec environment. - #2: `envsec download` now writes the output file with 0600 and tightens an existing file to 0600, so secrets aren't world-readable. - #3: pkg/filecache writes cache files atomically with 0600 inside 0700 directories, protecting the cached Cognito AWS credentials. The atomic rename also replaces old 0644 cache files. - #6: `envsec download --format` now defaults to "" (which ValidateFormat accepts) instead of "env" (which it rejected), so plain `envsec download .env` works again and `.json` auto-detection runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
Adds the status as its own line under the matching "Suggested fix order" item so it doesn't conflict with the other P0 fix PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
[High impact] The PR appears safe to merge; no new actionable issues remain.
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
- filecache: tighten an existing cache dir to 0700 and a legacy 0644 cache file to 0600 on read, so credentials cached by older versions aren't left readable by other users until they expire. - envsec download: chmod before truncating so a failed chmod doesn't wipe an existing file. - Add a test that the download command's actual --format default passes ValidateFormat, and a filecache upgrade test from 0755/0644. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
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.
Summary
Fixes P0 bugs #1, #2, #3 and #6 from
specs/bug-scan.md, and marks them as fixed in that file.envsec/pkg/envsec/set.go): the name regex had no trailing$, so names likeA/../../<otherProject>/prod/KEYorPATH=/evil:…passed validation. The first could overwrite another project's SSM secret; the second corrupted the env passed toexec. The regex is now anchored. This coverssetandupload, which both go throughSetMap.envsec/pkg/envsec/download.go):envsec downloadnow writes with0600. An existing file has its permissions tightened to0600before it is truncated, so a failed chmod (for example on a file owned by another user) leaves the old contents intact.pkg/filecache): cache files are now written atomically (temp file + rename) with0600, inside0700directories. Caches left by older versions are also tightened: the cache directory is chmodded to0700and a loose cache file to0600when read. This means valid, unexpired credentials from before the upgrade don't stay exposed. This protects the Cognito credentials cached byawsfedwhenENVSEC_USE_AWS_STORE=1.envsec downloadalways failed (envsec/pkg/envcli/download.go):--formatdefaulted to"env", whichValidateFormatrejects. It now defaults to"", so plainenvsec download .envworks again and.jsonauto-detection runs.Note: envsec pins
go.jetify.com/pkgby version, so released envsec binaries get thefilecachepart of #3 after the usual internal-dependency bump.How was it tested?
envsec/pkg/envsec/set_test.go: path-traversal,=, whitespace, newline andjetpack_names are rejected.envsec/pkg/envsec/download_test.go: an existing0644file ends up0600with the new contents.envsec/pkg/envcli/download_test.go: the download command's real--formatdefault passesValidateFormat. It fails on main.pkg/filecache/filecache_test.go:Setproduces a0600file in a0700dir, replaces a pre-existing0644file, and leaves no temp files behind.0755/0644is tightened to0700/0600on a cache hit. This test fails without the fix.go vet,go testand golangci-lint v2.15.0 pass inenvsecandpkg.Community Contribution License
All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.
By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2