fix(redact): mask passwords embedded in connection-string URLs - #169
Merged
Merged
Conversation
Keys like DATABASE_URL, REDIS_URL, MONGO_URI, AMQP_URL and SMTP_URL do not match the secret-key list, and the password inside a scheme://user:password@host URL matches none of the value-shaped patterns, so it was sent to the LLM in clear text. Add a userinfo pattern that masks only the password, keeping the scheme, user, and host visible so the model can still flag the credential. Adds tests covering the leak and a no-false-positive case for credential-free URLs. Closes OWASP#168
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
==========================================
+ Coverage 78.95% 81.13% +2.17%
==========================================
Files 26 32 +6
Lines 4158 5136 +978
==========================================
+ Hits 3283 4167 +884
- Misses 875 969 +94
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
advaitpatel
approved these changes
Sep 15, 2026
advaitpatel
left a comment
Collaborator
There was a problem hiding this comment.
lgtm, thank you for your contributions
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 & why
docksec/redact.pymasks secrets before file content is sent to the LLM, but it missed passwords embedded in connection-string URLs (scheme://user:password@host). Keys such asDATABASE_URL,REDIS_URL,MONGO_URI,AMQP_URL, andSMTP_URLdon't match the secret-key list, and the password inside the URL matches none of the value-shaped patterns, so it reached the provider in clear text. These URLs are one of the most common ways secrets show up in Dockerfiles and compose files.Before:
After:
# -> ('ENV DATABASE_URL=postgres://admin:[REDACTED-BY-DOCKSEC]@db:5432/app', 1)Approach
Adds a
_URL_CREDENTIALSpattern that matches the userinfo of a URL and masks only the password, keeping the scheme, user, and host visible — consistent with the module's existing principle that "the key names stay visible, which is all the model needs to flag an exposed credential." It runs per line alongside the other value-shaped checks, so it applies regardless of the key name and covers theENV, list-style, and quoted forms.Handles
redis://:pw@host(empty username) and leaves credential-free URLs (https://example.com,postgres://db:5432/app) untouched.Tests
test_redacts_password_in_url_credentials— five real URL forms; asserts each password is gone and the surrounding structure is preserved.test_leaves_url_without_password_alone— no false positives on URLs with no embedded credential.Verification (matches CONTRIBUTING's local checks):
pytest tests/→ 271 passed, 2 skipped;black --check,isort --check-only, andmypy docksec/redact.pyclean.Closes #168