omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty $200] security: shopify OAuth callback never verifies signatures — forged callbacks rebind grants to any uid

Open hridaya423 opened this issue 2 months ago • 5 comments

Summary

/auth/shopify/callback in plugins/omi-shopify-app/main.py trusts every query parameter without any verification:

  • verify_shopify_hmac() exists but is never called — the hmac Shopify signs the redirect with is accepted and ignored.
  • state is the raw uid (uid = state), so anyone can point the flow at a uid they don't own.

Impact

  1. Unsigned state → grant rebinding (login CSRF). An attacker initiates /auth/shopify?uid=<victim>&shop=<attacker>.myshopify.com, completes OAuth for their own shop, and the resulting valid callback binds the attacker's shop access token under the victim's uid. The victim's app then reads/writes the attacker's store.
  2. No Shopify HMAC check → forged callbacks. Anyone can hit the callback with arbitrary code/state/shop. Combined with the missing *.myshopify.com validation (tracked separately in #13656), the code exchange POSTs client_id + client_secret to an attacker host. Even with the domain fix, unverified callbacks still let a foreign grant overwrite a user's shop binding.
  3. The existing verify_shopify_hmac also re-encodes params with urlencode, which mismatches Shopify's documented signing scheme (decoded key=value pairs, sorted, &-joined) and would reject legitimate callbacks — it was presumably abandoned rather than fixed.

Fix

  • Call verify_shopify_hmac in the callback and reject forged/unsigned requests before the token exchange.
  • Sign state at initiation (_oauth_state_for(uid) → uid:hmac_sig) and verify it in the callback (_oauth_state_uid), so only flows this server started can bind a uid.
  • Correct verify_shopify_hmac to match Shopify's signing scheme.
  • Hermetic regression tests: forged hmac, missing hmac, foreign-state rebinding, tampered state, and the valid round-trip.

PR with fix + tests follows. cc @kodjima33 @Git-on-my-level

hridaya423 avatar Sep 18 '26 00:09 hridaya423

Fix + regression tests: #14443

hridaya423 avatar Sep 18 '26 00:09 hridaya423

@josancamon19 @kodjima33 — fix is up and verified with regression tests; if this qualifies under the paid-bounty program I would be glad to take it on.

hridaya423 avatar Sep 18 '26 03:09 hridaya423

Closing as already fixed on current main.

Current main shopify_callback calls verify_shopify_hmac and binds uid via _oauth_state_uid(state) (signed state, not raw uid)

aryanorastar avatar Sep 20 '26 16:09 aryanorastar

Hi @kodjima33 @josancamon19 — following up on the payout for this one.

PR #14612 was merged on 19 Sep and this issue closed as completed, with the fix (_signing_secret() fail-closed, corrected verify_shopify_hmac scheme, signed OAuth state) now on main.

Could you point me at how the $200 bounty is paid out — is there a form, an Algora/Stripe claim, or an address you need from me? Happy to follow whatever process you use.

Thanks for the quick review either way.

ajitv2 avatar Sep 22 '26 22:09 ajitv2

Hi @kodjima33 @josancamon19,

Following up on the security fix for this issue across the related PRs (#14443, #14548, and merged #14612).

In PR #14548, I submitted key structural improvements to the Shopify HMAC verification and state binding (including signature param removal, query multi-value joining, and empty-HMAC guards), which reviewer @Git-on-my-level validated and noted:

"Mechanically this PR is slightly better on a few points... credit is due to both authors either way."

Given that the final landed solution integrated insights from the earlier PRs (#14443 and #14548), could the maintainers consider a split bounty reward among the contributing authors?

Thank you for your consideration and for reviewing our contributions!

meanusarcanus avatar Sep 27 '26 08:09 meanusarcanus