Skip to content

fix(security): timing-safe webhook HMAC + clear high-severity deps (port of shopify-on-cloudflare#9) - #1

Merged
rome2o merged 1 commit into
add-shopify-on-cloudflare-templatefrom
fix/shopify-template-security
Aug 16, 2026
Merged

rome2o merged 1 commit into
add-shopify-on-cloudflare-templatefrom
fix/shopify-template-security

Conversation

@superkindhq

@superkindhq superkindhq Bot commented Aug 16, 2026

Copy link
Copy Markdown

Ports the security fix from devkindhq/shopify-on-cloudflare#9 (merged 2026-08-16, after this template branch was cut) into add-shopify-on-cloudflare-template, plus the Cloudflare-templates compliance re-check.

Why

src/lifecycle/webhooks.ts verified Shopify's X-Shopify-Hmac-Sha256 webhook signature with a plain !== string comparison — early-exit, timing-attack-vulnerable. The source repo fixed exactly this today; the template still shipped the vulnerable compare.

Changes

1. Timing-safe HMAC verification (the security fix)

  • New src/lib/timingSafeEqual.ts — uses the Workers runtime's crypto.subtle.timingSafeEqual extension (docs) with a constant-time XOR-fold fallback for non-Workers runtimes (Node/vitest). No early return on length mismatch (compares against self and negates, per the documented pattern).
  • webhooks.ts: computedHmac !== hmacHeader → !timingSafeEqual(computedHmac, hmacHeader).
  • Security-audit note added above registerWebhooks (audit false positive: outbound registration, not inbound handling).
  • New test: wrong-length signature still 401s (exercises the no-early-exit length path).

2. Dependency audit — 8 high → 0 high

Same npm audit fix the source repo shipped in cloudflare#9:

  • @cloudflare/vite-plugin 1.46.0 → 1.52.1 and wrangler 4.113.0 → 4.123.0 (peer dep) — clears the undici chain (8 high advisories).
  • Remaining 6 moderates = drizzle-kit / react-router major-bump chains, documented as out-of-scope upstream.
  • package-lock.json regenerated via pnpm fix:lockfiles; templates.json package_json_hash updated (sha1 of new package.json).

Verification (all run on this branch)

Check Result
templates lint . (check:templates) ✅ pass
prettier . --check ✅ pass
templates lint-npm-lockfiles ✅ pass
turbo run check cf-typegen --filter=shopify-on-cloudflare-template ✅ 3/3 (vite build + deploy dry-run with new toolchain)
vitest run ✅ 21/21 (20 before, +1 new length-mismatch test)
wrangler types idempotency vs committed worker-configuration.d.ts ✅ no drift
npm audit --package-lock-only ✅ 0 high, 0 critical (was 8 high)

Note: tsc --noEmit fails on React 18/19 @types conflicts identically on the pristine branch — pre-existing pnpm-workstore hoisting artifact (standalone npm install used by Deploy-to-Cloudflare resolves a single @types/react@18), unrelated to this change. Repo CI does not run tsc for this template; its gate is turbo check (build + dry-run), which passes.

Once merged, Uzair's branch can be synced to the upstream PR.

… shopify-on-cloudflare-template

Ports devkindhq/shopify-on-cloudflare#9 into the template:

1. Webhook HMAC verification compared the computed digest against the
   X-Shopify-Hmac-Sha256 header with plain !== (early-exit string
   compare), leaving it open to timing attacks. Replaced with
   crypto.subtle.timingSafeEqual (Workers runtime extension, per
   developers.cloudflare.com/workers/runtime-apis/web-crypto) with a
   constant-time XOR-fold fallback for non-Workers runtimes (vitest/Node).
   Adds a wrong-length-signature test covering the no-early-exit path.

2. Bumps @cloudflare/vite-plugin 1.46.0 -> 1.52.1 and wrangler
   4.113.0 -> 4.123.0 (peer dep of the new vite-plugin). Clears all 8
   high-severity npm audit advisories (undici chain). Remaining 6
   moderates are drizzle-kit/react-router major-bump chains, documented
   as out of scope upstream.

3. Adds the security-audit note above registerWebhooks (verified safe:
   outbound registration, not inbound handling).

Verified: templates lint, prettier, lockfile lint, turbo check +
cf-typegen (build + deploy dry-run), vitest 21/21, wrangler types
idempotent vs committed worker-configuration.d.ts.
@rome2o
rome2o merged commit ada0b83 into add-shopify-on-cloudflare-template Aug 16, 2026
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