Skip to content

Commit 8f3ccbf

Browse files
committed
Remove Session serialize/deserialize methods to fix RCE vulnerability
The Session.deserialize method used Oj.load without safe mode, which allows instantiation of arbitrary Ruby objects. If an attacker could control session storage (e.g., compromise a Redis instance or database), they could inject malicious serialized data to achieve remote code execution. These methods were vestigial code from when the library handled session storage (deprecated in v12.3.0). After that deprecation, apps became responsible for their own session persistence, rendering serialize/deserialize unnecessary for their original purpose. Investigation confirmed no external usage - the shopify_app gem stores individual session attributes in database columns and reconstructs sessions using Session.new(). The only internal usage was copy_attributes_from, which called serialize just to enumerate attribute names via JSON.parse(other.serialize).keys before copying instance variables. This has been refactored to directly copy each attribute, eliminating the dependency on serialize. Breaking change: Session#serialize and Session.deserialize removed. Migration: Apps should use Session.new() to reconstruct sessions from stored attributes (the pattern already used by shopify_app). Complete removal eliminates the RCE vector entirely while maintaining all functionality.
1 parent 8522bbd commit 8f3ccbf

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44
## Unreleased
5+
- ⚠️ [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.
56

67
### 15.0.0
78

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)