Skip to content

Commit

Permalink
prevent tampering with host, port, protocol
Browse files Browse the repository at this point in the history
Prevents :host, :port, :protocol settings get inherited from GET query
parameters.

Fixes #285
  • Loading branch information
mislav committed Sep 18, 2013
1 parent a213b7e commit c62c6f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/will_paginate/view_helpers/action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def default_url_params
def url(page)
@base_url_params ||= begin
url_params = merge_get_params(default_url_params)
url_params[:only_path] = true
merge_optional_params(url_params)
end

Expand Down
17 changes: 13 additions & 4 deletions spec/view_helpers/action_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ def renderer.gap() '<span class="my-gap">~~</span>' end
paginate
assert_links_match /foo\[bar\]=baz/
end

it "doesn't allow tampering with host, port, protocol" do
request.params :host => 'disney.com', :port => '99', :protocol => 'ftp'
paginate
assert_links_match %r{^/foo/bar}
assert_no_links_match /disney/
assert_no_links_match /99/
assert_no_links_match /ftp/
end

it "should not preserve parameters on POST" do
request.post
Expand Down Expand Up @@ -328,16 +337,16 @@ class << helper
include Routes.url_helpers
include WillPaginate::ActionView
end
helper.default_url_options[:host] = 'example.com'
helper.default_url_options[:controller] = 'dummy'
# helper.default_url_options[:only_path] = true
helper.default_url_options.update \
:only_path => true,
:controller => 'dummy'

collection = WillPaginate::Collection.new(2, 1, 3)
@render_output = helper.will_paginate(collection)

assert_select 'a[href]', 4 do |links|
urls = links.map {|l| l['href'] }.uniq
urls.should == ['http://example.com/dummy/page/1', 'http://example.com/dummy/page/3']
urls.should == ['/dummy/page/1', '/dummy/page/3']
end
end

Expand Down

3 comments on commit c62c6f6

@jordimassaguerpla
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this commit the fix for

"important security fix that prevents XSS in generated pagination links"

?

@mislav
Copy link
Owner Author

@mislav mislav commented on c62c6f6 Jan 9, 2014

Choose a reason for hiding this comment

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

Yes

@jordimassaguerpla
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks

Please sign in to comment.