mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 13:02:45 +08:00
SECURITY: Disallow caching of MIME/Content-Type errors (#14939)
This will sign intermediary proxies and/or misconfigured CDNs to not cache those error responses. Co-authored-by: Rafael dos Santos Silva <xfalcox@gmail.com>
This commit is contained in:
parent
a1dcf3a50c
commit
2da0001965
|
@ -314,7 +314,7 @@ module Middleware
|
|||
if PAYLOAD_INVALID_REQUEST_METHODS.include?(env[Rack::REQUEST_METHOD]) &&
|
||||
env[Rack::RACK_INPUT].size > 0
|
||||
|
||||
return [413, {}, []]
|
||||
return [413, { "Cache-Control" => "private, max-age=0, must-revalidate" }, []]
|
||||
end
|
||||
|
||||
helper = Helper.new(env)
|
||||
|
|
|
@ -35,7 +35,7 @@ module Middleware
|
|||
begin
|
||||
request.format
|
||||
rescue Mime::Type::InvalidMimeType
|
||||
return [400, {}, ["Invalid MIME type"]]
|
||||
return [400, { "Cache-Control" => "private, max-age=0, must-revalidate" }, ["Invalid MIME type"]]
|
||||
end
|
||||
|
||||
if ApplicationController.rescue_with_handler(exception, object: fake_controller)
|
||||
|
|
|
@ -243,11 +243,12 @@ describe Middleware::AnonymousCache do
|
|||
|
||||
context 'invalid request payload' do
|
||||
it 'returns 413 for GET request with payload' do
|
||||
status, _, _ = middleware.call(env.tap do |environment|
|
||||
status, headers, _ = middleware.call(env.tap do |environment|
|
||||
environment[Rack::RACK_INPUT].write("test")
|
||||
end)
|
||||
|
||||
expect(status).to eq(413)
|
||||
expect(headers["Cache-Control"]).to eq("private, max-age=0, must-revalidate")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user