Skip to content

ref(sentry-apps): extract webhook header parsing and masking helpers#119529

Merged
cvxluo merged 1 commit into
masterfrom
cvxluo/extract-webhook-header-parsing-and-masking-helpers
Jul 13, 2026
Merged

ref(sentry-apps): extract webhook header parsing and masking helpers#119529
cvxluo merged 1 commit into
masterfrom
cvxluo/extract-webhook-header-parsing-and-masking-helpers

Conversation

@cvxluo

@cvxluo cvxluo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Move logic for sentry app custom headers reading + masking into its own file, so they can be used by src/sentry/sentry_apps/external_requests/utils.py.

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 13, 2026
@cvxluo cvxluo marked this pull request as ready for review July 13, 2026 17:45
Comment on lines +8 to +9
for header in webhook_headers:
name, separator, value = header.partition(":")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The parse_custom_headers function will crash with a TypeError if webhook_headers is None, which can happen for older SentryApp database records.
Severity: HIGH

Suggested Fix

Add a guard to the parse_custom_headers function to handle cases where webhook_headers is None. A simple way to do this is to default to an empty list, for example: for header in webhook_headers or []:. This restores the safe behavior that existed before the refactor.

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: src/sentry/sentry_apps/utils/headers.py#L8-L9

Potential issue: The function `parse_custom_headers` does not handle `None` values for
its `webhook_headers` argument. This can lead to a `TypeError` when the function
attempts to iterate over `None`. The `webhook_headers` field can be `None` for
`SentryApp` records that were created before the database migration that added this
field, as the migration did not backfill existing rows, leaving them as `NULL` in the
database. The original code handled this possibility with `or []`, but this safeguard
was removed during refactoring, introducing a regression.

Also affects:

  • src/sentry/sentry_apps/api/serializers/app_platform_event.py:114~114

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.

pretty sure the column defaults to [] rather than null

@cvxluo cvxluo requested review from a team and billyvg July 13, 2026 17:50
@cvxluo cvxluo merged commit 3993147 into master Jul 13, 2026
68 checks passed
@cvxluo cvxluo deleted the cvxluo/extract-webhook-header-parsing-and-masking-helpers branch July 13, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants