Skip to content

Catch secrets split across lines in UTF-16 files and stop deleted binaries from blocking pushes (GST-2261) - #4261

Merged
capy-ai[bot] merged 6 commits into
mainfrom
capy/catch-secrets-split-across
Nov 10, 2026
Merged

capy-ai[bot] merged 6 commits into
mainfrom
capy/catch-secrets-split-across

Conversation

@garrytan

@garrytan garrytan commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

This closes two gaps #4243 left in the secret check and the pre-push hook. Both are security fixes that serve the project's goal of never pushing a credential.

What changed

Secrets split across two lines of UTF-16 text are now caught. #4243 reads a file git calls binary three ways (as bytes, and as little- and big-endian UTF-16) but put all three readings side by side on each line. So the line holding aws_secret_access_key: ended with the letter-spaced byte reading, and the rule that looks for the key on the next line lost its keyword. An AWS secret key under its YAML key in a UTF-16LE or UTF-16BE file passed both guards (the repro table in #4243's "Open advisory notes", item 1). scannableText becomes scannableReadings, which returns each distinct reading as a whole text with the file's line breaks. Pregate's secrets check runs gstack-redact once per reading, and the hook scans one part per reading, both keeping the file's line numbers. Plain-text files still have one reading and are scanned once, as before. A token that several readings of one file find is reported once.

Deleting a large binary no longer blocks a push. With --text, a deleted binary's old bytes filled the hook's 64 MiB diff buffer, so removing an already-pushed 70 MiB file (or moving it to Git LFS) failed with git diff failed (status=killed/overflow). The hook's git diff and per-commit git show now pass --irreversible-delete, so a deleted file prints only its header. A delete can't add a secret. Adding a binary over the limit still blocks. A replaced binary's old bytes still count: git has no flag that drops a modification's preimage (-B merges the broken pair back into a rewrite that prints the old lines), so that stays a documented limit. Pregate already skipped deletions and is unchanged there.

No screenshots: this change has no visible surface, and the tests below show the behavior.

Why

An AWS secret key stored under its YAML key in a UTF-16 file got past both the pre-push hook and pregate, which is the leak these guards exist to stop. Separately, deleting a large binary that was already pushed made the hook fail, so people could not clean up their repository. Now the split key is blocked in every encoding and the delete pushes clean.

Blast radius

The change touches the secret check in lib/pregate/checks/secrets.ts and the pre-push hook bin/gstack-redact-prepush, which imports it; lib/pregate/index.ts is untouched. Plain-text files still get exactly one reading, so their scan is the same as before, and the new tests fail on main at 76e2d3f and pass here (script ran, plus the carried CI run 42731728299).

Summary

The secret check and the pre-push hook let a key slip through when a UTF-16 file split it across two lines, and they blocked the push that deletes a large binary. Each reading of a binary file is now scanned as its own text with its line breaks, so the key and its value stay together. Deleted files leave the hook's diff, so removing a big binary no longer fills the buffer. A token that several readings find is listed once, and an allowlisted token never hides a different one.

Test Coverage

All new code paths have test coverage. The tests were written first and failed on main at 76e2d3f:

  • test/pregate-secrets-source-context.test.ts: the split AWS pair fails in plain text, UTF-16LE and UTF-16BE.
  • test/redact-prepush-hook.test.ts: the same pair blocks the push in all three encodings; adding a 70 MiB binary still blocks on the buffer limit, and deleting it pushes clean.

Tests ran: test 1658 (files, carried from CI run 42731728299/1 at tree 54dc12485f73)

Pre-Landing Review

Full panel (security change): two passes, a fix-check on the round-2 fix and a targeted secret-class read. Every blocking finding was fixed on the branch; each fix commit names its finding in a Review-Finding: trailer. The targeted secret read at 6bd89e1 found nothing. Outside review: CLEAN.

REVIEW_LOOP: passes=2 blocking_found=3 deferred=0 noted=3 fixed=4 scope=frozen ledgers_read=5 fix_checks=1

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL bin/gstack-redact-prepush:271 collectAddedLines only parses '+++ b/' headers, so a file whose name git quotes (non-ASCII, tab, quote, backslash) is scanned without its path: reported as (unknown file) and without sourcePath file-type context. Pre-existing on main; the scan still runs.
  • INFORMATIONAL bin/gstack-redact-prepush:723 An allowlisted plain token in a binary file is listed once per reading in the hook's suppressed list and pregate's allowlist lines, so 'suppressed N' overcounts; never unblocks a credential.
  • INFORMATIONAL lib/pregate/checks/secrets.ts:176 Pregate starts one gstack-redact per reading (up to 3 per binary file), each with the full per-run timeout.
  • INFORMATIONAL bin/gstack-redact-prepush:310 A modified (not deleted) large binary still overflows the hook's 64 MiB diff buffer with --text and blocks fail-closed; documented.
  • INFORMATIONAL test/redact-prepush-hook.test.ts:36 runHook maps a killed process to exit 0 (r.status ?? 0); the signal-kill test fails the same way at base 76e2d3f on this machine, so the helper can hide a hung hook as a pass.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. The docs already describe this branch's changes, so no edits were made.

Scope: six committed files from base 76e2d3f to head 0f731c4 (bin/gstack-redact-prepush, lib/pregate/checks/secrets.ts, docs/pregate.md, a changelog.d fragment, two tests). Nothing was staged, unstaged or untracked. I also checked the docs that mention the pre-push hook or the redaction guard: CLAUDE.md, docs/CONTRIBUTOR_REFERENCE.md, docs/troubleshooting.md and ship/SKILL.md.tmpl.

