-
Notifications
You must be signed in to change notification settings - Fork 73
THREESCALE-15550: Upgrade uri gem #4356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
09fa2ae
361e3b9
46b5aff
47252e4
4cb28f4
8641c06
4d98455
9f32039
b216d16
5b5bc85
794a67c
493a7cf
3dd8111
4b7f655
6400cf4
99b10e6
e47b127
f720960
2ed9e4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,9 @@ def show | |
| protected | ||
|
|
||
| def referrer_url | ||
| url = params[:referrer] | ||
| url = params.permit(:referrer)[:referrer] | ||
| if url | ||
| URI.decode(url) | ||
| CGI.unescapeURIComponent(url) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The referrer URL is generated by our app and passed through the OAuth redirect flow. Malformed percent encoding would only occur if the user tampered with their own callback URL, which isn't a scenario we need to guard against
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor:
jlledom marked this conversation as resolved.
|
||
| else | ||
| new_admin_service_path | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,12 +29,15 @@ class Proxy < ApplicationRecord # rubocop:disable Metrics/ClassLength | |
|
|
||
| validates :error_status_no_match, :error_status_auth_missing, :error_status_auth_failed, :error_status_limits_exceeded, presence: true | ||
|
|
||
| uri_pattern = URI::DEFAULT_PARSER.pattern | ||
| pchar = "(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})" | ||
| segment = "#{pchar}*(?:;#{pchar}*)*" | ||
| abs_path = "/#{segment}(?:/#{segment})*" | ||
| query = "(?:[\\-_.!~*'()a-zA-Z\\d;/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*" | ||
| optional_query = "(?:\\?(#{query}))?" | ||
| URI_PATH_PART = Regexp.new('\A' + abs_path + optional_query + '\z') | ||
| HOST = /\A(?:[a-zA-Z0-9\-._]|%\h\h)+(?::\d+)?\z/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see you said you verified it's the same as in old parser.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, its copy of original, and i verified them all in rails console, only difference is HOST, just added _ a for RFC3986 compliance
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I don't agree that we should start allowing underscores in hostnames. I think we should keep rejecting these. Is there a reason to allow them. If there is, I'm open to change my mind. Here and in the other places.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About this, can't we use the constants from I don't think it makes sense to eliminate all references to RFC2396 but then hardcode a copy of its patterns. In fact, we are actually using RFC2396 anyway, just in a more complicated way. If these values are exactly the same they were in RFC2396, then I think it's better to just mention RFC2396 and take them from the gem. If they are now different and meet RFC3986, then better create a helper module with all this regexps and use it from here or the validator. |
||
|
|
||
| URI_OR_LOCALHOST = /\A(https?:\/\/([a-zA-Z0-9._:\/?-])+|.*localhost.*)\Z/ | ||
| OPTIONAL_QUERY_FORMAT = "(?:\\?(#{uri_pattern.fetch(:QUERY)}))?" | ||
| URI_PATH_PART = Regexp.new('\A' + uri_pattern.fetch(:ABS_PATH) + OPTIONAL_QUERY_FORMAT + '\z') | ||
| HOST = Regexp.new('\A' + uri_pattern.fetch(:HOSTNAME) + '(:\d+)?' + '\z') | ||
|
|
||
| OAUTH_PARAMS = /(\?|&)(scope=|state=|tok=)/ | ||
|
|
||
|
|
@@ -675,7 +678,7 @@ def call(attribute) | |
|
|
||
| begin | ||
| uri = URI.parse(attribute_value) | ||
| value = URI::Generic.new(uri.scheme, uri.userinfo, uri.host, uri.port, uri.registry, uri.path, uri.opaque, uri.query, uri.fragment).to_s | ||
| value = URI::Generic.new(uri.scheme, uri.userinfo, uri.host, uri.port, nil, uri.path, uri.opaque, uri.query, uri.fragment).to_s | ||
|
qltysh[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found 8 issues: |
||
| @model[attribute] = value unless @model[attribute] == value | ||
| rescue URI::InvalidURIError | ||
| @model.errors.add(attribute, 'Invalid domain') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,16 @@ class PatternParser | |
| REGEX_LITERAL = /[_\w]+/i | ||
| REGEX_VARIABLE = /\{#{REGEX_LITERAL}\}/ | ||
|
|
||
| # pchar = unreserved | escaped | | ||
| # ":" | "@" | "&" | "=" | "+" | "$" | "," | ||
| UNRESERVED = "\\-_.!~*'()a-zA-Z\\d" | ||
| ESCAPED = "%[a-fA-F\\d]{2}" | ||
| RESERVED = ";/?:@&=+$,\\[\\]" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p URI::RFC2396_REGEXP::PATTERN::UNRESERVED etc
jlledom marked this conversation as resolved.
Outdated
|
||
|
|
||
| # pchar = unreserved / pct-encoded / ":" / "@" / "&" / "=" / "+" / "," ($ excluded intentionally) | ||
| param = / | ||
| (?: | ||
| [#{URI::REGEXP::PATTERN::UNRESERVED}:@&=+,] # note that $ is in the RFC but is removed for our purpposes | ||
| [#{UNRESERVED}:@&=+,] # note that $ is in the RFC but is removed for our purpposes | ||
| | | ||
| #{URI::REGEXP::PATTERN::ESCAPED} | ||
| #{ESCAPED} | ||
| | | ||
| #{REGEX_VARIABLE} | ||
| )* | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
|
|
@@ -53,9 +56,9 @@ class PatternParser | |
|
|
||
| query = / | ||
| (?: | ||
| [#{URI::REGEXP::PATTERN::UNRESERVED}#{URI::REGEXP::PATTERN::RESERVED}] | ||
| [#{UNRESERVED}#{RESERVED}] | ||
| | | ||
| #{URI::REGEXP::PATTERN::ESCAPED} | ||
| #{ESCAPED} | ||
| | | ||
| #{REGEX_LITERAL}=#{REGEX_VARIABLE} | ||
| )* | ||
|
qltysh[bot] marked this conversation as resolved.
|
||
|
|
@@ -89,7 +92,7 @@ def call(_) | |
| validates :http_method, inclusion: { in: ALLOWED_HTTP_METHODS } | ||
| validate :non_repeated_parameters | ||
| validate :no_vars_in_keys | ||
| validates :redirect_url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]), allow_blank: true, length: { maximum: 10000 } | ||
| validates :redirect_url, uri: { path: true, query: true, fragment: true }, allow_blank: true, length: { maximum: 10000 } | ||
|
|
||
| def parameters | ||
| Addressable::Template.new(path_pattern).variables | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.