You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
paramsdorequires:file,type: File,desc: 'The file to be uploaded'end
Currently, the File validator is only validating the existence of key :tempfile
# lib/grape/validations/types/file.rbdefvalue_coerced?(value)# Rack::Request creates a Hash with filename,# content type and an IO object. Do a bit of basic# duck-typing.value.is_a?(::Hash) && value.key?(:tempfile)end
Rack will set params[:file][:tempfile] to a TempFile object and params[:file][:filename] to a String if the end user really uploads a file.
However, the value of params[:file][:tempfile] is easily controllable by sending a normal POST request
@dm1try I think the whole point is that it can be a String which would cause you to read a file on the system like /etc/passwd and better safe than sorry.
Consider following parameter declaration
Currently, the File validator is only validating the existence of key :tempfile
Rack will set
params[:file][:tempfile]to aTempFileobject andparams[:file][:filename]to aStringif the end user really uploads a file.However, the value of
params[:file][:tempfile]is easily controllable by sending a normal POST requestHere the request will pass the check
value.key?(:tempfile)while it's not a valid file uploading request in fact.I think this issue is a risk and has caused some security issues (https://nvd.nist.gov/vuln/detail/CVE-2018-18649 for example). So I suggest to patch this validator to validate the type of :tempfile. Here is a great example
The text was updated successfully, but these errors were encountered: