Skip to content

Commit 92c025d

Browse files
jhawthorntenderlove
authored andcommitted
Only accept formats from registered mime types
[CVE-2019-5418] [CVE-2019-5419]
1 parent 24ab200 commit 92c025d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

actionpack/lib/action_dispatch/http/mime_negotiation.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ def formats
7676
else
7777
[Mime[:html]]
7878
end
79+
80+
v = v.select do |format|
81+
format.symbol || format.ref == "*/*"
82+
end
83+
7984
set_header k, v
8085
end
8186
end

actionpack/test/controller/mime/respond_to_test.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def made_for_content_type
103103
def custom_type_handling
104104
respond_to do |type|
105105
type.html { render body: "HTML" }
106-
type.custom("application/crazy-xml") { render body: "Crazy XML" }
106+
type.custom("application/fancy-xml") { render body: "Fancy XML" }
107107
type.all { render body: "Nothing" }
108108
end
109109
end
@@ -292,12 +292,14 @@ def setup
292292
@request.host = "www.example.com"
293293
Mime::Type.register_alias("text/html", :iphone)
294294
Mime::Type.register("text/x-mobile", :mobile)
295+
Mime::Type.register("application/fancy-xml", :fancy_xml)
295296
end
296297

297298
def teardown
298299
super
299300
Mime::Type.unregister(:iphone)
300301
Mime::Type.unregister(:mobile)
302+
Mime::Type.unregister(:fancy_xml)
301303
end
302304

303305
def test_html
@@ -453,10 +455,10 @@ def test_synonyms
453455
end
454456

455457
def test_custom_types
456-
@request.accept = "application/crazy-xml"
458+
@request.accept = "application/fancy-xml"
457459
get :custom_type_handling
458-
assert_equal "application/crazy-xml", @response.content_type
459-
assert_equal "Crazy XML", @response.body
460+
assert_equal "application/fancy-xml", @response.content_type
461+
assert_equal "Fancy XML", @response.body
460462

461463
@request.accept = "text/html"
462464
get :custom_type_handling

actionpack/test/controller/new_base/content_negotiation_test.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ class TestContentNegotiation < Rack::TestCase
1818
assert_body "Hello world */*!"
1919
end
2020

21-
test "Not all mimes are converted to symbol" do
21+
test "A js or */* Accept header will return HTML" do
22+
get "/content_negotiation/basic/hello", headers: { "HTTP_ACCEPT" => "text/javascript, */*" }
23+
assert_body "Hello world text/html!"
24+
end
25+
26+
test "A js or */* Accept header on xhr will return HTML" do
27+
get "/content_negotiation/basic/hello", headers: { "HTTP_ACCEPT" => "text/javascript, */*" }, xhr: true
28+
assert_body "Hello world text/javascript!"
29+
end
30+
31+
test "Unregistered mimes are ignored" do
2232
get "/content_negotiation/basic/all", headers: { "HTTP_ACCEPT" => "text/plain, mime/another" }
23-
assert_body '[:text, "mime/another"]'
33+
assert_body '[:text]'
2434
end
2535
end
2636
end

0 commit comments

Comments
 (0)