The RequestValidator can raise an exception when it tries to validate requests
that don't have any query parameters in the url and pass a non-enumerable (e.g.
the POST body as a string) value as the params.
This happens because internally it uses parsed_url = URI(url) and then
URI.decode_www_form(parsed_url.query) - without checking whether
parsed_url.query is nil.
We haven't seen this occur very frequently and we didn't have enough logging
last time it occured to be specific as to the arguments passed to validate
when it happened to us. But since this method should be able to validate whether
a request originated from Twilio or not, it should be resilient to issues such
as this.
In our specific code, we call it like this (simplified):
The above code is part of a Sinatra extension so env and request should be
understood within that context.
And in order to trigger the NoMethodError, request.url would have no query
parameters at all and env['rack.request.form_hash'] would need to not be
enumerable after being interogated by RequestValidator#body_or_hash. That
method has documentation indicating its use relative to versions of Rails,
however we are using this code in the context of Sinatra and Rack, not Rails.
Steps to Reproduce
The code snippet shows a working example of this bug in action
This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog (ref: DI-2242).
Issue Summary
The
RequestValidator
can raise an exception when it tries to validate requests that don't have any query parameters in the url and pass a non-enumerable (e.g. the POST body as a string) value as the params.This happens because internally it uses
parsed_url = URI(url)
and thenURI.decode_www_form(parsed_url.query)
- without checking whetherparsed_url.query
isnil
.We haven't seen this occur very frequently and we didn't have enough logging last time it occured to be specific as to the arguments passed to
validate
when it happened to us. But since this method should be able to validate whether a request originated from Twilio or not, it should be resilient to issues such as this.In our specific code, we call it like this (simplified):
The above code is part of a Sinatra extension so
env
andrequest
should be understood within that context.And in order to trigger the
NoMethodError
,request.url
would have no query parameters at all andenv['rack.request.form_hash']
would need to not be enumerable after being interogated byRequestValidator#body_or_hash
. That method has documentation indicating its use relative to versions of Rails, however we are using this code in the context of Sinatra and Rack, not Rails.Steps to Reproduce
The code snippet shows a working example of this bug in action
Code Snippet
Exception/Log
Technical details: