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

added request validation for urls with and without ports #481

Merged
merged 4 commits into from
Oct 24, 2019
Merged

Conversation

eshanholtz
Copy link
Contributor

PR for DI-322

@eshanholtz eshanholtz changed the title added request validation for urls with and without ports WIP: added request validation for urls with and without ports Oct 23, 2019
@eshanholtz
Copy link
Contributor Author

Just realized I forgot to add url builder unit tests. Adding now.

@eshanholtz eshanholtz changed the title WIP: added request validation for urls with and without ports added request validation for urls with and without ports Oct 23, 2019
Comment on lines -29 to +38
if params_hash.is_a? Enumerable
expected = build_signature_for(url, params_hash)
secure_compare(expected, signature)
else
expected_signature = build_signature_for(url, {})
body_hash = URI.decode_www_form(URI(url).query).to_h['bodySHA256']
expected_hash = build_hash_for(params)
secure_compare(expected_signature, signature) && secure_compare(expected_hash, body_hash)
unless params_hash.is_a? Enumerable
body_hash = URI.decode_www_form(parsed_url.query).to_h['bodySHA256']
params_hash = build_hash_for(params)
valid_body = !(params_hash.nil? || body_hash.nil?) && secure_compare(params_hash, body_hash)
params_hash = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Noice!

url += parsed_url.host ? "#{parsed_url.host}:#{parsed_url.default_port}" : ''
url += parsed_url.path
url += parsed_url.query ? "?#{parsed_url.query}" : ''
url += parsed_url.fragment ? "##{parsed_url.fragment}" : ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think there's any tests for this line, but I assume it's the correct syntax.

lib/twilio-ruby/security/request_validator.rb Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants