Skip to content

Stop MIME scanner probes from creating Rollbar noise - #2881

Merged
mroderick merged 2 commits into
masterfrom
feature/issue-2873-malformed-accept
Sep 16, 2026
Merged

mroderick merged 2 commits into
masterfrom
feature/issue-2873-malformed-accept

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Fixes #2873

Corrected diagnosis

The issue description assumed these probes cause 500s and that rescue_responses needs the mapping added. Neither holds on Rails 8.1.3.1:

  • ActionDispatch::Http::MimeNegotiation::InvalidType has been mapped to :not_acceptable in the default rescue_responses since Rails 6.1 (rails/rails commit 2bad7eb1, 2020). Malformed Accept/Content-Type headers already get 406 responses.
  • Rollbar still reported the exception because its RollbarMiddleware reports 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.rb already ignores ActionController::RoutingError via config.exception_level_filters for the same reason. Rollbar's ExceptionReporter#exception_data passes use_exception_level_filters: true, and 'ignore' values suppress reporting entirely (rollbar 3.8.0, lib/rollbar/notifier.rb).

Changes

  1. Rollbar ignore filter (config/initializers/rollbar.rb) — add ActionDispatch::Http::MimeNegotiation::InvalidType to exception_level_filters as 'ignore'. This stops the Rollbar noise regardless of which header shape the bots use.
  2. Nginx edge block (config/nginx.conf.erb) — a map on the combined Accept/Content-Type headers returns 406 when either contains ../, keeping these probes out of the application's access logs.

Testing

  • New spec/config/rollbar_config_spec.rb asserts the filter is registered (written first, failed with nil before the initializer change).
  • New spec/requests/malformed_mime_headers_spec.rb characterises the existing 406 behaviour for both headers.
  • Full suite: bundle exec parallel_rspec spec/ -n 3 — 1446 examples, 0 failures. RuboCop clean on changed files.
  • The nginx config cannot be exercised in CI (nginx is baked into the dyno image). After deploy, verify on staging with:
    curl -s -o /dev/null -w '%{http_code}' -H 'Accept: ../../etc/services{{' https://<staging-host>/ should return 406.

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
mroderick marked this pull request as ready for review September 16, 2026 10:38

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

@mroderick
mroderick merged commit c05a1de into master Sep 16, 2026
10 checks passed
@mroderick
mroderick deleted the feature/issue-2873-malformed-accept branch September 16, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed Accept headers from bots cause 500 errors (Rollbar #549)

3 participants