Repository navigation
Check same-position patterns after a scrubbing callback allows a match - #2826
Conversation
PR overviewNo security issues were found in this pull request. Reviews
|
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 5/5
- In
logfire-sdk/logfire/_internal/scrubbing.py, a user pattern identical to a default can make the callback run twice for the same match. Deduplicate the patterns before compiling them.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="logfire-sdk/logfire/_internal/scrubbing.py">
<violation number="1" location="logfire-sdk/logfire/_internal/scrubbing.py:285">
P3: The individual pattern list is not deduplicated, so a user `extra_patterns` entry identical to a default pattern makes the callback run twice for the same match. Deduplicate the pattern sequence before compiling it.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| patterns = [_DEFAULT_PATTERN, *(patterns or [])] | ||
| self._pattern = re.compile('|'.join(patterns), re.IGNORECASE | re.DOTALL) | ||
| self._individual_patterns = tuple( | ||
| re.compile(pattern, re.IGNORECASE | re.DOTALL) for pattern in [*DEFAULT_PATTERNS, *patterns[1:]] |
There was a problem hiding this comment.
P3: The individual pattern list is not deduplicated, so a user extra_patterns entry identical to a default pattern makes the callback run twice for the same match. Deduplicate the pattern sequence before compiling it.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At logfire-sdk/logfire/_internal/scrubbing.py, line 285:
<comment>The individual pattern list is not deduplicated, so a user `extra_patterns` entry identical to a default pattern makes the callback run twice for the same match. Deduplicate the pattern sequence before compiling it.</comment>
<file context>
@@ -281,6 +281,9 @@ def __init__(
patterns = [_DEFAULT_PATTERN, *(patterns or [])]
self._pattern = re.compile('|'.join(patterns), re.IGNORECASE | re.DOTALL)
+ self._individual_patterns = tuple(
+ re.compile(pattern, re.IGNORECASE | re.DOTALL) for pattern in [*DEFAULT_PATTERNS, *patterns[1:]]
+ )
self._callback = callback
</file context>
| re.compile(pattern, re.IGNORECASE | re.DOTALL) for pattern in [*DEFAULT_PATTERNS, *patterns[1:]] | |
| re.compile(pattern, re.IGNORECASE | re.DOTALL) for pattern in dict.fromkeys([*DEFAULT_PATTERNS, *patterns[1:]]) |
There was a problem hiding this comment.
(AI) The individual configured patterns are preserved as separate rules by design, including repeated entries. Each can reach the callback after an unchanged result and counts toward the shared 100-match limit. Deduplicating them would change that configured-rule behavior, so I am leaving the sequence as provided.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Summary
This addresses the same-position callback-whitelisting gap only; it does not complete pydantic/platform#38102.
Verification
uv run pytest tests/test_secret_scrubbing.py -q --tb=short(110 passed)pyright logfire-sdk/logfire/_internal/scrubbing.py tests/test_secret_scrubbing.py(0 errors)