diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f3169a4b..16652c8f7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -227,6 +227,9 @@ class ApplicationController < ActionController::Base end def invalid_authenticity_token + if api_request? + logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)." + end render_error "Invalid form authenticity token." end @@ -308,4 +311,8 @@ class ApplicationController < ActionController::Base def filename_for_content_disposition(name) request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name end + + def api_request? + %w(xml json).include? params[:format] + end end