Skip to content

feat(helper): warn on and refuse likely secrets in public pushes (E807) - #396

Merged
PastaPastaPasta merged 8 commits into
masterfrom
feat/mv1-scan
Oct 5, 2026
Merged

PastaPastaPasta merged 8 commits into
masterfrom
feat/mv1-scan

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

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 a pub const, and the rule table is documented in lib.rs so a TypeScript port can mirror it.
    • Refuse:

      • a .env file that sets a value: .env, or .env.<name> but not *.example, *.sample or *.template. Names are matched case-insensitively. NAME=value and NAME: value both count, and a leading BOM is ignored.
      • a PEM private-key block with a body. A mention of the marker is not a key, and a stray BEGIN does not hide a later real key. At most 64 markers are examined per file.
      • an AWS access key id with its secret in the same file.
      • a GitHub token (ghp_/gho_/ghu_/ghs_/ghr_) whose CRC32/base62 checksum verifies.
      • a GitLab routable token whose length and CRC32/base36 checksum verify.

      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:

      • .envrc with variables
      • WIF keys (base58check, versions 0x80/0xCC/0xEF)
      • high-entropy values assigned to secret-named settings
      • token prefixes without a verifiable checksum

      There is no id_* glob: keys are found by content.

    • Downgrades:

      • Content findings (key, AWS, token) become warnings under test/, tests/, testdata/ or fixtures/. tests/ is an addition to the design's list.
      • The .env name rule is never downgraded by a test folder: a real tests/.env is refused.
      • Any finding in history only warns.
    • Fingerprints: 12 hex digits of SHA-256 over rule, path and material. For .env/.envrc the 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-allow takes fingerprints and path globs.

      • A fingerprint silences its finding.
      • A path only turns a refusal into a printed warning ("its path is in the allow file"). It never silences, so a broad path can't hide a secret nobody looked at.
      • Paths are anchored at the repo root. Use **/ 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 giving severity refuse/warn/silent plus a reason.

      • Inputs come from tools/secret-scan-vectors/gen.py. FORGE_SECRETS_BLESS=1 cargo test -p forge-secrets fills in the expected results.
      • The generator computes one fingerprint independently in Python, and it matches Rust's.
      • The vectors sit in a subfolder because both existing conformance runners fail on an unknown top-level case.
      • Fake secrets are split into string pieces, so no whole token appears in this repo's bytes (GitHub push protection).
  • git-remote-dash: every push to a public repo is scanned right after plan_pushes, before anything is built, signed or stored (check_secrets).
    • What is scanned: files introduced by commits new to Forge, i.e. 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.
    • Per-ref judgement: each ref is judged by the allow file at its own tip. A ref whose new history adds an unallowed refusal is rejected with E807 and wire reason possible secret in new files, matching the §10 message block. The other refs go ahead.
    • When the full scan can't run: a name-only .env check (ls-tree of the tips against the remote's trees) still refuses, and a secretScanFailed event goes out in JSON mode.
    • Scope: private repos are not scanned (their content is encrypted).
  • Import point. Forge records no import marker in git. The scan uses the repo document's $createdAt minus a 24 h grace (IMPORT_GRACE_MS).
    • A file whose introducing commits are all older only warns.
    • forge-import pushes count as history.
    • Content reads are capped per push (64 MiB of history, 256 MiB of new files). Past the caps, files are matched by name only.
    • Object reads skip replace refs and never lazily fetch in a partial clone.
  • Push options learn 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.
  • Sealed-object ledger: <git common dir>/dash/sealed-ledger, created empty with the header # dash sealed-object ledger v1.
    • Shared by worktrees: it lives in the common git dir, so every worktree of a clone sees the same file.
    • When it is created: only on a clone (an empty repo's too) or a fetch into a repo with no refs. Never just because it is missing: an older clone, or a new worktree of a clone that already holds members-only objects, must not get a "never held" ledger.
    • Safety: created with create_new, so it is never truncated.
    • Format: v1 is documented in ledger.rs. There is no guard yet (phase 3).
    • Design change: D21 names $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_DIR is per worktree. D21 should read <common dir>/dash/sealed-ledger.
  • forge-core:
    • E807 SECRET_IN_PUSH is in the catalogue.
    • redact keeps the value of allow-secret=, which is a fingerprint the fix line must show (tested).
    • New resolve::repo_created_at.
  • Docs: E807 in docs/errors.md; "Secrets in a push" in docs/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

  • Gates:
    • 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.
    • All three ran under the shared-build disk rules. A full --workspace clippy 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 .env refuses, .env.example passes, a PEM under test/ warns, a GitHub token with a bad checksum warns, an AWS id alone passes, tests/.env refuses, a stray BEGIN before 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:
    • the refusal path and -o allow-secret=
    • per-ref allow files
    • path-glob warnings
    • history and the grace window
    • per-ref refusal
    • merges
    • tags of a blob or tree
    • the name-only fallback
    • tests/.env
    • the log parser, the ledger and options
  • Live QA on devnet sakura (scratch repo mv1-scan-qa-10050237, identity 4r5JxZ6S…). Transcripts are in dash-forge-qa/evidence/mv1/scan/:
    • 02-warnings-only.txt: .env.example, .envrc and test/key.pem give warnings only, and the push lands.
    • 03-env-refused.txt: a new .env gets E807 naming .env. ls-remote, --dump-refs and --dump-pack-heads show 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: AWS export NAME=value lines are refused.
    • 08-security-review.txt, with binary 36df6b27:
      • tests/.env is refused.
      • A key under a path glob is printed as a warning and lands.
      • The documented .env fingerprint is confirmed.
      • The ledger is in .git/dash/ for a clone, and a git worktree gets none of its own.
      • A clone with refs whose ledger was deleted does not get a new one on fetch.
      • init plus a first fetch gets one.

Limits

  • Old commits only warn. Commits made more than a day before the repo was created only warn, per the import-point rule. IMPORT_GRACE_MS is one constant.
  • Forks re-check history. A fork's first push re-checks history its parent already published.
  • Wording differs from §10. The .env fix line says git rm --cached rather than §10's dg env import, which arrives with stream 1I.
  • GitLab checksum is unverified against a real token. It has been checked only against tokens built from GitLab's own description.
  • Large first pushes use memory. A very large first push keeps the git log --raw output in memory; content reads are capped.
  • Warnings use every ref's allow file. A fingerprint in any pushed ref's allow file silences them. Refusals are judged per ref.
  • E807 docs overlap with stream 1C. Stream 1C also lists E807 for docs/errors.md. It should extend this section rather than add a second one.

🤖 Generated with Claude Code

PastaPastaPasta and others added 4 commits October 5, 2026 02:36
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]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a9f67f9-4d8f-422c-939f-40327ad9ef31
📥 Commits

