Skip to content

fix(scan): stop reporting a DSN whose password slot is a template - #175

Merged
ralyodio merged 1 commit into
masterfrom
fix/dsn-template-placeholder
Sep 3, 2026
Merged

fix(scan): stop reporting a DSN whose password slot is a template#175
ralyodio merged 1 commit into
masterfrom
fix/dsn-template-placeholder

Conversation

@ralyodio

@ralyodio ralyodio commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What

secret-database-url fires 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 one high per profile.

terrablue/devdb is the clean example — 9 files, 4 findings, all high, all in profiles.go, and all of them the template strings that are the repository's entire point:

dsn: "postgres://{{.user}}:{{.pass}}@{{.host}}:{{.port}}/{{.name}}"
dsn: "mongodb://{{.user}}:{{.pass}}@{{.host}}:{{.port}}/{{.name}}"
dsn: "redis://:{{.pass}}@{{.host}}:{{.port}}"

Zero true positives on the only file that matters, at high. Any CI gate is red on day one.

The fix

KNOWN_PLACEHOLDERS gains one pattern: a credential segment whose password slot is an interpolation — {{…}}, ${…}, $VAR, %s/%d/%v.

This is a stronger claim than the user:pass exemption 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:

DSN Before After
postgres://{{.user}}:{{.pass}}@host/db high exempt
redis://:{{.pass}}@host:6379 high exempt
mysql://${DB_USER}:${DB_PASS}@host/app high exempt
postgres://{{.user}}:hunter2@host/db high still high
postgres://devdb:Kd93mQpZx2@{{.host}}/devdb high still high

The last two rows are the cases this must not swallow, and they are asserted.

Verification

  • New packages/scan/src/__tests__/devdb-regression.test.ts, following limen-regression.test.ts — 4 tests, 2 of them guarding real credentials.
  • Full scan suite: 351 passing, 15 files. tsc --noEmit clean.
  • End-to-end through the built CLI: devdb 4 findings → 0.

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

`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
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

ThreatCrush Security Scan

12 finding(s)

HIGH/CRITICAL: 1 | MEDIUM: 6 | LOW: 5

Severity Rule Location
HIGH secret-aws-access-key prd/0003-detect-hardcoded-secrets-before-they-are-committed-or-served.md:126
MEDIUM js-open-redirect apps/web/src/app/auth/login/page.tsx:50
MEDIUM js-unescaped-html-sink apps/web/src/app/hire/page.tsx:96
MEDIUM js-unescaped-html-sink apps/web/src/app/hire/page.tsx:100
MEDIUM js-open-redirect apps/web/src/components/funding/FundingClient.tsx:97
MEDIUM js-unescaped-html-sink apps/web/src/components/GuideReader.tsx:265
MEDIUM js-uninitialized-buffer packages/scan/src/node-rules.ts:456
LOW secret-generic-credential PRD.md:269
LOW tls-verification-disabled prd/0004-find-dangerous-code-patterns-without-pretending-to-be-a-compiler.md:121
LOW tls-verification-disabled prd/0004-find-dangerous-code-patterns-without-pretending-to-be-a-compiler.md:122
LOW sh-remote-script-execution scripts/smoke-test.sh:47
LOW secret-aws-access-key scripts/smoke-test.sh:112

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit c98eebf into master Sep 3, 2026
11 checks passed
@ralyodio
ralyodio deleted the fix/dsn-template-placeholder branch September 3, 2026 11:14
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