Skip to content

fix(api): accept X-Hub-Signature for Bitbucket webhooks - #105

Merged
OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/bitbucket-signature-header
Oct 20, 2026
Merged

OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/bitbucket-signature-header

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Description

The Bitbucket webhook handler authenticated deliveries against the X-Hub-Signature-256 header, but Bitbucket Cloud sends the HMAC in the X-Hub-Signature header with a sha256=<hex> value (per Bitbucket's webhook documentation). Signed Bitbucket webhooks were therefore rejected with 401.

The handler now also accepts X-Hub-Signature as a fallback. The existing X-Hub-Signature-256 and X-Webhook-Signature headers keep working with their current precedence, and all malformed signature values (missing, empty, wrong digest, missing/unknown algorithm prefix, non-hex) keep failing closed for every header.

Fixes #94

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • New platform/collector support

Platform/Component

  • API Server
  • Kubernetes
  • CI/CD (specify: ____________)
  • Cloud Provider (specify: ____________)
  • ArgoCD
  • Docker
  • Tools/Executor
  • Documentation
  • Tests

Testing

  • Unit tests added/updated — 25 new cases in tests/test_security.py cover acceptance per header, missing/empty/wrong-digest/malformed rejections, header precedence in both directions, and empty-header fallback
  • Integration tests pass — fork CI run #39296622438: 10/10 jobs green on dda52c939b45cd984ee5aa0eefe20ae790d21b4e
  • Tested with dummy data — via the CI suite above
  • Manual testing performed
  • Tested in production-like environment

Test Configuration

OS: Ubuntu (GitHub Actions runners)
Python Version: 3.10 / 3.11 / 3.12 (CI matrix)
Kubernetes Version: N/A
Cloud Provider: N/A

Locally: python3 -m pytest tests/test_security.py -q → 63 passed; bandit -r . -ll → clean (0 medium/high).

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published (none required)

Breaking Changes

None. Existing senders using X-Hub-Signature-256 or X-Webhook-Signature are unaffected; X-Hub-Signature is accepted only additionally, after both existing headers in the selection order.

Additional Notes

The X-Hub-Signature/X-Webhook-Signature selection shape also appears in the Alertmanager, Grafana, GitLab and Manual handlers; those were left unchanged here since this issue concerns Bitbucket, whose documented header is X-Hub-Signature.

Generated by GPT-6.1 Sol (implementation, task review), GPT-6 Astra (final review), GLM-5.3-Flash (brief, coordination)

Preserve existing signature headers and precedence, test acceptance and rejection paths, and document webhook secret setup.

Co-Authored-By: GPT-6.1 Sol <[email protected]>

@OkiriGabriel OkiriGabriel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Nitjsefnie, this fixes #94 correctly. Bitbucket's X-Hub-Signature is now accepted after X-Hub-Signature-256 and X-Webhook-Signature. The precedence is preserved (a present-but-invalid preferred header doesn't fall through), and an empty header correctly allows the fallback. The tests cover every header with every invalid form, which is more than I'd have asked for. The setup steps in the docs are a nice addition. Approving and merging.

@OkiriGabriel
OkiriGabriel merged commit d879388 into open-devops-agent:main Oct 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Signed Bitbucket webhooks are rejected: handler reads X-Hub-Signature-256, Bitbucket sends X-Hub-Signature

2 participants