Skip to content

Return 401 when the HMAC header is missing instead of raising - #2098

Merged
lizkenyon merged 1 commit into
Shopify:mainfrom
jsaubry:js-11-02-fix-missing-hmac-header
Nov 2, 2026
Merged

lizkenyon merged 1 commit into
Shopify:mainfrom
jsaubry:js-11-02-fix-missing-hmac-header

Conversation

@jsaubry

@jsaubry jsaubry commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Description

Return false from ShopifyApp::PayloadVerification#hmac_valid? when X-Shopify-Hmac-Sha256 is missing or blank, so unsigned webhook and extension requests receive the normal 401 instead of a 500 caused by secure_compare raising NoMethodError. Security behavior is unchanged: these requests are still rejected, but without an exception. Related to the closed issue #529.

ShopifyApp::PayloadVerification#hmac_valid? passed the X-Shopify-Hmac-Sha256 header straight to ActiveSupport::SecurityUtils.secure_compare. When the header is absent, secure_compare calls nil.bytesize and raises NoMethodError, so unsigned requests to webhook and extension endpoints return 500 instead of 401. Treat a missing or blank header as an invalid HMAC.

Co-authored-by: River <river@shopify.com>
Co-authored-by: Claude <noreply@anthropic.com>
@jsaubry
jsaubry marked this pull request as ready for review November 2, 2026 16:26

@lizkenyon lizkenyon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY!

@lizkenyon
lizkenyon merged commit 2ea0cf0 into Shopify:main Nov 2, 2026
6 checks passed
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.

2 participants