mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 13:16:59 +08:00
SECURITY: Remove ember-cli specific response from application routes (#15155)
Under some conditions, these varied responses could lead to cache poisoning, hence the 'security' label. Previously the Rails application would serve JSON data in place of HTML whenever Ember CLI requested an `application.html.erb`-rendered page. This commit removes that logic, and instead parses the HTML out of the standard response. This means that Rails doesn't need to customize its response for Ember CLI.
This commit is contained in:
@ -119,23 +119,9 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
class RenderEmpty < StandardError; end
|
||||
class PluginDisabled < StandardError; end
|
||||
class EmberCLIHijacked < StandardError; end
|
||||
|
||||
def catch_ember_cli_hijack
|
||||
yield
|
||||
rescue ActionView::Template::Error => ex
|
||||
raise ex unless ex.cause.is_a?(EmberCLIHijacked)
|
||||
send_ember_cli_bootstrap
|
||||
end
|
||||
|
||||
rescue_from RenderEmpty do
|
||||
catch_ember_cli_hijack do
|
||||
with_resolved_locale { render 'default/empty' }
|
||||
end
|
||||
end
|
||||
|
||||
rescue_from EmberCLIHijacked do
|
||||
send_ember_cli_bootstrap
|
||||
with_resolved_locale { render 'default/empty' }
|
||||
end
|
||||
|
||||
rescue_from ArgumentError do |e|
|
||||
@ -324,21 +310,13 @@ class ApplicationController < ActionController::Base
|
||||
rescue Discourse::InvalidAccess
|
||||
return render plain: message, status: status_code
|
||||
end
|
||||
catch_ember_cli_hijack do
|
||||
with_resolved_locale do
|
||||
error_page_opts[:layout] = opts[:include_ember] ? 'application' : 'no_ember'
|
||||
render html: build_not_found_page(error_page_opts)
|
||||
end
|
||||
with_resolved_locale do
|
||||
error_page_opts[:layout] = opts[:include_ember] ? 'application' : 'no_ember'
|
||||
render html: build_not_found_page(error_page_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def send_ember_cli_bootstrap
|
||||
response.headers['X-Discourse-Bootstrap-Required'] = true
|
||||
response.headers['Content-Type'] = "application/json"
|
||||
render json: { preloaded: @preloaded }
|
||||
end
|
||||
|
||||
# If a controller requires a plugin, it will raise an exception if that plugin is
|
||||
# disabled. This allows plugins to be disabled programmatically.
|
||||
def self.requires_plugin(plugin_name)
|
||||
|
Reference in New Issue
Block a user