Skip to content

fix(security): timing-safe webhook HMAC + audit fixes - #9

Merged
rome2o merged 2 commits into
mainfrom
fix/security-audit-webhook-hmac
Aug 16, 2026
Merged

rome2o merged 2 commits into
mainfrom
fix/security-audit-webhook-hmac

Conversation

@superkindhq

@superkindhq superkindhq Bot commented Aug 16, 2026

Copy link
Copy Markdown

Security audit fixes (2026-08-16)

Ref: #7

1. Timing-safe HMAC comparison in handleWebhook (src/lifecycle/webhooks.ts)

The webhook handler compared the computed HMAC against the X-Shopify-Hmac-Sha256 header with a plain === string comparison, which is vulnerable to timing attacks (early-exit on first differing byte). Cloudflare Workers has no crypto.timingSafeEqual, so this is replaced with an inline constant-time comparison: length check via XOR of lengths, then an XOR-fold accumulated over every character code, and a single diff !== 0 decision at the end. Behavior is unchanged — 401 { error: 'Unauthorized' } on mismatch, 200 on success.

2. Audit-noted false positive on registerWebhooks (src/lifecycle/webhooks.ts)

The scanner flagged registerWebhooks for webhook-no-verification. Verified false positive: this function performs outbound webhook registration via the Shopify Admin API (authenticated by the X-Shopify-Access-Token header), not inbound webhook handling. No code change — an audit comment documenting the verification now sits above the function.

3. npm audit fix — dev-dependency vulnerabilities

All fixes were semver-compatible within existing ranges; no package.json version changes were needed (lockfile-only update).

Severity Before After
critical 0 0
high 9 0
moderate 7 6
low 0 0

Cleared the high advisories in: @cloudflare/vite-plugin, brace-expansion, js-yaml, miniflare, nanoid (plus transitive wrangler, postcss, sharp, undici).

Skipped (noted, not fixed):

  • drizzle-kit chain (4 moderates: @esbuild-kit/*, esbuild) — the only available "fix" is a downgrade to drizzle-kit 0.18.1 (semver-major break). Recommend a dedicated upgrade to current drizzle-kit instead.
  • react-router/react-router-dom (2 moderates, prod dependency) — fix requires major bump to React Router 7.x; out of scope for this dev-dep audit fix. Recommend separate upgrade PR.

Verification

  • tsc --noEmit — ✅ pass
  • vitest run — ✅ 6 files, 20 tests passed (incl. all 3 webhook HMAC tests: valid / invalid / missing signature)
  • npm audit — ✅ 0 high, 0 critical (was 9 high)

hermes-agent and others added 2 commits August 16, 2026 09:50
- handleWebhook: replace === string comparison with XOR-fold timing-safe compare
- registerWebhooks: audit comment (verified safe, outbound registration)
- deps: npm audit fix (5 high dev deps)
…pattern)

Replace hand-rolled XOR-fold with the Cloudflare Workers runtime's
crypto.subtle.timingSafeEqual, per:
https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#timingsafeequal
https://developers.cloudflare.com/workers/examples/protect-against-timing-attacks/

Helper src/lib/timingSafeEqual.ts: canonical CF pattern (self-compare on
length mismatch to avoid leaking length); Node fallback (XOR fold) so
vitest runs outside workerd.
@superkindhq

superkindhq Bot commented Aug 16, 2026

Copy link
Copy Markdown
Author

Follow-up commit e7b63a2: replaced the hand-rolled XOR-fold with Cloudflare's documented pattern — crypto.subtle.timingSafeEqual (web-crypto docs, timing-attack example) via a shared helper src/lib/timingSafeEqual.ts (canonical CF self-compare on length mismatch; Node fallback so vitest passes outside workerd). tsc clean, 20/20 tests.

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