Skip to content

Secret scan: catch untyped PKCS#8 key headers and literal *_TOKEN assignments - #1065

Merged
hyperpolymath merged 2 commits into
mainfrom
claude/secret-pattern-gaps
Nov 13, 2026
Merged

hyperpolymath merged 2 commits into
mainfrom
claude/secret-pattern-gaps

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

The live CLI secret scan (cli.ex → SecurityErrors.detect_secrets/1) missed two secret shapes. Both came from estate bot findings in November 2026.

  • Untyped PKCS#8 key header. -----BEGIN [A-Z]+ PRIVATE KEY----- needed a type word, so BEGIN PRIVATE KEY never matched. That untyped header is the format a GitHub App private key comes in. The pattern now accepts zero or more type words, plus PGP's PRIVATE KEY BLOCK. Public keys and certificates still don't match.
  • Literal *_TOKEN assignments. Nothing saw a literal value assigned to a *_TOKEN name in shell, env or YAML. The new "Token assignment" pattern needs an UPPER_SNAKE *_TOKEN name, then = or :, then a value of 20+ characters that contains a digit. Values starting with $, { or < are skipped, because those are references or placeholders.

Evidence

I ran the patterns over every tracked file in hypatia, cicd-squabbler, gitbot-fleet and standards:

  • 0 new Token assignment hits.
  • The only Private Key hits are two test lines that were already flagged before this change (test/ is exempt).

test/rules/secret_pattern_gaps_test.exs covers six key-header kinds (positive), public keys and certificates (negative), three literal token forms (positive) and six reference or placeholder forms (negative). The test builds headers and values at runtime, so the file holds no secret-shaped literal.

Testing

I ran these locally on Elixir 1.17.3 / OTP 25, with a harness that leaves out the web and neural tiers. The scope was test/rules, scanner_suppression_test, proof_source_secret_test and cli_test: 679 tests, 0 failures. CI is the first full run.

mix format under 1.17 flags security_errors.ex:696-702. Those lines are unchanged here, and main has the same diff, so this is probably a formatter-version difference.


Generated by Claude Code

…ssignments

Two secret shapes the live CLI secret scan (cli.ex -> detect_secrets/1)
missed, both from estate bot findings in November 2026:

- `-----BEGIN [A-Z]+ PRIVATE KEY-----` needed a type word, so the
  untyped PKCS#8 header -- the format a GitHub App private key comes in
  -- never matched. The pattern now accepts zero or more type words and
  PGP's `PRIVATE KEY BLOCK`. Public keys and certificates still do not
  match.
- No rule saw a literal value assigned to a *_TOKEN name in shell, env
  or YAML. New "Token assignment" pattern: an UPPER_SNAKE *_TOKEN name,
  `=` or `:`, then a value of 20+ characters that contains a digit and
  does not start with `$`, `{` or `<` (references and placeholders).

Measured on every tracked file of hypatia, cicd-squabbler, gitbot-fleet
and standards: 0 new Token assignment hits; the only Private Key hits
are two test lines already flagged before this change (test/ is
exempt). Tests build key headers and token values at runtime so the
test file holds no secret-shaped literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 41eff638-1695-48db-a9ab-702b628fd128
Commits

Reviewing files that changed from the base of the PR and between a8e7866 and 6a3059a.

Files selected for processing: 3

  • lib/hypatia/scanner_suppression.ex
  • lib/rules/security_errors.ex
  • test/rules/secret_pattern_gaps_test.exs
  • Autofix · 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

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 13, 2026 13:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T13:44:53.494925Z 6a3059a New commits
🔒 Security Review ❌ Failed 2026-11-13T13:40:20.971915Z
We couldn’t complete this review. Comment @codex security review to try again.
6a3059a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3352029476

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/rules/security_errors.ex Outdated
Comment on lines +613 to +614
{~r/\b[A-Z][A-Z0-9_]*_TOKEN[ \t]*[=:][ \t]*["']?(?![$\{<])(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recognize dotted token references before raising a leak

For assignments such as const DEPLOY_TOKEN = process.env.DEPLOY_TOKEN_V2, the dotted reference consists entirely of the permitted characters, exceeds 20 characters, and contains a digit, so it is labeled as a literal token. The CLI then emits a critical revoke_rotate_and_purge finding because the line is neither a placeholder nor a comment. The reference exclusion needs to cover common forms such as process.env.* and Terraform's var.*, rather than relying on the presence of a digit to distinguish literals.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a3059a. The pattern now has a negative lookahead for dotted references: process.env., import.meta.env., os.environ, var./vars., secrets., env., local./locals., data., module., self., config., settings., inputs., steps., needs. and github.. A test covers process.env.DEPLOY_TOKEN_V2…, var.…, secrets.… and os.environ…; none is labelled a token. I kept the digit requirement as well, since it still screens out UPPER_SNAKE variable names that have no dot.


Generated by Claude Code

Comment thread lib/rules/security_errors.ex Outdated
Comment on lines +613 to +614
{~r/\b[A-Z][A-Z0-9_]*_TOKEN[ \t]*[=:][ \t]*["']?(?![$\{<])(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept quoted YAML token keys

A valid YAML assignment such as "SONAR_TOKEN": "abc123..." is missed because the match can begin at SONAR_TOKEN, but the closing key quote appears where the regex requires whitespace, =, or :. Since this pattern explicitly targets YAML, it should allow matching quotes around the key as well as around the value.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a3059a. An optional quote is now allowed after the key name, so "SONAR_TOKEN": "…" matches. A test covers the quoted form.


Generated by Claude Code

Comment thread lib/rules/security_errors.ex Outdated
Comment on lines +613 to +614
{~r/\b[A-Z][A-Z0-9_]*_TOKEN[ \t]*[=:][ \t]*["']?(?![$\{<])(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow base64 punctuation at the start of token values

The comment excludes only values beginning with $, {, or <, but the mandatory first-value class is [A-Za-z0-9], so otherwise eligible tokens beginning with /, +, -, or _ are silently missed. In particular, standard Base64 credentials can begin with / or +; these characters are already accepted everywhere after the first position, so the initial character restriction creates a real secret-scanning false negative.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a3059a. The first value character may now be /, +, - or _ as well as alphanumerics; only $, { and < starts are excluded, as the comment said. A test covers all four leading characters.


Generated by Claude Code

Comment thread lib/rules/security_errors.ex Outdated
Comment on lines +613 to +614
{~r/\b[A-Z][A-Z0-9_]*_TOKEN[ \t]*[=:][ \t]*["']?(?![$\{<])(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Suppress commented token-assignment examples

When a non-first comment line contains an example such as # DEPLOY_TOKEN=abcdefghijklmnopqr1, this new form-only pattern returns Token assignment, but ScannerSuppression.comment_masked_secret_label?/3 suppresses only the three existing form-ambiguous labels. The CLI therefore reports a medium credential finding for ordinary commented documentation, even though equivalent generic API-key, secret, and password assignments are dropped as documentation noise; the new label needs to participate in that suppression path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a3059a. "Token assignment" is now in @form_ambiguous_secret_labels in ScannerSuppression, alongside the generic API-key, secret and password labels, so a whole-line comment such as # DEPLOY_TOKEN=… is suppressed as documentation. A test asserts comment_masked_secret_label?/3 returns true for it.


Generated by Claude Code

Comment thread lib/rules/security_errors.ex Outdated
Comment on lines +613 to +614
{~r/\b[A-Z][A-Z0-9_]*_TOKEN[ \t]*[=:][ \t]*["']?(?![$\{<])(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Collapse overlapping token detections into one finding

For an assignment such as GITHUB_TOKEN=ghp_<36-character body containing a digit>, both the existing GitHub PAT matcher and this new generic assignment matcher return labels. detect_secrets_with_context/4 only deduplicates identical labels and then emits one finding per remaining label, so a single leaked credential now produces two critical findings and two annotations, inflating scan counts. The generic assignment hit should be discarded when a specific credential matcher already identified the same line, or the output should be deduplicated at the line and rule level.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6a3059a. detect_secrets/1 now drops the generic "Token assignment" label whenever a specific credential matcher (GitHub PAT, npm token, …) has also matched the line, so one leaked credential is one finding. A test asserts GITHUB_TOKEN=ghp_… yields "GitHub PAT" and not "Token assignment".


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Red checks: none are from this diff

This PR changes two files: lib/rules/security_errors.ex (@secret_patterns) and a new test. It touches no Rust, Cargo, container or workflow file.

  • Build Test Images / Integration Status — Containerfile:58 cargo build --package hypatia-cli exits 101 (TARGET not defined at compile time; error[E0658] atomic_try_update). The image's Rust is older than the host CI toolchain. Red on main too (runs 43357534889, 43264284438). Integration Status is its rollup.
  • Rust Dependency Audit / Security Status — cargo audit on a transitive advisory (quinn-udp, RUSTSEC-2026-0538). No Cargo files change here.

Both need their own estate-wide change. Detail and evidence in #1064.


Generated by Claude Code

…keys, one finding per secret

Addresses the five Codex findings on #1065:

- Dotted references (process.env.X, import.meta.env.X, os.environ,
  var./vars./secrets./env./inputs./steps./needs./github. and similar)
  are not literal tokens. Without this, `DEPLOY_TOKEN =
  process.env.DEPLOY_TOKEN_V2` became a critical revoke-and-rotate
  finding.
- A quoted key (`"SONAR_TOKEN": "..."`, YAML or JSON) now matches.
- A value may begin with base64 punctuation (`/`, `+`, `-`, `_`); only
  `$`, `{`, `<` starts are excluded, as the comment said.
- "Token assignment" joins the form-ambiguous labels in
  ScannerSuppression, so a commented-out example is documentation, the
  same as the generic API-key, secret and password labels.
- detect_secrets/1 drops the generic "Token assignment" label when a
  specific credential matcher (GitHub PAT, npm, ...) already named the
  value, so one leaked secret is one finding, not two.

Re-measured on every tracked file of hypatia, cicd-squabbler,
gitbot-fleet and standards: still 0 Token assignment hits. 684 tests
pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@sonarqubecloud

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a3059a41d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +638 to +640
if labels != ["Token assignment"] and "Token assignment" in labels and
Enum.any?(labels, &(&1 not in @form_only_labels)) do
List.delete(labels, "Token assignment")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate only overlapping credential matches

When detect_secrets/1 receives an entire file from Rules.scan_file/3, these lines remove Token assignment whenever any specific credential appears anywhere else in that file. For example, a file containing a GitHub PAT on one line and a distinct literal DEPLOY_TOKEN on another produces only the PAT finding, so fixing that finding leaves the second leaked credential undetected by the reviewer path. Deduplication needs to establish that the generic and specific patterns matched the same value rather than comparing file-wide labels.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6ef7516. The de-duplication now compares values, not labels: "Token assignment" is dropped only when every assignment value it matched is itself named by a specific matcher (the same secret twice). A test puts a GitHub PAT and a distinct literal DEPLOY_TOKEN in one file; both are reported.


Generated by Claude Code

Comment on lines +616 to +617
{~r/\b[A-Z][A-Z0-9_]*_TOKEN["']?[ \t]*[=:][ \t]*["']?(?![$\{<])(?!(?:process\.env|import\.meta\.env|os\.environ|vars?|secrets|env|locals?|data|module|self|config|settings|inputs|steps|needs|github)\.)(?=[A-Za-z0-9_\-.\/+=]*[0-9])[A-Za-z0-9_\-\/+][A-Za-z0-9_\-.\/+=]{19,}/,
"Token assignment"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply reference exemptions to individual assignments

In the live CLI path, detect_secrets_with_context/4 skips an entire line before invoking this new matcher whenever context_safe_line?/2 sees a secret reference. Consequently, a valid shell line such as DEPLOY_TOKEN=abcdefghijklmnopqrst1 API_TOKEN=$API_TOKEN ./deploy is treated as wholly safe: the referenced second assignment suppresses detection of the distinct hardcoded token added here. The exemption must be scoped to the referenced assignment rather than bypassing secret detection for the whole line.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is real, but it predates this PR and is not specific to the new pattern, so I have not changed it here.

ScannerSuppression.context_safe_line?("secret_detected", line, _) returns true for the whole line whenever it contains a ${{ secrets.X }} / ${{ vars.X }} reference, a shell ${VAR} / $VAR expansion, an env default, or a Rust test literal. cli.ex then skips detect_secrets/1 for that line entirely. That applies to every secret label, not just "Token assignment": a line such as AWS_ACCESS_KEY_ID=AKIA… OTHER=${{ secrets.X }} has always been skipped too.

The right fix is to mask only the reference spans and still scan the rest of the line. That changes suppression for every label across the estate, so it may surface new true positives and needs its own measured PR (with a before/after count over the estate) rather than riding on this one. I've raised it with the repository owner as a follow-up.


Generated by Claude Code

@hyperpolymath
hyperpolymath enabled auto-merge (squash) November 13, 2026 13:46
@hyperpolymath
hyperpolymath merged commit 0e6dd08 into main Nov 13, 2026
86 of 88 checks passed
@hyperpolymath
hyperpolymath deleted the claude/secret-pattern-gaps branch November 13, 2026 13:46
hyperpolymath added a commit that referenced this pull request Nov 13, 2026
…er (#1068)

## What

Follow-up to #1065. It merged at `6a3059a`, one commit before this fix,
so `main` currently has the bug below.

`detect_secrets/1` also receives whole files (via `Rules.scan_file/3`).
Its de-duplication dropped the generic "Token assignment" label whenever
**any** specific credential (a GitHub PAT, an npm token, …) appeared
anywhere in the content. So a file with a PAT on one line and a separate
literal `DEPLOY_TOKEN=…` on another reported only the PAT. Fixing that
one finding left the second leaked credential undetected.

The generic label is now dropped only when **every** value it matched is
itself named by a specific matcher — that is, the same secret reported
twice.

Codex found this on #1065 (the per-value comparison it asked for).

## Testing

New test: one file holding a GitHub PAT and a distinct literal
`DEPLOY_TOKEN`. Both are reported. `secret_pattern_gaps_test`,
`scanner_suppression_test` and `cli_test`: 112 tests, 0 failures (local
Elixir 1.17 / OTP 25 harness).

---
_Generated by [Claude
Code](https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT)_

Co-authored-by: CLAUDE <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
hyperpolymath added a commit that referenced this pull request Nov 14, 2026
## Summary
Follow-up to #1063. Docs only:
`docs/reports/coverage-matrix/{matrix.json,README.adoc}`. No rule, CI or
code changes.

- Adds `sq_id` to the rows that overlap a cicd-squabbler FIX/ACT rule
(ADR 0004): 4 full, 4 partial overlaps.
- Three route conflicts resolved in the squabbler's favour (ADR 0003):
`pull-request-target-checkout`, Scorecard Dangerous-Workflow and
`pages-build-failure` are now `owner-only` (SQ-OWN-03, SQ-OWN-01).
- Adds 18 squabbler-only rows keyed by SQ id (estate-specific, not
public-platform rules). Hypatia detection for them is `unassessed`.
- Adds a `referral` row for tag-keyed `actions.lock` records refused by
the standards pin-contract gate (hypatia#1090, draft).
- CodeRabbit and Codex rate-limit/credit rows are now route `noise`
(ruling R7).
- README documents the routes `noise` and `upstream` and the `rerun` fix
status.

Agreed with the Rule reconciliation thread (experiment owner) and sent
to Tsunami-breaker before opening. The 4 detection gaps (concurrency,
Dockerfile/shell pins, Renovate, SAST) are the experiment owner's first
cases.

## Status: DRAFT
- Detection statuses still come from reading code, not fixtures; rows
citing #1064/#1065/#1090 stay `unassessed`.
- Not for auto-merge; leave for review.
- Known red checks on this PR (`cli/` container build, `quinn-udp`
cargo-audit, and their rollups) are also red on `main` and are not
caused by this diff.

## Test plan
- [ ] Verify `partial` and `unassessed` rows with offline fixtures
(experiment owner)
- [ ] Re-key ids to the reconciliation thread's `<domain>/<name>` scheme
as they land

---
_Generated by [Claude
Code](https://claude.ai/code/session_0136P7ZmVXyECkfzpj3uaW6p)_

---------

Co-authored-by: Claude <[email protected]>
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.

3 participants