Skip to content

Commit

Permalink
Decrease default allowed parameter recursion level from 100 to 32
Browse files Browse the repository at this point in the history
Fixes stack issues on HP-PARISC.  32 levels ought to be enough for
anybody.

Fixes #1640.
  • Loading branch information
jeremyevans committed Jul 19, 2020
1 parent 297bf99 commit 649c72b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. For info on
- HMAC argument for `Rack::Session::Cookie` doesn't accept a class constant anymore, but only a string recognized by OpenSSL (e.g. `"SHA256"`) or compatible instance (e.g. `OpenSSL::Digest.new("SHA256")`) ([#1676](https://github.com/rack/rack/pull/1676), [@bdewater](https://github.com/bdewater))
- `Rack::HTTP_VERSION` has been removed and the `HTTP_VERSION` env setting is no longer set in the CGI and Webrick handlers . ([#970](https://github.com/rack/rack/issues/970), [@jeremyevans](https://github.com/jeremyevans))
- `Rack::Request#[]` and `#[]=` now warn even in non-verbose mode. ([#1277](https://github.com/rack/rack/issues/1277), [@jeremyevans](https://github.com/jeremyevans))
- Decrease default allowed parameter recursion level from 100 to 32. ([#1640](https://github.com/rack/rack/issues/1640), [@jeremyevans](https://github.com/jeremyevans))

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -200,7 +200,7 @@ but this query string would not be allowed:

Limiting the depth prevents a possible stack overflow when parsing parameters.

Defaults to 100.
Defaults to 32.

=== multipart_part_limit

Expand Down
2 changes: 1 addition & 1 deletion lib/rack/utils.rb
Expand Up @@ -27,7 +27,7 @@ class << self
end
# The default number of bytes to allow parameter keys to take up.
# This helps prevent a rogue client from flooding a Request.
self.default_query_parser = QueryParser.make_default(65536, 100)
self.default_query_parser = QueryParser.make_default(65536, 32)

module_function

Expand Down
6 changes: 3 additions & 3 deletions test/spec_request.rb
Expand Up @@ -343,14 +343,14 @@ def initialize(*)
end

it "limit the allowed parameter depth when parsing parameters" do
env = Rack::MockRequest.env_for("/?a#{'[a]' * 110}=b")
env = Rack::MockRequest.env_for("/?a#{'[a]' * 40}=b")
req = make_request(env)
lambda { req.GET }.must_raise RangeError

env = Rack::MockRequest.env_for("/?a#{'[a]' * 90}=b")
env = Rack::MockRequest.env_for("/?a#{'[a]' * 30}=b")
req = make_request(env)
params = req.GET
90.times { params = params['a'] }
30.times { params = params['a'] }
params['a'].must_equal 'b'

old, Rack::Utils.param_depth_limit = Rack::Utils.param_depth_limit, 3
Expand Down

0 comments on commit 649c72b

Please sign in to comment.