Skip to content

Commit 3bc4349

Browse files
committed
Fix ReDoS vulnerability in name parsing
Thanks to @ooooooo_q for the patch! [CVE-2023-22799]
1 parent 93150b1 commit 3bc4349

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/global_id/uri/gid.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ def set_params(params)
127127
private
128128
COMPONENT = [ :scheme, :app, :model_name, :model_id, :params ].freeze
129129

130-
# Extracts model_name and model_id from the URI path.
131-
PATH_REGEXP = %r(\A/([^/]+)/?([^/]+)?\z)
132-
133130
def check_host(host)
134131
validate_component(host)
135132
super
@@ -149,11 +146,11 @@ def check_scheme(scheme)
149146
end
150147

151148
def set_model_components(path, validate = false)
152-
_, model_name, model_id = path.match(PATH_REGEXP).to_a
153-
model_id = CGI.unescape(model_id) if model_id
154-
149+
_, model_name, model_id = path.split('/', 3)
155150
validate_component(model_name) && validate_model_id(model_id, model_name) if validate
156151

152+
model_id = CGI.unescape(model_id) if model_id
153+
157154
@model_name = model_name
158155
@model_id = model_id
159156
end
@@ -166,7 +163,7 @@ def validate_component(component)
166163
end
167164

168165
def validate_model_id(model_id, model_name)
169-
return model_id unless model_id.blank?
166+
return model_id unless model_id.blank? || model_id.include?('/')
170167

171168
raise MissingModelIdError, "Unable to create a Global ID for " \
172169
"#{model_name} without a model id."

0 commit comments

Comments
 (0)