You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
However, the linked docs to verify hooks actually do not verify HTTPS. Instead it asks devs to verify the HMAC. Checking HTTPS would have been much more straightforward.
2. provide a validator?
Although Shopify does have an HMAC validator as part of the standard js kit, it isn't usable and fails.
webhooks data is the req.bodystring before any parsing (re-serializing from the built-in express.js JSON middleware is inefficient and could break us).
app proxy data is partial query parameters, without the signature, ordered, then custom serialization
each of these contrived hmac schemes could be replaced with JWT. next best would be some consistency. or sample code:
/** tests an hmac value against the data as imposed by shopify */functionverifyHmac(/** @type {string} */data,/** @type {string} */unverifiedHmac,/** * @note * * Shopify uses hex digest for app proxy https://shopify.dev/docs/apps/online-store/app-proxies#calculate-a-digital-signature * * Shopify uses base64 digest for webhooks https://shopify.dev/docs/apps/webhooks/configuration/https#step-5-verify-the-webhook * @type { import("crypto").BinaryToTextEncoding} */encoding){constverifiedHmac=createHmac("sha256",shopify.api.config.apiSecretKey).update(data)// accepts string or ArrayBufferView; we'll just use string.digest(encoding);returnunverifiedHmac===verifiedHmac;}
Actual behavior
🤯
The text was updated successfully, but these errors were encountered:
For your concerns about the documentation would you be able to provide your feedback via the Was this section helpful? box on the offending pages. This will help out route the feedback to the correct teams in the most efficient way.
Regarding the HMAC validator for App proxies. This is something that we are aware of. Please watch for updates soon with the Remix App template that are working to resolve this.
Thank you for raising some of the inconsistencies on the platform. I agree this is something that we could definitely improve on. I can't promise any firm deadlines on when improvements would be made, but I really do appreciate you taking the time to provide this feedback.
Issue summary
1. test HTTPS?
Shopify docs for hooks state that app developers should verify hooks sent using HTTPS:
However, the linked docs to verify hooks actually do not verify HTTPS. Instead it asks devs to verify the HMAC. Checking HTTPS would have been much more straightforward.
2. provide a validator?
Although Shopify does have an HMAC validator as part of the standard js kit, it isn't usable and fails.
Shopify also has
shopify.api.webhooks.validate()
for javascript api but it isn't declared in the main docs?3. what to use for HMAC?
for hmac data:
req.body
string
before any parsing (re-serializing from the built-in express.js JSON middleware is inefficient and could break us).for hmac value:
x-shopify-hmac-sha256
.signature
for hmac digest encoding
base64
.hex
HS256
(base64-url
per JWT spec)and there are other situations in shopify that use tokens, oauth and cookies.
why not just use JWT in each of these cases?
Expected behavior
each of these contrived hmac schemes could be replaced with JWT. next best would be some consistency. or sample code:
Actual behavior
🤯
The text was updated successfully, but these errors were encountered: