req.params may throw EOFError #547
-
This is more of a question / advice on protecting against some types of malformed requests. We currently have simple simple block Rack::Attack.blocklist("Block requests with invalid params") do |req|
begin
req.params # just testing that params are valid
false
rescue Rack::QueryParser::InvalidParameterError
true
end
end This works great for requests like However, there is another type of malformed requests that causes Rack to throw an I know I can also rescue from EOFError. However, if I don't have this block, Rails seems to handle the malformed request fine somehow. I can even access |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I reckon if you want to keep the RoR's behavior you have to replicate it yourself: # @see ActionDispatch::Http::Parameters#parameters
params =
begin
req.params
rescue EOFError
req.GET
end |
Beta Was this translation helpful? Give feedback.
-
Apologies for not replying, and it's been a while so my memory is fuzzy, but if I recall, what we ended up doing was catching |
Beta Was this translation helpful? Give feedback.
Apologies for not replying, and it's been a while so my memory is fuzzy, but if I recall, what we ended up doing was catching
EOFError
but then returningfalse
inside the blocklist. This would pass the request to Rails, which would handle it ok.