Ensures the current request carries a valid Shopify query / app-proxy HMAC
signature and, when present, a fresh timestamp.
Security properties:
- HMACs are compared in constant time with
Plug.Crypto.secure_compare/2. - Computed HMAC values are never logged.
- When the request includes a
timestampparameter (Shopify always sends one for admin-load and app-proxy flows) it must be withinconfig :shopifex, :hmac_timestamp_tolerance_seconds(default90) of now, closing the replay window. (A request that carries notimestampskips the freshness check, unless:require_timestampis set — see below.)
Requiring a timestamp
Some signed flows (e.g. bulk-action links) legitimately omit timestamp, so by
default a missing timestamp is allowed. App-proxy requests, however, always
carry one, and without it the signed URL is replayable forever. Pass
require_timestamp: true to reject any request that lacks a timestamp:
plug Shopifex.Plug.ValidateHmac, require_timestamp: trueThe :shopify_proxy pipeline sets this by default.
Per-pipeline tolerance
The config :shopifex, :hmac_timestamp_tolerance_seconds default is global. App
proxy / storefront requests can legitimately lag past 90s, but widening the
global value also widens the admin-load replay window. Pass a plug option to
relax the tolerance for one pipeline only, without touching the global default:
plug Shopifex.Plug.ValidateHmac, timestamp_tolerance_seconds: 600This plug only verifies the signature — it does not load the shop into
conn.assigns. The :shopify_proxy pipeline pairs it with
Shopifex.Plug.LoadProxyShop so app-proxy consumers get current_shop/1.