masker_formatter: Allow catching multiple secrets in the same str#22
Merged
masker_formatter: Allow catching multiple secrets in the same str#22
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.
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.
aviadlevy
requested changes
Nov 12, 2025
aviadlevy
approved these changes
Nov 13, 2025
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.
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.