Skip to content

Commit 57e4f98

Browse files
committed
Deprecate validate_shop call from JWT class
1 parent 8430c82 commit 57e4f98

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## Unreleased
44

55
### Fixed
6+
67
- [#935](https://github.com/Shopify/shopify_api/pull/935) Fix issue [#931](https://github.com/Shopify/shopify_api/pull/931), weight of variant should be float
7-
- [#939](https://github.com/Shopify/shopify_api/pull/939) Hotfix for `.spin.dev` JWT validation.
8+
- [#944](https://github.com/Shopify/shopify_api/pull/944) Deprecated the `validate_shop` method from the JWT class since we can trust the token payload, since it comes from Shopify.
89

910
## Version 10.0.2
1011

lib/shopify_api/auth/jwt_payload.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,21 @@ def initialize(token)
3535

3636
raise ShopifyAPI::Errors::InvalidJwtTokenError,
3737
"Session token had invalid API key" unless @aud == Context.api_key
38-
raise ShopifyAPI::Errors::InvalidJwtTokenError,
39-
"Session token had invalid shop" unless validate_shop(shop)
4038
end
4139

4240
sig { returns(String) }
4341
def shop
4442
@dest.gsub("https://", "")
4543
end
4644

45+
# TODO: Remove before releasing v11
4746
sig { params(shop: String).returns(T::Boolean) }
4847
def validate_shop(shop)
49-
/\A[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\.(myshopify\.(io|com)|spin\.dev)\z/.match?(shop)
48+
Context.logger.warn(
49+
"Deprecation notice: ShopifyAPI::Auth::JwtPayload.validate_shop no longer checks the given shop and always " \
50+
"returns true. It will be removed in v11."
51+
)
52+
true
5053
end
5154

5255
alias_method :eql?, :==

test/auth/jwt_payload_test.rb

-9
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ def test_decode_jwt_payload_fails_if_not_activated_yet
8383
end
8484
end
8585

86-
def test_decode_jwt_payload_fails_if_domain_is_invalid
87-
payload = @jwt_payload.dup
88-
payload[:dest] = "https://notadomain"
89-
jwt_token = JWT.encode(payload, ShopifyAPI::Context.api_secret_key, "HS256")
90-
assert_raises(ShopifyAPI::Errors::InvalidJwtTokenError) do
91-
ShopifyAPI::Auth::JwtPayload.new(jwt_token)
92-
end
93-
end
94-
9586
def test_decode_jwt_payload_fails_with_invalid_api_key
9687
jwt_token = JWT.encode(@jwt_payload, ShopifyAPI::Context.api_secret_key, "HS256")
9788

0 commit comments

Comments
 (0)