Skip to content

Commit e9cc781

Browse files
authored
Merge branch 'main' into liz/drop-ruby-versions
2 parents ad8b966 + 2a25d93 commit e9cc781

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

BREAKING_CHANGES_FOR_V16.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,64 @@ Ruby 3.0 and 3.1 have reached End of Life (EOL).
1313
If you're currently using Ruby 3.0 or 3.1, you'll need to upgrade to Ruby 3.2 or higher before upgrading to shopify-api-ruby v16.0.0.
1414

1515
**Note:** Ruby 3.2+ includes performance improvements and new features. Most applications should not require code changes beyond updating the Ruby version itself.
16+
## Removal of `Session#serialize` and `Session.deserialize` methods
17+
18+
The `Session#serialize` and `Session.deserialize` methods have been removed due to a security vulnerability. The `deserialize` method used `Oj.load` without safe mode, which allows instantiation of arbitrary Ruby objects.
19+
20+
These methods were originally created for session persistence when the library handled session storage. After session storage was deprecated in v12.3.0, applications became responsible for their own session persistence, making these methods unnecessary for their original purpose.
21+
22+
### Why this change?
23+
24+
**No impact on most applications:** The `shopify_app gem` stores individual session attributes in database columns and reconstructs sessions using `Session.new()`, which is the recommended pattern.
25+
26+
## Migration Guide
27+
28+
If your application was using `Session#serialize` and `Session.deserialize` for session persistence, you'll need to refactor to store individual session attributes and reconstruct sessions using `Session.new()`.
29+
30+
### Previous implementation (removed in v16.0.0)
31+
32+
```ruby
33+
# Storing a session
34+
session = ShopifyAPI::Auth::Session.new(
35+
shop: "example.myshopify.com",
36+
access_token: "shpat_xxxxx",
37+
scope: "read_products,write_orders"
38+
)
39+
40+
serialized_data = session.serialize
41+
# Store serialized_data in Redis, database, etc.
42+
redis.set("session:#{session.id}", serialized_data)
43+
44+
# Retrieving a session
45+
serialized_data = redis.get("session:#{session_id}")
46+
session = ShopifyAPI::Auth::Session.deserialize(serialized_data)
47+
```
48+
49+
### New implementation (required in v16.0.0)
50+
51+
Store individual session attributes and reconstruct using `Session.new()`:
52+
53+
## Reference: shopify_app gem implementation
54+
55+
The [shopify_app gem](https://github.com/Shopify/shopify_app) provides a reference implementation of session storage that follows these best practices:
56+
57+
**Shop Session Storage** ([source](https://github.com/Shopify/shopify_app/blob/main/lib/shopify_app/session/shop_session_storage.rb)):
58+
```ruby
59+
# Stores attributes in database columns
60+
def store(auth_session)
61+
shop = find_or_initialize_by(shopify_domain: auth_session.shop)
62+
shop.shopify_token = auth_session.access_token
63+
shop.save!
64+
end
65+
66+
# Reconstructs using Session.new()
67+
def retrieve(id)
68+
shop = find_by(id: id)
69+
return unless shop
70+
71+
ShopifyAPI::Auth::Session.new(
72+
shop: shop.shopify_domain,
73+
access_token: shop.shopify_token
74+
)
75+
end
76+
```

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44
## Unreleased
55
- ⚠️ [Breaking] Minimum required Ruby version is now 3.2. Ruby 3.0 and 3.1 are no longer supported.
6+
- ⚠️ [Breaking] Removed `Session#serialize` and `Session.deserialize` methods due to security concerns (RCE vulnerability via `Oj.load`). These methods were not used internally by the library. If your application relies on session serialization, use `Session.new()` to reconstruct sessions from stored attributes instead.
67

78
### 15.0.0
89

lib/shopify_api/auth/session.rb

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,22 @@ def from(shop:, access_token_response:)
117117
shopify_session_id: access_token_response.session,
118118
)
119119
end
120-
121-
sig { params(str: String).returns(Session) }
122-
def deserialize(str)
123-
Oj.load(str)
124-
end
125120
end
126121

127122
sig { params(other: Session).returns(Session) }
128123
def copy_attributes_from(other)
129-
JSON.parse(other.serialize).keys.each do |key|
130-
next if key.include?("^")
131-
132-
variable_name = "@#{key}"
133-
instance_variable_set(variable_name, other.instance_variable_get(variable_name))
134-
end
124+
@shop = other.shop
125+
@state = other.state
126+
@access_token = other.access_token
127+
@scope = other.scope
128+
@associated_user_scope = other.associated_user_scope
129+
@expires = other.expires
130+
@associated_user = other.associated_user
131+
@is_online = other.online?
132+
@shopify_session_id = other.shopify_session_id
135133
self
136134
end
137135

138-
sig { returns(String) }
139-
def serialize
140-
Oj.dump(self)
141-
end
142-
143136
alias_method :eql?, :==
144137
sig { params(other: T.nilable(Session)).returns(T::Boolean) }
145138
def ==(other)

0 commit comments

Comments
 (0)