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 Jun 17, 2014
1 parent 03c19d7 commit cca3616
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

1 comment on commit cca3616

@leods92
Copy link

Choose a reason for hiding this comment

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

What if we filtered params instead?
I think some may need the full URL.

Please sign in to comment.