From 80b40da3a208cea17d65f0659cf3df0d39c3e69b Mon Sep 17 00:00:00 2001 From: Thomas <31560900+0xtlt@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:55:24 +0100 Subject: [PATCH] fix(oauth): accept a customer account extension token's `iss` on its shop `verify_extension_session_token` required an `iss` of exactly `{origin}/admin`, so customer account UI extension tokens, whose `iss` is `https://{shop}.myshopify.com/checkouts`, were refused. An `iss` on the extension path now passes when it is the origin of `dest`'s shop followed by `/` and a path. `verify_session_token` keeps requiring `{origin}/admin`. Refs 0xtlt/openshop-rust#83 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +++ crates/shopify_api/src/oauth.rs | 55 +++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a88093d..2829b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fixed: `verify_extension_session_token` refused the tokens of customer account UI extensions, whose `iss` is `https://{shop}.myshopify.com/checkouts` (seen on a development store; Shopify's documentation does not list it). An `iss`, when there is one, now passes when it is `https://{shop}.myshopify.com/` followed by a path, on the shop of `dest`: another shop, a host that only starts with the shop's, `http://` or the shop with no path are still refused. `verify_session_token` still takes only an `iss` of exactly `https://{shop}.myshopify.com/admin`. ([openshop-rust#83](https://github.com/0xtlt/openshop-rust/issues/83)) + ## 1.0.0-rc.4 (2026-11-08) The fourth release candidate: rc.3 and the changes under "Since 1.0.0-rc.3" diff --git a/crates/shopify_api/src/oauth.rs b/crates/shopify_api/src/oauth.rs index b5f98a3..8547196 100644 --- a/crates/shopify_api/src/oauth.rs +++ b/crates/shopify_api/src/oauth.rs @@ -360,6 +360,22 @@ fn check_admin_issuer(issuer: &str, shop: &ShopDomain) -> Result<()> { } } +/// Checks that `iss` is a page of `shop`: its origin, then `/` and a path. +/// Comparing the origin and the `/` together leaves no room for another host +/// (`https://{shop}.evil.example/…`), a port, a user or `http://`. +fn check_shop_issuer(issuer: &str, shop: &ShopDomain) -> Result<()> { + let path = issuer + .strip_prefix(shop.origin().as_str()) + .and_then(|rest| rest.strip_prefix('/')); + if path.is_some_and(|path| !path.is_empty()) { + Ok(()) + } else { + Err(invalid( + "the `iss` of the session token is not on its `dest`", + )) + } +} + impl ShopifyApp { pub fn new(client_id: impl Into, client_secret: impl Into) -> Self { Self { @@ -674,7 +690,12 @@ impl ShopifyApp { /// extension (`shopify.sessionToken.get()`): signed by the app's secret with /// HS256, issued for the app, within its dates, with a `dest` that is a /// `*.myshopify.com` domain (Shopify writes it without `https://`). An - /// `iss`, when there is one, must be exactly `https://{shop}.myshopify.com/admin`. + /// `iss`, when there is one, must be a path on that same shop: + /// `https://{shop}.myshopify.com/` followed by a path, such as `/admin`. + /// Checkout extension tokens have no `iss`; customer account extension + /// tokens were seen with `https://{shop}.myshopify.com/checkouts`, a value + /// Shopify's documentation does not list. Only the shop of `iss` is + /// checked, not its path. /// /// Any buyer of the shop can get such a token: it proves the shop and, /// when one is logged in, the customer, never a staff member. It is a type @@ -694,7 +715,7 @@ impl ShopifyApp { .ok_or_else(|| invalid("the session token has no `dest`"))?; let shop = shop_of_host(destination.strip_prefix("https://").unwrap_or(destination))?; if let Some(issuer) = verified.claim("iss") { - check_admin_issuer(issuer, &shop)?; + check_shop_issuer(issuer, &shop)?; } Ok(ExtensionSessionToken { // Only a customer's GID: the `sub` of an admin token is a staff member. @@ -1170,6 +1191,8 @@ mod tests { "https://my-shop.myshopify.com/admin/", "https://my-shop.myshopify.com/adminx", "http://my-shop.myshopify.com/admin", + // The `iss` of a customer account extension: not the admin. + "https://my-shop.myshopify.com/checkouts", ] { let mut token = claims(now); token["iss"] = json!(issuer); @@ -1248,13 +1271,27 @@ mod tests { assert_eq!(admin.customer(), None); assert_eq!(admin.claims()["sub"], claims(now)["sub"]); - // An `iss` is compared whole here as well. - let mut prefixed = extension_claims(now); - prefixed["iss"] = json!("https://store-name.myshopify.com.evil.example/admin"); - assert_eq!( - verify(&prefixed).unwrap_err().to_string(), - "verification failed: the `iss` of the session token is not the admin of its `dest`" - ); + // The `iss` of a customer account extension: a path on the same shop. + let mut customer_account = extension_claims(now); + customer_account["iss"] = json!("https://store-name.myshopify.com/checkouts"); + assert!(verify(&customer_account).is_ok()); + // Another shop, a host that only starts with the shop's, `http://`, or + // the shop with no path. + for issuer in [ + "https://other-shop.myshopify.com/checkouts", + "https://store-name.myshopify.com.evil.example/checkouts", + "http://store-name.myshopify.com/checkouts", + "https://store-name.myshopify.com", + "https://store-name.myshopify.com/", + ] { + let mut token = extension_claims(now); + token["iss"] = json!(issuer); + assert_eq!( + verify(&token).unwrap_err().to_string(), + "verification failed: the `iss` of the session token is not on its `dest`", + "{issuer}" + ); + } // A bare handle, or another host, is still not a shop. for destination in ["store-name", "store-name.example.com", "https://store-name"] { let mut token = extension_claims(now);