Skip to content

Commit 873d39e

Browse files
committed
Use a fully resolved file path when confirming if a file can be served by Rack::Static.
1 parent 7829663 commit 873d39e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/rack/static.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def can_serve(path)
122122

123123
def call(env)
124124
path = env[PATH_INFO]
125+
actual_path = Utils.clean_path_info(Utils.unescape_path(path))
125126

126-
if can_serve(path)
127+
if can_serve(actual_path)
127128
if overwrite_file_path(path)
128129
env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
129130
elsif @gzip && env['HTTP_ACCEPT_ENCODING'] && /\bgzip\b/.match?(env['HTTP_ACCEPT_ENCODING'])

test/spec_static.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ def static(app, *args)
4343
res.body.must_match(/ruby/)
4444
end
4545

46+
it "does not serve files outside :urls" do
47+
res = @request.get("/cgi/../#{File.basename(__FILE__)}")
48+
res.must_be :ok?
49+
res.body.must_equal "Hello World"
50+
end
51+
4652
it "404s if url root is known but it can't find the file" do
4753
res = @request.get("/cgi/foo")
4854
res.must_be :not_found?

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy