Skip to content

Commit

Permalink
Merge pull request #67 from tilthouse/uri-parsing
Browse files Browse the repository at this point in the history
URI encode before passing to URI object to deal with pathological URIs
  • Loading branch information
tobmatth committed Mar 17, 2014
2 parents 2c9daa7 + c39a72b commit 1ef4515
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rack/ssl-enforcer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def ssl_request?

def destination_host
if @options[:redirect_to]
host_parts = URI.split(@options[:redirect_to])
host_parts = URI.split(URI.encode(@options[:redirect_to]))
host_parts[2] || host_parts[5]
end
end
Expand Down Expand Up @@ -153,7 +153,7 @@ def replace_scheme(uri, scheme)
return uri if not scheme_mismatch?

port = adjust_port_to(scheme)
uri_parts = URI.split(uri)
uri_parts = URI.split(URI.encode(uri))
uri_parts[3] = port unless port.nil?
uri_parts[0] = scheme
URI::HTTP.new(*uri_parts).to_s
Expand All @@ -162,9 +162,9 @@ def replace_scheme(uri, scheme)
def replace_host(uri, host)
return uri unless host_mismatch?

host_parts = URI.split(host)
host_parts = URI.split(URI.encode(host))
new_host = host_parts[2] || host_parts[5]
uri_parts = URI.split(uri)
uri_parts = URI.split(URI.encode(uri))
uri_parts[2] = new_host
URI::HTTPS.new(*uri_parts).to_s
end
Expand Down

9 comments on commit 1ef4515

@oveddan
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised this commit was done and accepted without any tests around it....this has caused bugs in our application

@rymai
Copy link
Collaborator

@rymai rymai commented on 1ef4515 Jul 17, 2014

Choose a reason for hiding this comment

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

The original committer tried to write a test but didn't succeed. Don't hesitate to open a pull-request with a failing test!

@oveddan
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not testable then it shouldn't be accepted. Tests should be required for new functionality, as is the case with widely used open source projects. Besides, the requirements in the readme state so.

What this commit does is encode url parameters, even if they are already encoded.

So if you have a url such as:
http://www.app.com/email?email=someemail%40somedomain.com
It gets encoded and redirected to:
https://www.app.com/email?email=someemail%254040somedomain.com

The test failed because the url it was testing is not valid from the get go. Rack ssl enforcer's job is not to fix invalid urls.
It's purpose is to redirect from http to https or visa versa with the original query string parameters.

Definitely not the desired behavior.

@rymai
Copy link
Collaborator

@rymai rymai commented on 1ef4515 Jul 17, 2014

Choose a reason for hiding this comment

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

I agree, please open a new issue/pull-request with the comment above. Thank you!

@oveddan
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, will do!

@tobmatth
Copy link
Owner Author

Choose a reason for hiding this comment

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

Dan - i'm really sorry, please accept my apologies about that. I fully agree with you, will try to fix that this evening...

@oveddan
Copy link
Contributor

Choose a reason for hiding this comment

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

@tobmatth no worries at all - thanks for keeping this to be an awesome awesome library!

@oveddan
Copy link
Contributor

Choose a reason for hiding this comment

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

Also - should I write some tests that verify that already encoded parameters do not get encoded again?

@tobmatth
Copy link
Owner Author

Choose a reason for hiding this comment

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

That'd be greatly appreciated!

Please sign in to comment.