fix(redact): detect modern OpenAI keys (sk-proj-/sk-svcacct-/sk-admin- with -/_ body)#1867
Open
jbetala7 wants to merge 1 commit into
Open
fix(redact): detect modern OpenAI keys (sk-proj-/sk-svcacct-/sk-admin- with -/_ body)#1867jbetala7 wants to merge 1 commit into
jbetala7 wants to merge 1 commit into
Conversation
The HIGH-tier `openai.key` pattern required a contiguous [A-Za-z0-9] run right after the prefix, so real `sk-proj-`/`sk-svcacct-`/`sk-admin-` keys (base64url body with `-` and `_`) produced no finding at all — a genuinely-secret credential failing OPEN past the redaction gate used by /spec, /ship, /cso, and /document-*. The sibling `anthropic.key` pattern already allows separators. Widen the body charset to [A-Za-z0-9_-] only on the prefixed form; the bare `sk-` legacy path keeps its narrow alnum match so it does not start matching kebab/snake identifiers that begin with `sk-`. Linear-time, passes redact-pattern-lint. +regression test for the separator forms. Fixes garrytan#1866 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
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.
Problem
lib/redact-patterns.tsopenai.keyis HIGH tier (block), but it only matches a contiguous alphanumeric body:Modern OpenAI keys aren't pure-alphanumeric. Project / service-account / admin keys (
sk-proj-,sk-svcacct-,sk-admin-) use a base64url-style body containing-and_— the same charset gitleaks / trufflehog / GitHub secret scanning use for OpenAI.[A-Za-z0-9]{32,}stops at the first separator, never reaches 32 chars, and the scan returns no finding at all: a genuinely-secret HIGH credential fails open through the redaction gate behind/spec,/ship,/cso, and/document-*.The sibling
anthropic.keyin the same file already permits separators (sk-ant-[A-Za-z0-9_\-]{20,});openai.keyis the inconsistent one.Repro on
main(c43c850)lib/redact-enginescan()of realistic prefixed keys:test/redact-engine.test.tsonly exercised"sk-proj-" + "a".repeat(40), so the gap was untested.Root cause
The body character class excludes
-/_, which real modern keys contain.Fix
Widen the body charset to
[A-Za-z0-9_\-]only on the prefixed form, and keep the baresk-legacy path narrow (alnum) so it doesn't start matching kebab/snake identifiers that begin withsk-:Single bounded quantifier per alternative — linear-time, passes
redact-pattern-lint. No tier/visibility/engine changes.Testing
openai.key, the legacy baresk-form still flags, and a shortsk-kebab identifier does not (FP guard).bun test test/redact-engine.test.ts test/redact-pattern-lint.test.ts test/redact-engine-autoredact.test.ts→ 101 pass, 0 fail.bun test test/redact-doc-resolver.test.ts test/redact-prepush-hook.test.ts test/gstack-redact-cli.test.ts→ 30 pass, 0 fail (description change is doc-safe).Fixes #1868
🤖 Generated with Claude Code