Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate expanded path matches public_dir when serving static files #1683

Merged
merged 1 commit into from Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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