Skip to content

fix: stop matching sk- keys inside longer words in the publication audit - #12

Open
Brendan-Lim wants to merge 1 commit into
mainfrom
fix/audit-openai-key-boundary
Open

Brendan-Lim wants to merge 1 commit into
mainfrom
fix/audit-openai-key-boundary

Conversation

@Brendan-Lim

Copy link
Copy Markdown
Member

Summary

Publication Security on main failed after #11 merged. The history audit flagged GitHub's merge commit e4bc812, whose message contains the branch name fix/cask-browser-download-url. That matches the OpenAI key pattern sk-[A-Za-z0-9_-]{20,}. It's a false positive, and it's now permanent in main's history, so the pattern needs fixing (rewriting main is not an option).

-sk-[A-Za-z0-9_-]{20,}
+(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}

An sk- key now counts only when it isn't the tail of a longer word (cask-, task-, disk-, risk-…). Keys at the start of a line or after =, a quote or a space are still caught. The other patterns are unchanged.

Evidence

  • Before: main run 44926415220: Publication audit (history): 850 file versions, 788 blobs, 1 findings (git-metadata, object e4bc812, line 24 = the merge message).
  • After: audit-public-files.py --history: 0 findings. Tracked: 0 findings.
  • New test test_sk_key_inside_a_longer_word_is_not_a_credential: fails on the old pattern, passes on the new one. It also checks that sk-… alone, after OPENAI_API_KEY=, after key: " and after a space are still flagged.
  • python3 -m unittest discover -s scripts/tests: 83 OK (2 skipped).

Merge Danger

Door: two-way

Blast Radius: the publication audit only. It's slightly narrower: a real sk- key glued directly to a preceding letter or digit (e.g. abcsk-…) would no longer be flagged by this script. Gitleaks still scans independently in the same workflow. The homebrew-tap copy of the script gets the same change in a matching PR.

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