-
Notifications
You must be signed in to change notification settings - Fork 15
masker_formatter: Allow catching multiple secrets in the same str #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22 +/- ##
==========================================
+ Coverage 91.82% 92.65% +0.83%
==========================================
Files 4 4
Lines 159 177 +18
==========================================
+ Hits 146 164 +18
Misses 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d36b5f2 to
4225008
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once missing lines are covered in tests, we're good
Description
Fixed a critical issue where only the first occurrence of a secret pattern was being detected and masked in log messages. The MaskerLogger now properly detects and masks all instances of secrets within the same string, significantly improving security coverage.
Related Issue
Fixes # (if there's an associated issue number)
Type of Change
Changes Made
ahocorasick_regex_match.py: Changed fromregex.search()toregex.finditer()to find all occurrences of each pattern in a line, not just the first one_mask_secret()method inmasker_formatter.py: Replaced the problematic string replacement approach with a position-based masking system that:Testing
Manual Testing Steps
"First password=secretpassword and second password=anothersecret and third password=secretpassword"Checklist
Screenshots (if applicable)
Before Fix:
After Fix:
Additional Context
This fix addresses a significant security vulnerability where sensitive data could leak through logs if the same secret appeared multiple times in a single log message. The previous implementation used
msg.replace(group, masked_part, 1)which explicitly limited replacement to only the first occurrence.The new implementation:
finditer()to find all regex matches in the textThis ensures comprehensive secret detection and masking while maintaining backward compatibility with existing functionality.
Note
Switch to find-all regex matching and a position-based masking algorithm to mask multiple/overlapping secrets, with extensive tests; bump version to 1.1.0b2.
regex.finditer()inmaskerlogger/ahocorasick_regex_match.pyto collect all matches per pattern._mask_secretinmaskerlogger/masker_formatter.pyto a position-based masker that:tests/test_masked_logger.py):pyproject.tomlto1.1.0b2.Written by Cursor Bugbot for commit 5d73052. This will update automatically on new commits. Configure here.