From a9c022023361914f232b2b62572bab3c7b6a584a Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Wed, 22 Apr 2026 14:45:15 +0200 Subject: [PATCH] fix: ignore Accept header to prevent UnknownFormat errors Prevents server errors when crawlers/scripts send non-HTML Accept headers. See: https://github.com/rails/rails/commit/2f4aaed7b3feb3be787a316fab3144c06bb21a27 --- config/environments/production.rb | 35 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index ba891f0c4..ef788f7a9 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -15,8 +15,13 @@ # Turn on fragment caching in view templates. config.action_controller.perform_caching = true + # Ignore Accept header for format negotiation. + # Prevents UnknownFormat errors from crawlers/scripts sending non-HTML Accept headers. + # See: https://github.com/rails/rails/commit/2f4aaed7b3feb3be787a316fab3144c06bb21a27 + config.action_dispatch.ignore_accept_header = true + # Cache assets for far-future expiry since they are all digest stamped. - config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" } config.assets.js_compressor = :terser @@ -39,14 +44,14 @@ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } # Log to STDOUT with the current request id as a default log tag. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) # Change to "debug" to log everything (including potentially personally-identifiable information!). - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Prevent health checks from clogging up the logs. - config.silence_healthcheck_path = "/up" + config.silence_healthcheck_path = '/up' # Don't log any deprecations. config.active_support.report_deprecations = false @@ -70,15 +75,15 @@ # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. config.action_mailer.smtp_settings = { - port: '587', - address: 'smtp.sendgrid.net', - user_name: ENV['SENDGRID_USERNAME'], - password: ENV['SENDGRID_PASSWORD'], - domain: 'heroku.com', - authentication: :plain, - enable_starttls_auto: true - } - ActionMailer::Base.delivery_method = :smtp + port: '587', + address: 'smtp.sendgrid.net', + user_name: ENV['SENDGRID_USERNAME'], + password: ENV['SENDGRID_PASSWORD'], + domain: 'heroku.com', + authentication: :plain, + enable_starttls_auto: true + } + ActionMailer::Base.delivery_method = :smtp # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). @@ -88,7 +93,7 @@ config.active_record.dump_schema_after_migration = false # Only use :id for inspections in production. - config.active_record.attributes_for_inspect = [ :id ] + config.active_record.attributes_for_inspect = [:id] # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [