Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ def match_regex_list(
return False

for item_matcher in regex_list:
if not substring_matching and item_matcher[-1] != "$":
if not substring_matching and (not item_matcher or item_matcher[-1] != "$"):
item_matcher += "$"
Comment on lines +1739 to 1740

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The fix for an IndexError causes an empty string in regex_list to be treated as a pattern that matches everything, leading to unintended consequences.
Severity: HIGH

Suggested Fix

The function match_regex_list should handle empty strings in regex_list explicitly. Instead of converting "" to "$", it should either skip empty strings (possibly with a warning) or only match them against empty input strings. This will prevent the unintended "match-all" behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: sentry_sdk/utils.py#L1739-L1740

Potential issue: The change in `match_regex_list` prevents an `IndexError` when an item
in `regex_list` is an empty string. However, it introduces a new issue. An empty string
pattern `""` is converted to `"$"` which, when used with `re.search`, matches the end of
any string. Consequently, if a configuration list like `trace_propagation_targets` or
`exclude_beat_tasks` contains an empty string, `match_regex_list` will return `True` for
every input. This could lead to all HTTP requests having trace propagation enabled, or
all Celery beat tasks being excluded from monitoring, failing silently instead of
crashing.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I would expect with an empty regex


matched = re.search(item_matcher, item)
Expand Down
Loading