fix(redact): add GitLab and PyPI token prefixes to secret detection - #32
fix(redact): add GitLab and PyPI token prefixes to secret detection#32DevChiniwala wants to merge 1 commit into
Conversation
The KEY_PREFIXES array covers content-shaped secrets that appear in bot replies, tool titles, and permission cards. Two well-documented credential prefixes were missing: - glpat- (GitLab personal access tokens) - pypi- (PyPI API tokens) Both are unmistakable and meet the "high precision on purpose" criterion stated in the module's header comment: a false positive on either prefix is essentially impossible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The PyPI token regex is currently too permissive (high false-positive risk vs the module’s stated “high precision” goal) and should be tightened to the documented token format, with the corresponding test fixture updated.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the server-side secret redaction heuristics to recognize additional content-shaped credential prefixes that can appear in free-form text (bot replies, tool titles, permission cards), extending coverage beyond key-name-based detection.
Changes:
- Added
glpat-detection to redact GitLab personal access tokens. - Added
pypi-detection to redact PyPI API tokens. - Extended
redactSecretsInTexttest coverage with new prefix fixtures built at runtime.
File summaries
| File | Description |
|---|---|
| server/redact.ts | Adds new KEY_PREFIXES regex patterns for GitLab and PyPI token prefixes. |
| server/redact.test.ts | Adds new test cases ensuring redactSecretsInText masks the new token shapes. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /\bAIza[0-9A-Za-z_-]{30,}/g, // google api key | ||
| /\bnpm_[A-Za-z0-9]{20,}/g, // npm | ||
| /\bglpat-[A-Za-z0-9_-]{20,}/g, // gitlab personal access token | ||
| /\bpypi-[A-Za-z0-9_-]{16,}/g, // pypi api token |
| [`google ${"AIza" + "SyA-"}${alpha.slice(0, 32)}`, /AIza/], | ||
| [`npm ${"npm" + "_"}${alpha}`, /npm_[a-z]/], | ||
| [`gitlab ${"glpat" + "-"}${alpha}`, /glpat-[a-z]/], | ||
| [`pypi ${"pypi" + "-"}${alpha.slice(0, 24)}`, /pypi-[a-z]/], |
|
@DevChiniwala — thanks for this one too. Both prefixes are real gaps and the change is in the right place. One of the two needs tightening before I take it.
|
| input | {16,} (current) |
{48,} |
|---|---|---|
pypi-publishing-workflow |
MATCH | — |
pypi-mirror-configuration |
MATCH | — |
pypi-upload-action-v1 |
MATCH | — |
pypi-trusted-publisher-github-action-config |
MATCH | — |
| a real PyPI token (macaroon, ~150 chars) | MATCH | MATCH |
Any transcript discussing Python packaging would get chewed up. That runs against the module's own stated contract, a few lines above your change:
High precision on purpose: a generic "long hex/base64" heuristic would rewrite real code in the transcript, so only shapes that are unmistakably credentials match.
Real PyPI tokens are macaroons — pypi- followed by ~150+ characters of base64url — so there's a lot of headroom to raise the floor without risking a miss.
Requested change
/\bpypi-[A-Za-z0-9_-]{48,}/g, // pypi api tokenThat clears all four false positives above and still matches a real token comfortably.
Your test fixture uses alpha.slice(0, 24), which won't reach 48 — it'll need lengthening alongside the regex. Something like ${alpha}${alpha} is plenty.
One coordination note
This and #33 both insert after the npm_ line in server/redact.ts and at the same spot in server/redact.test.ts. I confirmed they conflict with each other — whichever I merge first, the other will need a rebase. Nothing wrong with either; just so it isn't a surprise.
CI hasn't run yet — GitHub holds workflow runs for first-time contributors until a maintainer approves. I'll approve it.
Bump the pypi- threshold and the fixture and I'll take this.
Summary
KEY_PREFIXESinserver/redact.tscovers content-shaped secrets that can appear in bot replies, tool titles, and permission cards — places where the key-name heuristic (isSecretName) does not apply. Two well-documented credential prefixes were missing:glpat-— GitLab personal access tokens. Always this prefix, documented by GitLab.pypi-— PyPI API tokens. Always this prefix, documented by PyPI.Both meet the "high precision on purpose" criterion in the module header: they are unmistakably credentials, cannot match ordinary code or prose, and follow the same naming convention as the existing entries.
What changed
KEY_PREFIXESinserver/redact.ts, positioned between the existingnpm_and JWT patterns.server/redact.test.ts, following the existing split-prefix pattern that avoids the test file itself being redacted.Test plan
pnpm typecheckcleanpnpm check:brandclean