aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJordan Owens <jkowens@gmail.com>2016-01-12 14:05:54 -0500
committerJordan Owens <jkowens@gmail.com>2016-01-12 14:05:54 -0500
commit918f0eea970c9f0d39b8d470a316ad5109935dae (patch)
treece831158a47a0c8cf3e0cc82c1536ac4eb5c4b63 /actionpack/lib
parent15299f3a5c0e068b4945bdb8199755100dc91e13 (diff)
downloadrails-918f0eea970c9f0d39b8d470a316ad5109935dae.tar.gz
rails-918f0eea970c9f0d39b8d470a316ad5109935dae.tar.bz2
rails-918f0eea970c9f0d39b8d470a316ad5109935dae.zip
Prevent attempt to serve a request with a null byte
File paths cannot contain null byte characters and methods that do path operations such as Rack::Utils#clean_path_info will raise unwanted errors.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/middleware/static.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb
index ea9ab3821d..41c220236a 100644
--- a/actionpack/lib/action_dispatch/middleware/static.rb
+++ b/actionpack/lib/action_dispatch/middleware/static.rb
@@ -27,7 +27,7 @@ module ActionDispatch
# in the server's `public/` directory (see Static#call).
def match?(path)
path = ::Rack::Utils.unescape_path path
- return false unless path.valid_encoding?
+ return false unless valid_path?(path)
path = Rack::Utils.clean_path_info path
paths = [path, "#{path}#{ext}", "#{path}/#{@index}#{ext}"]
@@ -94,6 +94,10 @@ module ActionDispatch
false
end
end
+
+ def valid_path?(path)
+ path.valid_encoding? && !path.include?("\0")
+ end
end
# This middleware will attempt to return the contents of a file's body from