Skip to content

Add shop validation#1443

Open
gonzaloriestra wants to merge 1 commit intomainfrom
river/use-jwt-dest-for-token-exchange
Open

Add shop validation#1443
gonzaloriestra wants to merge 1 commit intomainfrom
river/use-jwt-dest-for-token-exchange

Conversation

@gonzaloriestra
Copy link
Copy Markdown

@gonzaloriestra gonzaloriestra commented Apr 9, 2026

Description

https://docs.google.com/document/d/1c0iXhKBpm-yhvff0iSgq1XwBSPL39fTBVajIJ3svaxU/edit?usp=sharing

Checklist:

  • My commit message follow the pattern described in here
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the project documentation.
  • I have added a changelog line.

@gonzaloriestra gonzaloriestra force-pushed the river/use-jwt-dest-for-token-exchange branch from aaf2cc7 to 7992177 Compare April 9, 2026 11:38
@gonzaloriestra gonzaloriestra marked this pull request as ready for review April 9, 2026 11:59
@lizkenyon lizkenyon requested a review from zzooeeyy April 9, 2026 14:18
dest_shop = jwt_payload.shop

shop_session = ShopifyAPI::Auth::Session.new(shop: shop)
shop_session = ShopifyAPI::Auth::Session.new(shop: dest_shop)
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.

If we are no longer using the shop param. We could deprecate it, so it can be removed in the next major version.

  jwt_payload = ShopifyAPI::Auth::JwtPayload.new(session_token)
  dest_shop = jwt_payload.shop

  if shop != dest_shop
    ShopifyAPI::Context.logger.warn(
      "shop parameter (#{shop}) does not match session token dest claim (#{dest_shop}). " \
      "The dest claim will be used. The shop parameter is deprecated for exchange_token " \
      "and will be removed in a future major version."
    )
  end

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.

I also agree! We should remove shop from this method's arguments


module ShopifyAPI
module Utils
class ShopValidator
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.

I think we need to modify the ShopValidator check to protect against URLs like "attacker.com/.myshopify.com". This passes validation since it ends with .myshopify.com, but URI.parse resolves the host to
attacker.com


module ShopifyAPI
module Utils
class ShopValidator
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.

This could probably be module similar to hmac


module ShopifyAPI
module Utils
class ShopValidator
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.

There's also a similar sanitize method from shopify_app gem, I wonder if the logic can be extracted so we don't have to maintain 2 packages for validating Shopify URLS

dest_shop = jwt_payload.shop

shop_session = ShopifyAPI::Auth::Session.new(shop: shop)
shop_session = ShopifyAPI::Auth::Session.new(shop: dest_shop)
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.

I also agree! We should remove shop from this method's arguments

extend T::Sig

sig { params(shop: String).returns(String) }
def validate!(shop)
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.

validate might be a misleading method name since it does more than validation and returns the sanitized shop name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants