Skip to content

FIX Detect postgresql://, mongodb+srv://, rediss:// and amqps:// connection strings in CredentialLeakScorer - #3639

Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/credential-leak-connection-schemes
Open

Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/credential-leak-connection-schemes

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #3638.

CredentialLeakScorer's "Connection String" pattern matched only the schemes mongodb, postgres, mysql, redis and amqp. URIs that embed a password under the scheme variants these services document were scored as no leak: the canonical postgresql://, MongoDB Atlas's mongodb+srv://, and the TLS variants rediss:// and amqps://.

  • _DEFAULT_PATTERNS: the scheme group is now mongodb(?:\+srv)?|postgres(?:ql)?|mysql|rediss?|amqps?.
  • GARAK_PATTERNS: the scheme group is now mongodb|postgres(?:ql)?|mysql|rediss?|amqps?. mongodb+srv:// is left out because the existing "MongoDB Cloud Connection String" pattern already matches it, and adding it here would report one leak under two pattern names.

The rest of each pattern is unchanged: user, :password@host, and the credential capture group that GARAK_PATTERNS exclusions rely on. A URI without credentials still doesn't match.

Tests and Documentation

New tests in tests/unit/score/regex/test_credential_leak_scorer.py:

  • test_connection_string_scheme_variants_detected: the four scheme variants match "Connection String" with the default patterns, and the score is True.
  • test_garak_connection_string_scheme_variants_detected: postgresql://, rediss:// and amqps:// match "Connection String" with GARAK_PATTERNS.
  • test_garak_mongodb_srv_reported_once: with GARAK_PATTERNS, mongodb+srv:// is reported only as "MongoDB Cloud Connection String".
  • test_connection_string_scheme_variant_without_credentials_not_detected: postgresql:// and rediss:// URIs without credentials are not reported.

7 of the 10 new cases fail on main (7facfdb). The other 3 are the "reported once" and "no credentials" guards, which pass on main too. With the fix, the whole file passes (201 tests). ruff check, ruff format --check and ty check are clean on both changed files.

No documentation changes: the scorer's docstring doesn't list the supported schemes. I didn't run JupyText because no notebooks are affected.

This change was prepared with the help of Claude Code (an AI coding assistant). I reviewed the change and the tests.

🤖 Generated with Claude Code

…ection strings in CredentialLeakScorer

The "Connection String" pattern matched only the mongodb, postgres, mysql,
redis and amqp schemes, so URIs that embed a password under the canonical
postgresql:// scheme, MongoDB Atlas's mongodb+srv:// or the TLS variants
rediss:// and amqps:// were scored as no leak. GARAK_PATTERNS leaves out
mongodb+srv://, which its MongoDB Cloud pattern already matches.

Fixes microsoft#3638

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
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.

BUG: CredentialLeakScorer misses postgresql://, mongodb+srv://, rediss:// and amqps:// connection strings

2 participants