Skip to content

Commit

Permalink
Fix ReDoS vulnerability in name parsing
Browse files Browse the repository at this point in the history
Thanks to @ooooooo_q for the patch!

[CVE-2023-22799]
  • Loading branch information
tenderlove committed Jan 17, 2023
1 parent 42f5ea6 commit 4a75ecb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/global_id/uri/gid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def set_params(params)
private
COMPONENT = [ :scheme, :app, :model_name, :model_id, :params ].freeze

# Extracts model_name and model_id from the URI path.
PATH_REGEXP = %r(\A/([^/]+)/?([^/]+)?\z)

def check_host(host)
validate_component(host)
super
Expand All @@ -145,11 +142,11 @@ def check_scheme(scheme)
end

def set_model_components(path, validate = false)
_, model_name, model_id = path.match(PATH_REGEXP).to_a
model_id = CGI.unescape(model_id) if model_id

_, model_name, model_id = path.split('/', 3)
validate_component(model_name) && validate_model_id(model_id, model_name) if validate

model_id = CGI.unescape(model_id) if model_id

@model_name = model_name
@model_id = model_id
end
Expand All @@ -162,7 +159,7 @@ def validate_component(component)
end

def validate_model_id(model_id, model_name)
return model_id unless model_id.blank?
return model_id unless model_id.blank? || model_id.include?('/')

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

0 comments on commit 4a75ecb

Please sign in to comment.