Documentation health:

  • docs/pregate.md: current (updated on the branch). It covers the three readings of a binary file, each scanned as its own text, and the hook leaving deleted files out of its scan.
  • CLAUDE.md: current, no change needed.
  • docs/CONTRIBUTOR_REFERENCE.md: current, no change needed.
  • docs/troubleshooting.md: current, no change needed.
  • ship/SKILL.md.tmpl: current, no change needed.
  • changelog.d/capy-catch-secrets-split-across.md: reviewed only (owned by the parent).

Coverage debt: none that affects users. No doc says that a token several readings find is reported once, because that is an internal detail. Diagram drift: none.

Test plan

  • bun run test (lane test): green in CI run 42731728299/1 at tree 54dc12485f73, carried by /ship
  • Remote lanes: free-tests.yml/macos-named-regressions (run 42731728299) and windows-smoke.yml/windows-smoke (run 42723243605), both green at this tree

🤖 Generated with Claude Code

Agent notes
  • Captain: GStack Minder; lane GSTA-488. Scope: lib/pregate/checks/secrets.ts (the captain's brief said lib/pregate/secrets.ts; that path doesn't exist) and the hook bin/gstack-redact-prepush, which is the diff reader that imports it and holds the 64 MiB buffer. lib/pregate/index.ts is untouched (GSTA-465 / Stop the pre-merge check from accepting a half-finished run (GST-2194) #4258).
  • CI_CARRY: accepted ci-carry tree=54dc12485f73 tests=36942 runs=42731728299/1
  • PREGATE: requires-remote cleared (final tree)

Refs GST-2261

Approvals

Approved: yes (record r-bc7075abdcc5). The full approval record stays private.
Plan: exempt: bug fix
Plan check: exempt bug fix

REVIEW_LOOP: passes=2 blocking_found=3 deferred=0 noted=3 fixed=4 scope=frozen ledgers_read=5 fix_checks=1
Review-loop exception: accepted by Captain GStack Minder (GSTA-36) 2026-11-09 via approval a-d171d28be775 (GSTA-488 rule 11): one scoped fix-check at head 6bd89e1, covering the round-2 dedup fix (the 6ea1d57→6bd89e1 delta within 0ff06cc..6bd89e1) (fix-check at 6bd89e1, 2 findings)

{
  "schema_version": 1,
  "pr": 4261,
  "head": "4cb72faadc3fd95f847d97f97677d7996bf658de",
  "version": "1.98.0.0",
  "base": "main",
  "gate": {
    "test": {
      "pass": 36942,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "test",
      "run": 42738452057,
      "attempt": 1,
      "tree": "684f2a2e45d5f9ff24adca5027b0df07a41dbbcc"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "684f2a2e45d5f9ff24adca5027b0df07a41dbbcc",
  "product_patch_id": "d6b6cacd7997566fe93e93b580d6e8dde01357e1",
  "gstack_version": "1.98.0.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 107,
    "rules": "66e5174161eecc2c",
    "base": "56c4e873b2a83074ff8c832a178f3f90f7f86bc4",
    "registry": "56c4e873b2a83074ff8c832a178f3f90f7f86bc4",
    "gate_scan": {
      "tagged": 0,
      "head": "4cb72faadc3fd95f847d97f97677d7996bf658de"
    },
    "reasons": [
      "gate-class",
      "risk:secret",
      "risk:security",
      "runtime=107"
    ],
    "risk": [
      "secret",
      "security"
    ],
    "mode": "panel"
  },
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "review_targeted": {
    "classes": [
      "secret"
    ],
    "rules": "8811fd300bf305f0",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "d6b6cacd7997566fe93e93b580d6e8dde01357e1",
    "status": "done",
    "findings": 0,
    "raised_by": "targeted"
  }
}
{"head":"0f731c42a9b450083fe25320c449d2dc7bf97187","version":"1.98.0.0","gstack_version":"1.98.0.0","review_loop":{"passes":2,"blocking_found":3,"deferred":0,"noted":3,"fixed":4,"scope":"frozen","fix_checks":1,"rounds":3,"ledgers_read":5},"review_loop_exception":{"accepted_by":"Captain GStack Minder (GSTA-36)","date":"2026-11-09","via":"approval a-d171d28be775 (GSTA-488 rule 11)","reason":"one scoped fix-check at head 6bd89e199d8c2b87d0eb92c59a3f265fb6ccafc3, covering the round-2 dedup fix (the 6ea1d57→6bd89e1 delta within 0ff06cc..6bd89e1)","fix_check":{"head":"6bd89e199d8c2b87d0eb92c59a3f265fb6ccafc3","findings":2}},"depth":"full"}

…es in the push scan (GST-2261)

Each reading of a file git calls binary is now scanned as its own text with the file's line numbers, so a keyword and its value on the next line stay neighbours. The pre-push hook diffs with --irreversible-delete, so a deleted binary's old bytes no longer fill its 64 MiB buffer.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits November 9, 2026 23:15
Review-Finding: changelog.d/scan-binary-files-for-secrets.md:1:release reader=core
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…-2261)

Review-Finding: p1/specialist-batched#1 reader=specialist-batched
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan and others added 3 commits November 9, 2026 23:25
…listed token never hides another (GST-2261)

Review-Finding: p2/specialist-batched#1 reader=security
Review-Finding: p2/red-team#2 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…d in different readings still fail (GST-2261)

Review-Finding: audit/cross-family#1 reader=gpt-6.1-sol
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit ccc3f0f into main Nov 10, 2026
78 checks passed
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