Skip to content
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

feat(bitbucket): check bitbucket webhook signature if webhook_secret is defined #84309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

oioki
Copy link
Member

@oioki oioki commented Jan 30, 2025

Preparing Bitbucket webhook secret validation. This is actual signature header validation, but no integrations/repos have the associated secret yet.

Follow-up PRs:

Previous attempt (#82541) had repository-level secrets but we decided to go with integration-level secret to align with other integrations (GitLab, GitHub).

@oioki oioki requested review from a team as code owners January 30, 2025 14:38
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 98.59155% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/integrations/bitbucket/webhook.py 97.29% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #84309       +/-   ##
===========================================
+ Coverage   46.61%   87.66%   +41.05%     
===========================================
  Files        9563     9575       +12     
  Lines      541874   542418      +544     
  Branches    21264    21252       -12     
===========================================
+ Hits       252589   475535   +222946     
+ Misses     288933    66531   -222402     
  Partials      352      352               

Copy link
Member

@cathteng cathteng left a 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)
Copy link
Member

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

Copy link
Member Author

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:

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):

Copy link
Member

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?

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