Skip to content

Webhooks: constant-time HMAC signature verification#11

Merged
OmarAlJarrah merged 5 commits into
mainfrom
feat/webhook
Jun 16, 2026
Merged

Webhooks: constant-time HMAC signature verification#11
OmarAlJarrah merged 5 commits into
mainfrom
feat/webhook

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Implements the webhook package: constant-time HMAC-SHA256 verification of
inbound webhook signatures, with a timestamp-tolerance window to defeat replay.
This completes the package set — no placeholder packages remain.

What's included

  • Sign(secret, payload) — lowercase hex HMAC-SHA256 (locked against the
    canonical published test vector).
  • Verifier (NewVerifier(secret, WithTolerance(d))) —
    • Verify(payload, sigHex) compares with hmac.Equal on the raw MAC bytes
      (constant-time); invalid hex maps to a mismatch with no information leak.
    • VerifyTimestamp(body, timestamp, now, sigHex) implements the common
      "<unix>.<body>" scheme, rejecting timestamps outside the tolerance window in
      either direction before checking the signature. now is injected for
      deterministic verification.
  • Typed sentinels ErrSignatureMismatch and ErrTimestampOutsideTolerance for
    errors.Is.

VerifyTimestamp streams the HMAC over the timestamp/body parts (no payload copy).
A tolerance of <= 0 disables the window — clearly warned in the GoDoc.

Behavior changes

None — new package only (webhook was a placeholder).

Deferred (not in this PR)

  • Provider-specific signature-header parsing (callers pass the timestamp +
    signature they extracted).
  • Non-HMAC-SHA256 schemes (e.g. Ed25519).

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . (clean)
  • go test -race ./... (all 18 packages pass)
  • Covered: Sign/Verify round-trip; tampered payload, wrong secret, invalid hex →
    mismatch; timestamp within/outside (stale and future) tolerance; tolerance
    disabled; a known-answer HMAC golden vector; and the hex output format.

🤖 Generated with Claude Code

OmarAlJarrah and others added 5 commits June 16, 2026 19:31
Constant-time HMAC-SHA256 verification with a timestamp-tolerance window;
Sign helper and typed sentinel errors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OmarAlJarrah OmarAlJarrah merged commit 164dd1d into main Jun 16, 2026
1 of 2 checks passed
@OmarAlJarrah OmarAlJarrah deleted the feat/webhook branch June 16, 2026 16:40
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.

1 participant