Skip to content

Commit

Permalink
Merge pull request #1683 from cji-stripe/static_path_check
Browse files Browse the repository at this point in the history
Validate expanded path matches public_dir when serving static files
  • Loading branch information
namusyaka committed Mar 15, 2021
2 parents 936ea0b + 462c3ca commit cf40452
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
Expand Up @@ -1090,6 +1090,7 @@ def static!(options = {})
return unless valid_path?(path)

path = File.expand_path(path)
return unless path.start_with?(File.expand_path(public_dir) + '/')
return unless File.file?(path)

env['sinatra.static_file'] = path
Expand Down
1 change: 1 addition & 0 deletions test/static_test.rb
Expand Up @@ -97,6 +97,7 @@ class StaticTest < Minitest::Test
mock_app do
set :static, true
set :public_folder, __dir__ + '/data'
disable :protection
end
get "/../#{File.basename(__FILE__)}"
assert not_found?
Expand Down

0 comments on commit cf40452

Please sign in to comment.