Stop MIME scanner probes from creating Rollbar noise - #2881
Merged
Merged
Conversation
Rails has mapped ActionDispatch::Http::MimeNegotiation::InvalidType to :not_acceptable in rescue_responses since Rails 6.1, so malformed Accept/Content-Type headers already get 406 responses. Rollbar still reported the handled exception because its middleware reports anything passing through. Add the exception class to exception_level_filters as "ignore", the same treatment RoutingError already receives.
Return 406 from nginx when the Accept or Content-Type header contains a path-traversal pattern, keeping these probes out of the application access logs entirely.
mroderick
marked this pull request as ready for review
September 16, 2026 10:38
KimberleyCook
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2873
Corrected diagnosis
The issue description assumed these probes cause 500s and that
rescue_responsesneeds the mapping added. Neither holds on Rails 8.1.3.1:ActionDispatch::Http::MimeNegotiation::InvalidTypehas been mapped to:not_acceptablein the defaultrescue_responsessince Rails 6.1 (rails/rails commit 2bad7eb1, 2020). Malformed Accept/Content-Type headers already get 406 responses.RollbarMiddlewarereports every exception passing through it (:use_exception_level_filters => true), even ones Rails has already rescued and rendered as 406.Verification of the middleware chain
config/initializers/rollbar.rbalready ignoresActionController::RoutingErrorviaconfig.exception_level_filtersfor the same reason. Rollbar'sExceptionReporter#exception_datapassesuse_exception_level_filters: true, and'ignore'values suppress reporting entirely (rollbar 3.8.0,lib/rollbar/notifier.rb).Changes
config/initializers/rollbar.rb) — addActionDispatch::Http::MimeNegotiation::InvalidTypetoexception_level_filtersas'ignore'. This stops the Rollbar noise regardless of which header shape the bots use.config/nginx.conf.erb) — amapon the combined Accept/Content-Type headers returns 406 when either contains../, keeping these probes out of the application's access logs.Testing
spec/config/rollbar_config_spec.rbasserts the filter is registered (written first, failed withnilbefore the initializer change).spec/requests/malformed_mime_headers_spec.rbcharacterises the existing 406 behaviour for both headers.bundle exec parallel_rspec spec/ -n 3— 1446 examples, 0 failures. RuboCop clean on changed files.curl -s -o /dev/null -w '%{http_code}' -H 'Accept: ../../etc/services{{' https://<staging-host>/should return 406.