fix(scan): stop reporting a DSN whose password slot is a template - #175
Merged
Conversation
`secret-database-url` matched any connection string with a credential
segment, so a tool that builds DSNs at run time got one `high` per
profile. terrablue/devdb is the clean case: four findings, all of them
the literal template strings that are the repository's core data —
`postgres://{{.user}}:{{.pass}}@{{.host}}:{{.port}}/{{.name}}` and its
mongo and redis siblings.
Exempt the credential segment when an interpolation fills the password
slot: Go and Handlebars `{{…}}`, shell and JavaScript `${…}`, bare
`$VAR`, printf `%s`. This is a stronger claim than the neighbouring
`user:pass` exemption rather than a looser one — that rule reads English
words and infers intent, while these cannot occur in a credential at
all, since the value that reaches the driver is whatever the template
engine substitutes.
Only the password slot decides it, so `postgres://{{.user}}:hunter2@`
stays reported at `high`. devdb goes 4 findings to 0, verified through
the built CLI; the full scan suite is 351 passing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CnhqMwFo6ceywCRLdU2EG
ThreatCrush Security Scan12 finding(s) HIGH/CRITICAL: 1 | MEDIUM: 6 | LOW: 5
Snippets are redacted; ThreatCrush never prints matched credential material. |
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.
What
secret-database-urlfires on any connection string with a credential segment before the@. It does not check what sits in that segment, so a tool whose job is building DSNs gets onehighper profile.terrablue/devdb is the clean example — 9 files, 4 findings, all
high, all inprofiles.go, and all of them the template strings that are the repository's entire point:Zero true positives on the only file that matters, at
high. Any CI gate is red on day one.The fix
KNOWN_PLACEHOLDERSgains one pattern: a credential segment whose password slot is an interpolation —{{…}},${…},$VAR,%s/%d/%v.This is a stronger claim than the
user:passexemption next to it, not a looser one. That rule reads English metasyntactic words and infers intent. An interpolation cannot occur in a credential at all: the value that reaches the driver is whatever the template engine substitutes, so there is nothing in the file to leak.The username is not a credential, so only the password slot decides it:
postgres://{{.user}}:{{.pass}}@host/dbredis://:{{.pass}}@host:6379mysql://${DB_USER}:${DB_PASS}@host/apppostgres://{{.user}}:hunter2@host/dbpostgres://devdb:Kd93mQpZx2@{{.host}}/devdbThe last two rows are the cases this must not swallow, and they are asserted.
Verification
packages/scan/src/__tests__/devdb-regression.test.ts, followinglimen-regression.test.ts— 4 tests, 2 of them guarding real credentials.tsc --noEmitclean.Scope
Only the DSN rule. It does not touch the AWS-key reasoning deliberately excluded from
KNOWN_PLACEHOLDERS, and it drops nothing that carries an actual value.🤖 Generated with Claude Code
https://claude.ai/code/session_017CnhqMwFo6ceywCRLdU2EG