-
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 4 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 |
|---|---|---|
|
|
@@ -24,9 +24,8 @@ def message_subject(message) | |
| def hyperlink_urls(text) | ||
| text = h(text) | ||
|
|
||
| text.scan(URI.regexp(%w(http https))) do | ||
| #$& contains the whole match of the regural expression | ||
| url = $&.sub(/\.$/, '').sub(/\:$/,'') | ||
| text.scan(%r{https?://[^\s)\]>]+}) do | ||
|
jlledom marked this conversation as resolved.
Outdated
|
||
| url = Regexp.last_match(0).sub(/[.:]+\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. this seems to be a behavior change. Previously only
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. Reverted in commit 4d98455, I also reworked the regex to accept ), ], > as valid URL characters per RFC3986. |
||
| text = text.sub(url, link_to(url, url)) | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,9 @@ class AuthenticationProvider < ApplicationRecord | |
|
|
||
| validates :client_id, :client_secret, presence: true, if: :oauth_config_required? | ||
|
|
||
| with_options format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), allow_blank: true, message: :invalid_url } do |ops| | ||
| ops.validates :site | ||
| with_options uri: { path: true, query: true, fragment: true }, allow_blank: true do |ops| | ||
| # Skip uri: for whitespace URLs — keycloak/auth0 whitespace validator handles these | ||
| ops.validates :site, unless: -> { site.to_s.match?(/\s/) } | ||
|
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. The UX improvement is nice (one error instead of two for whitespace URLs). Was stripping whitespace with
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. The UX improvement is nice (one error instead of two for whitespace URLs). Was stripping whitespace with
jlledom marked this conversation as resolved.
|
||
| ops.validates :token_url | ||
| ops.validates :authorize_url | ||
| ops.validates :user_info_url | ||
|
|
||
| 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,32 +30,35 @@ class PatternParser | |
| REGEX_LITERAL = /[_\w]+/i | ||
| REGEX_VARIABLE = /\{#{REGEX_LITERAL}\}/ | ||
|
|
||
| # pchar = unreserved | escaped | | ||
| # ":" | "@" | "&" | "=" | "+" | "$" | "," | ||
| param = / | ||
| 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.
|
||
| /x | ||
|
|
||
| segment = / | ||
| #{param} | ||
| (?:;#{param})* | ||
| SEGMENT = / | ||
| #{PARAM} | ||
| (?:;#{PARAM})* | ||
| /x | ||
|
|
||
| REGEX_PATH = %r{ | ||
| /#{segment}(?:/#{segment})* # normal URI path segments like /foo/bar | ||
| /#{SEGMENT}(?:/#{SEGMENT})* # normal URI path segments like /foo/bar | ||
| }x | ||
|
|
||
| query = / | ||
| 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.
|
||
|
|
@@ -64,7 +67,7 @@ class PatternParser | |
| ABSOLUTE_PATH = /\A | ||
| #{REGEX_PATH} # absolute path | ||
| [$]? # optionally forcing to match the end of path | ||
| (?:\?(?:#{query}))? # optionally followed by a query string | ||
| (?:\?(?:#{QUERY}))? # optionally followed by a query string | ||
| \Z/x | ||
|
|
||
| def initialize | ||
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1898,6 +1898,7 @@ en: | |
|
|
||
| errors: | ||
| messages: | ||
| invalid_url: "Invalid URL format" | ||
|
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. Now that all validators use
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. Removed in 794a67c
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. Now that all validators use |
||
| host_label_too_long: is too long for one or more labels of the host (maximum is %{count} characters) | ||
| duplicated_user_provider_side: "Duplicate user registration. Delete one of the duplicates in order to continue." | ||
| duplicated_user_buyer_side: "For activating your account please contact support." | ||
|
|
@@ -2028,16 +2029,20 @@ en: | |
| cannot_be_destroyed_with_products: cannot be deleted because it is used by at least one Product | ||
| private_endpoint: | ||
| invalid: "the accepted format is 'scheme://address(:port)(/path)'. Accepted schemes are http, https, ws and wss" | ||
| invalid_url: "the accepted format is 'scheme://address(:port)(/path)'. Accepted schemes are http, https, ws and wss" | ||
| proxy: | ||
| attributes: | ||
| api_backend: | ||
| invalid: "the accepted format is 'scheme://address(:port)(/path)'. Accepted schemes are http, https, ws and wss" | ||
| invalid_url: "the accepted format is 'scheme://address(:port)(/path)'. Accepted schemes are http, https, ws and wss" | ||
| api_test_path: | ||
| invalid: "only URI characters allowed" | ||
| endpoint: | ||
| invalid: "the accepted format is 'protocol://address(:port)'" | ||
| invalid_url: "the accepted format is 'protocol://address(:port)'" | ||
| sandbox_endpoint: | ||
| invalid: "the accepted format is 'protocol://address(:port)'" | ||
| invalid_url: "the accepted format is 'protocol://address(:port)'" | ||
| oauth_login_url: | ||
| invalid: "invalid auth login url. (hint: make sure it uses https scheme)" | ||
| proxy_config: | ||
|
|
@@ -2106,6 +2111,7 @@ en: | |
| attributes: | ||
| url: | ||
| invalid: Must be a valid URL such as http://example.com | ||
| invalid_url: Must be a valid URL such as http://example.com | ||
|
|
||
| cms/partial: | ||
| attributes: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,9 @@ | |
| url: url | ||
| } | ||
|
|
||
| (provider.web_hook || provider.build_web_hook).update!(attrs) | ||
| hook = provider.web_hook || provider.build_web_hook | ||
| hook.assign_attributes(attrs) | ||
| hook.save!(validate: false) | ||
|
jlledom marked this conversation as resolved.
Outdated
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. Could the fixture URL be fixed to pass validation instead of skipping it? |
||
| end | ||
|
|
||
| Then /^there should be no webhooks enqueued$/ do | ||
|
|
||
|
jlledom marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.