fix(webhooks): reject disconnected grants and stop returning 500 on bad requests #154
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 543 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #154"
general
weight: 0.35
Nirupon123
Description
The VoxBento webhook receiver kept accepting validly signed webhooks after an organizer disconnected VoxBento, and several malformed requests ended in an unhandled exception (HTTP 500) instead of a 4xx. This PR hardens
VoxbentoWebhookReceiverView.Related Issue
Closes #153
Changes Made
is_disconnected, so a disconnected event no longer accepts webhooks signed with its old secret. Reconnecting already resets the flag and the secret (views_oauth.py), so nothing else needs to change..get(event__slug=...)raisedMultipleObjectsReturned. A new helper,_find_verified_grant, returns the grant whose webhook secret verifies the signature.v1value no longer raisesTypeErrorinhmac.compare_digest.ValueErrorwhen parsing the body, so a body that is not valid UTF-8 returns 400 instead of raisingUnicodeDecodeError.dataafter verification, so"data": nullno longer crashes a handler.Testing
Added six regression tests to
tests/test_views_webhooks.py. I ran them against the unfixed code first, and all six failed with the errors listed in #153 (200 for a disconnected grant,TypeError,UnicodeDecodeError, 404 for an unknown event,AttributeError,MultipleObjectsReturned).Screenshots (if applicable)
Not applicable (backend only).
Checklist
ruffclean, 120 columns)Additional Notes
post()in this file. Whichever PR merges second will need a small rebase; this PR does not touch logging.Summary by Sourcery
Harden the VoxBento webhook receiver to authenticate only active grants and consistently reject invalid requests with safe client errors.
Bug Fixes:
Enhancements:
Tests:
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Webhook requests for unknown events, disconnected accounts, missing secrets, or invalid signatures receive a consistent unauthorized response.
Malformed JSON, invalid text encoding, and non-string event types receive a bad-request response.
Requests larger than 256 KiB are rejected.
When multiple accounts have events with the same slug, the webhook updates the event whose account secret validates the request, checking up to 10 matches.
Webhooks for accounts disconnected during processing are rejected without updating event state or sending notifications.
* Signed webhook requests with a
nulldata value are ignored.<!-- end of auto-generated comment: release notes by coderabbit.ai -->