Reviewing files that changed from the base of the PR and between fe376f7 and 8dbe124.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (63)
  • Cargo.toml
  • crates/forge-core/src/resolve.rs
  • crates/forge-core/src/user_error.rs
  • crates/forge-secrets/Cargo.toml
  • crates/forge-secrets/src/allow.rs
  • crates/forge-secrets/src/content.rs
  • crates/forge-secrets/src/glob.rs
  • crates/forge-secrets/src/lib.rs
  • crates/forge-secrets/src/tests.rs
  • crates/forge-secrets/src/util.rs
  • crates/forge-secrets/tests/vectors.rs
  • crates/git-remote-dash/Cargo.toml
  • crates/git-remote-dash/src/git.rs
  • crates/git-remote-dash/src/helper.rs
  • crates/git-remote-dash/src/ledger.rs
  • crates/git-remote-dash/src/main.rs
  • crates/git-remote-dash/src/options.rs
  • crates/git-remote-dash/src/secret_scan.rs
  • docs/errors.md
  • docs/guides/quick-start.md
  • forge-contracts/vectors/secret_scan/secret_scan__allow_file_bare_name_is_rooted.json
  • forge-contracts/vectors/secret_scan/secret_scan__allow_file_fingerprint.json
  • forge-contracts/vectors/secret_scan/secret_scan__allow_file_glob.json
  • forge-contracts/vectors/secret_scan/secret_scan__allow_push_option.json
  • forge-contracts/vectors/secret_scan/secret_scan__aws_documentation_pair_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__aws_id_alone_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__aws_pair_dockerfile_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__aws_pair_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__aws_pair_shell_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__binary_file_by_name_only.json
  • forge-contracts/vectors/secret_scan/secret_scan__dash_core_wif_vectors_warn.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_bom_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_example_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_file_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_local_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_named_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_not_read_refuses_by_name.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_template_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_under_tests_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_upper_case_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_without_values_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__env_yaml_colon_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__envrc_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__envrc_without_values_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__github_fine_grained_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__github_token_bad_checksum_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__github_token_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__gitlab_legacy_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__gitlab_routable_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__history_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_after_stray_begin_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_json_escaped_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_marker_only_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_public_key_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_refused.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_under_fixtures_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__pem_under_test_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__secret_assignment_low_entropy_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__secret_assignment_placeholder_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__secret_assignment_warns.json
  • forge-contracts/vectors/secret_scan/secret_scan__wif_bad_checksum_passes.json
  • forge-contracts/vectors/secret_scan/secret_scan__wif_outside_tests_warns.json
  • tools/secret-scan-vectors/gen.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

PastaPastaPasta and others added 4 commits October 5, 2026 04:15
- 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]>
# Conflicts:
#	Cargo.toml
#	crates/git-remote-dash/src/helper.rs
@PastaPastaPasta
PastaPastaPasta merged commit d57744f into master Oct 5, 2026
31 checks passed
@PastaPastaPasta
PastaPastaPasta deleted the feat/mv1-scan branch October 5, 2026 12:42
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