Skip to content
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

Validation of labels of domain names according to RFC 1035 #1515

Merged
merged 2 commits into from Jan 9, 2020

Conversation

guicassolato
Copy link
Contributor

@guicassolato guicassolato commented Jan 3, 2020

According to RFC 1035, domain host names must be 255 characters-long or less, and its labels must be 63 characters-long or less. Currently we do not validate domain names against this constraint which is causing OpenShift to reject non-compliant routes created by Zync.

One not-so-obvious case where this issue can cause us trouble is when creating a new product. The system_name of the product, chosen by the user, will end up being used to generate the proxy endpoints (depending on the sandbox proxy config). A sufficiently long system_name may produce a domain name containing a lable that is longer than 63 characters. The route will then fail to be created or updated by Zync, requiring a manual intervention by the user to fix it. The creation of the product succeeds in this case though; yet, the endpoints cannot be used.

This PR fixes this behavior by enforcing every domain name validated with https://github.com/3scale/porta/blob/bdc91b894eac16fbd81afd4f05198eb5cb8beee9/app/validators/uri_validator.rb to comply with the limits of characters specified by the RFC. Moreover, it makes proxy endpoints to be validated using this validator instead of using the old simple regex

URI_OPTIONAL_PORT = /\Ahttps?:\/\/[a-zA-Z0-9._-]*(:\d+)?\Z/
.

The PR also makes sure that validation errors on the proxy endpoints due to this new requirement are propagated to the service, specifically marking the system_name attribute. This is done with the support of https://github.com/3scale/porta/blob/bdc91b894eac16fbd81afd4f05198eb5cb8beee9/app/services/service_creator.rb.

Closes THREESCALE-2932.

@guicassolato guicassolato self-assigned this Jan 3, 2020
@guicassolato guicassolato requested a review from a team January 3, 2020 15:12
@@ -26,6 +26,10 @@ def valid_scheme?(scheme)
end
end

def valid_host?(host)
host.present? && (host.size <= 255) && !host.split('.').any? { |label| label.size > 63 }
Copy link
Contributor

@hallelujah hallelujah Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would separate it in another method

Suggested change
host.present? && (host.size <= 255) && !host.split('.').any? { |label| label.size > 63 }
host.present? && valid_domain_parts?
def valid_domain_parts
   host.split('.').map(&:size).all?(&63.method(:'>'))
end

…racters for the overall name and its labels

- overall host name must be 255 characters long or less
- labels must be 63 characters long or less

Closes https://issues.redhat.com/browse/THREESCALE-2932
@codecov
Copy link

codecov bot commented Jan 7, 2020

Codecov Report

Merging #1515 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1515      +/-   ##
=========================================
- Coverage      93%     93%   -0.01%     
=========================================
  Files        2514    2514              
  Lines       83469   83503      +34     
=========================================
+ Hits        77630   77658      +28     
- Misses       5839    5845       +6
Impacted Files Coverage Δ
test/unit/models_test.rb 100% <ø> (ø) ⬆️
app/models/proxy.rb 97.77% <100%> (-0.01%) ⬇️
test/integration/api/services_controller_test.rb 100% <100%> (ø) ⬆️
app/services/service_creator.rb 100% <100%> (ø) ⬆️
test/unit/proxy_test.rb 100% <100%> (ø) ⬆️
test/unit/validators/uri_validator_test.rb 100% <100%> (ø) ⬆️
app/validators/uri_validator.rb 100% <100%> (ø) ⬆️
lib/tasks/multitenant/tenants.rake 41.5% <0%> (-11.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bdc91b8...6ffe6ce. Read the comment docs.

@guicassolato guicassolato merged commit ef480eb into master Jan 9, 2020
@guicassolato guicassolato deleted the 63-char-host-name-labels branch January 9, 2020 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants