-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(bitbucket): check bitbucket webhook signature if webhook_secret is defined #84309
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 ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #84309 +/- ##
===========================================
+ Coverage 46.61% 87.71% +41.10%
===========================================
Files 9563 9599 +36
Lines 541874 544269 +2395
Branches 21264 21252 -12
===========================================
+ Hits 252589 477423 +224834
+ Misses 288933 66494 -222439
Partials 352 352 |
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.
looks good, not sure what the request
is being used for in the handler though
@@ -206,6 +262,6 @@ def post(self, request: HttpRequest, organization_id: int) -> HttpResponse: | |||
domain=IntegrationDomain.SOURCE_CODE_MANAGEMENT, | |||
provider_key=event_handler.provider, | |||
).capture(): | |||
event_handler(event, organization=organization) | |||
event_handler(event, request=request, organization=organization) |
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.
what do we need the request
for here? it's not being used in BitbucketWebhook
except to check that it's passed
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.
request
contains X-Hub-Signature
header and request body which are used here:
sentry/src/sentry/integrations/bitbucket/webhook.py
Lines 135 to 142 in 90fc14b
method, signature = request.META["HTTP_X_HUB_SIGNATURE"].split("=", 1) | |
except (IndexError, KeyError, ValueError): | |
raise WebhookMissingSignatureException() | |
if method != "sha256": | |
raise WebhookUnsupportedSignatureMethodException() | |
if not is_valid_signature(request.body, secret, signature): |
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.
oh wait, can we do this in the webhook itself before calling the handler?
external_id=str(event["repository"]["uuid"]), | ||
) | ||
except Repository.DoesNotExist: | ||
raise Http404() |
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.
Since we are now doing signature check on the upper level (in post()
method), and repository
is always in the payload (https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#Repository), we will always lookup the repo on the upper level as well. Hence passing the repo as kwarg and removing this code.
Preparing Bitbucket webhook secret validation. This is actual signature header validation, but no integrations/repos have the associated secret yet.
Follow-up PRs:
webhook_secret
: feat(bitbucket): add webhook secret on each repository creation #84311Previous attempt (#82541) had repository-level secrets but we decided to go with integration-level secret to align with other integrations (GitLab, GitHub).