Repository navigation
fix(security): timing-safe webhook HMAC + audit fixes - #9
Merged
Merged
Conversation
- 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.
Author
|
Follow-up commit |
rome2o
approved these changes
Aug 16, 2026
This was referenced Aug 16, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-Sha256header with a plain===string comparison, which is vulnerable to timing attacks (early-exit on first differing byte). Cloudflare Workers has nocrypto.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 singlediff !== 0decision 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
registerWebhooksfor webhook-no-verification. Verified false positive: this function performs outbound webhook registration via the Shopify Admin API (authenticated by theX-Shopify-Access-Tokenheader), not inbound webhook handling. No code change — an audit comment documenting the verification now sits above the function.3.
npm audit fix— dev-dependency vulnerabilitiesAll fixes were semver-compatible within existing ranges; no
package.jsonversion changes were needed (lockfile-only update).Cleared the high advisories in:
@cloudflare/vite-plugin,brace-expansion,js-yaml,miniflare,nanoid(plus transitivewrangler,postcss,sharp,undici).Skipped (noted, not fixed):
drizzle-kitchain (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— ✅ passvitest 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)