Skip to content

Commit 8f42c2b

Browse files
authored
Merge pull request rails#55319 from cmitz/fix_param_encoding_errors
Fix errors when querystring keys have invalid encoding
2 parents a701ceb + 48a4dc6 commit 8f42c2b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Always check query string keys for valid encoding just like values are checked.
2+
3+
*Casper Smits*
4+
15
* Always return empty body for HEAD requests in `PublicExceptions` and
26
`DebugExceptions`.
37

actionpack/lib/action_dispatch/http/param_builder.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ def store_nested_param(params, name, v, depth, encoding_template = nil)
111111

112112
return if k.empty?
113113

114+
unless k.valid_encoding?
115+
raise InvalidParameterError, "Invalid encoding for parameter: #{k}"
116+
end
117+
114118
if depth == 0 && String === v
115119
# We have to wait until we've found the top part of the name,
116120
# because that's what the encoding template is configured with

actionpack/test/dispatch/request_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,11 @@ class RequestParameters < BaseRequestTest
11211121
assert_raises(ActionController::BadRequest) { request.parameters }
11221122
end
11231123

1124+
test "parameters key containing an invalid UTF8 character" do
1125+
request = stub_request("QUERY_STRING" => "%81E=bar")
1126+
assert_raises(ActionController::BadRequest) { request.parameters }
1127+
end
1128+
11241129
test "parameters containing a deeply nested invalid UTF8 character" do
11251130
request = stub_request("QUERY_STRING" => "foo[bar]=%81E")
11261131
assert_raises(ActionController::BadRequest) { request.parameters }

0 commit comments

Comments
 (0)