← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

Webhooks

Architecture PHP 5.0+ Beginner
debt(d7/e5/b5/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note that semgrep can flag some patterns (e.g. no HMAC verification, synchronous heavy processing), but automated detection is explicitly marked 'no' in the metadata. Missing signature verification and non-idempotent handlers are invisible until a real webhook sender triggers duplicate or forged payloads in production — semgrep gives partial coverage but won't catch all logical mistakes like missing idempotency, pushing this toward d7.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix requires: adding HMAC signature verification middleware, refactoring synchronous handlers to enqueue work asynchronously (introducing a queue worker), and adding idempotency checks. This spans the endpoint handler, a queue system, and potentially a logging layer — more than a one-liner but contained within the integration component rather than a full cross-cutting refactor.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). Webhook handling applies to web and api contexts and introduces ongoing obligations: every new webhook integration must re-implement signature verification, idempotency, async dispatch, and raw payload logging. The pattern doesn't pervade the entire codebase but imposes a recurring structural cost on every integration work stream, consistent with b5.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field explicitly states developers assume webhooks are always more efficient than polling, and the common_mistakes list shows several well-documented but non-obvious gotchas (missing signature verification, synchronous processing causing retries, lack of idempotency). These are documented traps that most developers learn only after hitting them — fitting t5 rather than t7 because the issues are well-covered in provider documentation.

About DEBT scoring →

Also Known As

HTTP callback webhook endpoint push notification HTTP

TL;DR

A reverse API — a service POSTs event notifications to a registered URL whenever something occurs, eliminating the need to poll.

Explanation

Webhooks enable event-driven integrations: instead of your application polling an API every minute, the service POSTs a JSON payload to your endpoint the moment an event fires (payment.completed, push.received). Implementing a receiver: expose a public HTTPS endpoint, verify the payload signature (HMAC-SHA256 of the body against a shared secret, constant-time comparison with hash_equals()), respond with 200 immediately, and queue actual processing asynchronously to avoid delivery timeouts. Sending webhooks: store endpoint URLs per customer, deliver with retry and exponential backoff, record all delivery attempts, and support manual replay for debugging.

Common Misconception

✗ Webhooks are always more efficient than polling. Webhooks push events immediately but require a publicly reachable endpoint, reliable delivery handling, and signature verification. Polling is simpler and sometimes more appropriate for batch processing or when strict ordering matters.

Why It Matters

Webhooks deliver real-time event notifications via HTTP POST — they invert the polling model, but require validation, idempotency, and failure handling that polling naturally provides.

Common Mistakes

  • Not validating the webhook signature — any HTTP client can send a fake payload to your endpoint.
  • Not returning HTTP 200 quickly and processing asynchronously — slow handlers cause the sender to retry, duplicating events.
  • Not handling duplicate delivery — webhook senders retry on timeout or non-2xx; your handler must be idempotent.
  • Not logging raw payloads — debugging webhook failures requires the original body.

Avoid When

  • The consumer cannot guarantee idempotent processing — duplicate deliveries will cause duplicate side effects.
  • The payload contains sensitive data sent to an unverified URL — always validate signatures and use HTTPS.
  • The receiving server is unreliable — webhooks can be lost; use a message queue for guaranteed delivery.
  • You need request-reply semantics — webhooks are fire-and-forget; use polling or SSE for two-way flow.

When To Use

  • Notifying external systems of events in real time without them needing to poll.
  • Integrating with third-party platforms (Stripe, GitHub, Shopify) that push events on state changes.
  • Triggering CI pipelines, cache purges, or downstream workflows in response to your own events.
  • Replacing polling in scenarios where events are infrequent and latency matters.

Code Examples

✗ Vulnerable
// No signature validation — accepts any POST as legitimate:
app()->post('/webhook', function(Request $req): Response {
    processEvent($req->json()); // No HMAC verification
    return response('ok', 200);
});
// Add: hash_equals(hash_hmac('sha256', $req->rawBody(), $secret), $req->header('X-Signature'))
✓ Fixed
// Verify Stripe webhook signature
$payload = file_get_contents('php://input');
$sig = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = \Stripe\Webhook::constructEvent($payload, $sig, $secret);

Added 15 Mar 2026
Edited 30 May 2026
Views 187
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping S 0 pings S 1 ping M 0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 1 ping S
PetalBot 1
PetalBot 1
Amazonbot 29 PetalBot 16 Perplexity 15 SEMrush 12 Ahrefs 10 Google 9 Bing 8 ChatGPT 4 Scrapy 4 Unknown AI 3 Twitter/X 3 Meta AI 2 Claude 2 Brave Search 2 Applebot 2 Baidu 2 Majestic 1
crawler 117 crawler_json 7
⚡ DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Define webhook payloads as versioned typed events, verify HMAC signatures on every delivery, and respond 200 immediately — do processing asynchronously in a queue
📦 Applies To
PHP 5.0+ web api
🔗 Prerequisites
🔍 Detection Hints
Webhook handler doing heavy processing synchronously; no HMAC signature verification; webhook endpoint not responding within 5 seconds
Auto-detectable: ✗ No semgrep
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File Tests: Update
CWE-345 CWE-352

✓ schema.org compliant