Skip to content

fix(sanitize): redact credentials in URLs of any scheme - #512

Open
liwenjie200543 wants to merge 1 commit into
Tencent-Hunyuan:mainfrom
liwenjie200543:fix/sanitize-url-credential-schemes
Open

liwenjie200543 wants to merge 1 commit into
Tencent-Hunyuan:mainfrom
liwenjie200543:fix/sanitize-url-credential-schemes

Conversation

@liwenjie200543

Copy link
Copy Markdown

_URL_CREDENTIAL only matches http(s)://, so the same user:password@ block in a
database or broker URL is left in the text: DATABASE_URL=postgres://…,
MONGODB_URI=mongodb+srv://…, BROKER=amqp://… and REDIS_URL=redis://:… all reach
the model with the password intact, while the same credentials under http:// are
redacted.

The scheme is now any RFC 3986 scheme ([A-Za-z][A-Za-z0-9+.-]*://) and the user
part may be empty, which is how Redis writes a password-only URL. A plain
ssh://git@host/path has no : before its @, so it is still not matched.

Before → after (sanitize_model_input):

DATABASE_URL=postgres://alice:s3cr3t-pass@db.internal:5432/app
    -> DATABASE_URL=postgres://alice:<redacted-secret>@db.internal:5432/app
REDIS_URL=redis://:s3cr3t-pass@cache.internal:6379/0
    -> REDIS_URL=redis://:<redacted-secret>@cache.internal:6379/0

Tests: test_redacts_credentials_in_urls_of_any_scheme in
memhub/apps/core/tests/test_input_sanitization.py. 23 passed / 1 failed before the
change, 24 passed after. Ran the two sanitization test files standalone (the package
conftest.py imports pwd, which does not exist on Windows).


Found in the same audit as #511. That one is _AUTHORIZATION (header value with
punctuation, redacted or not); this one is _URL_CREDENTIAL (which schemes are
covered at all) — separate patterns, separate tests, and the #511 case still leaks on
this branch. Say the word and I will fold both into one PR instead.

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