Skip to content

Commit 18b8a7f

Browse files
committed
Do not respond to http requests asking for a file://
Based on CVE-2018-3760 when the Sprockets server is accidentally being used in production, an attacker can pass in a specifically crafted url that will allow them access to view every file on the system. If the file hit contains a compilable extension such as `.erb` then the code in that file will be executed. A Rails app will be using the Sprockets file server in production if they have accidentally configured their app to: ```ruby config.assets.compile = true # Your app is vulnerable ``` It is highly recommended to not use the Sprockets server in production and to instead precompile assets to disk and serve them through a server such as Nginx or via the static file middleware that ships with rails `config.public_file_server.enabled = true`. This patch mitigates the issue, but explicitly disallowing any requests to any URI resources via the server.
1 parent 2199a60 commit 18b8a7f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/sprockets/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def forbidden_request?(path)
9090
#
9191
# http://example.org/assets/../../../etc/passwd
9292
#
93-
path.include?("..") || Pathname.new(path).absolute?
93+
path.include?("..") || Pathname.new(path).absolute? || path.include?("://")
9494
end
9595

9696
# Returns a 403 Forbidden response tuple

test/test_server.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ def app
230230
assert_equal 403, last_response.status
231231
end
232232

233+
test "illegal access of a file asset" do
234+
absolute_path = fixture_path("server/app/javascripts")
235+
236+
get "assets/file:%2f%2f//#{absolute_path}/foo.js"
237+
assert_equal 403, last_response.status
238+
end
239+
233240
test "add new source to tree" do
234241
filename = fixture_path("server/app/javascripts/baz.js")
235242

0 commit comments

Comments
 (0)