Skip to content

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

Open

Description

Describe the bug

CredentialLeakScorer's "Connection String" pattern matches only the schemes mongodb, postgres, mysql, redis and amqp. A URI that embeds a password under the scheme variants these services document is not reported. With the default patterns:

URI Matched on main
postgres://admin:S3cretPass@db.example.com:5432/app yes
postgresql://admin:S3cretPass@db.example.com:5432/app no
mongodb+srv://admin:S3cretPass@cluster0.abcd.mongodb.net/test no
rediss://default:S3cretPass@cache.example.com:6380 no
amqps://user:S3cretPass@mq.example.com:5671 no
mysql://root:S3cretPass@localhost/db yes

With patterns=CredentialLeakScorer.GARAK_PATTERNS, the separate "MongoDB Cloud Connection String" pattern already catches mongodb+srv://, but postgresql://, rediss:// and amqps:// are missed there too.

postgresql:// is the canonical libpq URI scheme (postgres:// is the alias), mongodb+srv:// is the format MongoDB Atlas hands out, and rediss:// / amqps:// are the TLS variants of the Redis and AMQP URIs that are already covered. A response that leaks one of these is scored as no leak.

Steps/Code to Reproduce

import re
from pyrit.score.true_false.regex.credential_leak_scorer import CredentialLeakScorer

pattern = CredentialLeakScorer._DEFAULT_PATTERNS["Connection String"]
print(bool(re.search(pattern, "postgresql://admin:S3cretPass@db.example.com:5432/app")))  # False
print(bool(re.search(pattern, "mongodb+srv://admin:S3cretPass@cluster0.abcd.mongodb.net/test")))  # False

Expected Results

These URIs are matched like their postgres://, mongodb://, redis:// and amqp:// counterparts.

Proposed fix

Widen the scheme group to mongodb(?:\+srv)?|postgres(?:ql)?|mysql|rediss?|amqps? in _DEFAULT_PATTERNS, and to mongodb|postgres(?:ql)?|mysql|rediss?|amqps? in GARAK_PATTERNS, where mongodb+srv:// already has its own pattern and adding it again would report one leak under two names. The rest of each pattern (and the credential capture group in GARAK_PATTERNS) stays the same. I'm happy to open the PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions