Repository navigation
feat(helper): warn on and refuse likely secrets in public pushes (E807) - #396
Merged
Merged
Conversation
A shared, pure rule crate (forge-secrets) finds likely secrets in the files a public push publishes for the first time. The helper refuses a ref whose new commits add a .env file, a PEM private key, an AWS key id with its secret, or a GitHub/GitLab token with a valid checksum (E807, wire reason "possible secret in new files"), and warns on .envrc, WIFs, random-looking secret assignments, test folders and history older than the repo on Forge. -o allow-secret=<fingerprint> and .forge/secret-scan-allow override. The helper also creates the empty sealed-object ledger ($GIT_DIR/dash/sealed, v1 header) on clone and first fetch, and push options learn key=value. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e the file in E807 git announces a clone only before fetch, and a clone of an empty repository never fetches, so a list into a repo with no refs and no dash/ folder now creates the ledger. The E807 headline names the file; the line number stays on the per-finding line. The guide shows the live sakura output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- The ledger moves to $GIT_DIR/dash/sealed-ledger: dash/sealed is already the folder where a private push keeps its sealed pack for a retry. - AWS secrets written NAME=value (shell, Dockerfile, compose) are found. - What this clone last fetched (refs/remotes/<remote>/*) counts as public, so a stale clone is not refused for content already pushed. - Object reads skip replace refs and never lazily fetch in a partial clone; a blob git does not return is matched by name; new files get a content budget. - Allow files are read in one batch and only as files; one git call less per remote ref; paths are escaped for the terminal and quoted in the fix line; a malformed -o allow-secret value is not echoed. - Linear-time line numbers, PEM marker search and glob matching. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
⛔ Files ignored due to path filters (1)
📒 Files selected for processing (63)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- PEM: a stray BEGIN no longer hides a later real key; at most 64 markers per file. - Already public means only the tips Forge lists for the remote, never refs/remotes/*. - The ledger lives in the common git dir (shared by worktrees) and is created only on a clone or in a repo with no refs, never just because it is missing. - A path in .forge/secret-scan-allow turns a refusal into a printed warning; only fingerprints silence. Paths are anchored at the root (use **/ for any depth). Each ref is judged by the allow file at its own tip. - Tags of a tree or blob are scanned. .env names match case-insensitively; a BOM and NAME: value count; a tests/.env is refused (only content rules soften in test folders). Name-only .env fingerprints use the git blob id. - When the full scan cannot run, a name-only .env check runs and a JSON event says so. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # Cargo.toml # crates/git-remote-dash/src/helper.rs
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.
What
Mixed-visibility phase 1, stream 1K (DESIGN.md §4.5 "Accidental-commit prevention", product review H4/J12, D21's ledger file).
crates/forge-secrets(new workspace member): one pure, deterministic rule set for likely secrets, shared by the push helper now and the web editor / publish dialog later. No I/O; every threshold and word list is apub const, and the rule table is documented inlib.rsso a TypeScript port can mirror it.Refuse:
.envfile that sets a value:.env, or.env.<name>but not*.example,*.sampleor*.template. Names are matched case-insensitively.NAME=valueandNAME: valueboth count, and a leading BOM is ignored.BEGINdoes not hide a later real key. At most 64 markers are examined per file.ghp_/gho_/ghu_/ghs_/ghr_) whose CRC32/base62 checksum verifies.Format sources are cited in
content.rs(GitHub's 2021 token-format post, GitLab's routable-tokens design doc). Neither says exactly which characters the CRC covers, so both readings are accepted and the comments say so.Warn:
.envrcwith variablesThere is no
id_*glob: keys are found by content.Downgrades:
test/,tests/,testdata/orfixtures/.tests/is an addition to the design's list..envname rule is never downgraded by a test folder: a realtests/.envis refused.Fingerprints: 12 hex digits of SHA-256 over rule, path and material. For
.env/.envrcthe material is the git blob id, so a file that was not read gets the same fingerprint as a read one. A fingerprint is a short hash: for a tiny file, the content could be guessed from it offline. The docs say so.Allow list:
.forge/secret-scan-allowtakes fingerprints and path globs.**/for any depth.-o allow-secret=<fp>silences one finding for one push.Conformance vectors for the later TS port:
forge-contracts/vectors/secret_scan/secret_scan__*.json(42), each givingseverityrefuse/warn/silent plus a reason.tools/secret-scan-vectors/gen.py.FORGE_SECRETS_BLESS=1 cargo test -p forge-secretsfills in the expected results.case.git-remote-dash: every push to a public repo is scanned right afterplan_pushes, before anything is built, signed or stored (check_secrets).git log <tips> ^<tips Forge lists for the remote> -c --raw -z. Remote-tracking refs are not trusted. A merge reports only its own changes. Tags of a tree or blob are scanned too.possible secret in new files, matching the §10 message block. The other refs go ahead..envcheck (ls-treeof the tips against the remote's trees) still refuses, and asecretScanFailedevent goes out in JSON mode.$createdAtminus a 24 h grace (IMPORT_GRACE_MS).forge-importpushes count as history.key=value(OptionState::push_option_values). This is additive, so it should merge with open PR feat(push): --force-with-lease, an honest --atomic refusal, and ref-name collisions refused (E9) #377.<git common dir>/dash/sealed-ledger, created empty with the header# dash sealed-object ledger v1.create_new, so it is never truncated.ledger.rs. There is no guard yet (phase 3).$GIT_DIR/dash/sealed. That path is already the folder where a private push keeps its sealed pack for a retry (sealed_cache_path), and$GIT_DIRis per worktree. D21 should read<common dir>/dash/sealed-ledger.SECRET_IN_PUSHis in the catalogue.redactkeeps the value ofallow-secret=, which is a fingerprint the fix line must show (tested).resolve::repo_created_at.docs/errors.md; "Secrets in a push" indocs/guides/quick-start.md(what refuses, what warns, the override, allow-file semantics, real sakura output).Why
A public push publishes for good. The design refuses a narrow, high-confidence set and warns on the rest. That way imports such as Dash Core's WIF test vectors or TLS test keys are never refused, and no blanket "skip the scan" switch is needed (product review J12/H4).
How it was tested
cargo fmt --all -- --check: green.cargo clippy -p forge-secrets -p git-remote-dash --all-targets -- -D warnings: green.cargo test -p forge-secrets -p git-remote-dash: green.--workspaceclippy and test run was green before the security-review round; CI is the authority for the rest.forge-secrets: 26 unit tests plus 42 vectors. Among them: Dash Core's real WIF vectors warn, a new.envrefuses,.env.examplepasses, a PEM undertest/warns, a GitHub token with a bad checksum warns, an AWS id alone passes,tests/.envrefuses, a strayBEGINbefore a real key refuses, a path glob warns, a fingerprint silences, and bare allow-file names are anchored at the root.git-remote-dash: scratch-repo tests of:-o allow-secret=tests/.envmv1-scan-qa-10050237, identity4r5JxZ6S…). Transcripts are indash-forge-qa/evidence/mv1/scan/:02-warnings-only.txt:.env.example,.envrcandtest/key.pemgive warnings only, and the push lands.03-env-refused.txt: a new.envgets E807 naming.env.ls-remote,--dump-refsand--dump-pack-headsshow no new refUpdate and no new pack.04-allow-secret-override.txt:-o allow-secret=<fp>lands.06-allow-file.txt: a PEM is refused.07-after-review.txt: AWSexport NAME=valuelines are refused.08-security-review.txt, with binary36df6b27:tests/.envis refused..envfingerprint is confirmed..git/dash/for a clone, and agit worktreegets none of its own.initplus a first fetch gets one.Limits
IMPORT_GRACE_MSis one constant..envfix line saysgit rm --cachedrather than §10'sdg env import, which arrives with stream 1I.git log --rawoutput in memory; content reads are capped.docs/errors.md. It should extend this section rather than add a second one.🤖 Generated with Claude Code