Skip to content

7404 - Stop reporting invalid MIME type scanner probes to Scout - #7409

Open
costajohnt wants to merge 1 commit into
rubyforgood:mainfrom
costajohnt:fix/issue-7404-172617
Open

costajohnt wants to merge 1 commit into
rubyforgood:mainfrom
costajohnt:fix/issue-7404-172617

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

What github issue is this PR for, if any?

Resolves #7404

What changed, and why?

Turns out the home page isn't actually returning a 500 for these. Rails already maps
ActionDispatch::Http::MimeNegotiation::InvalidType to 406 in its default
rescue_responses, and I confirmed / and /users/sign_in return 406 with
production-style exception handling (show_exceptions = :all, no detailed exceptions).

What we're seeing is Scout's error middleware. It sits inside the Rails exception
handling and records every exception that passes through it unless the class is in
errors_ignored_exceptions. It doesn't care that Rails turns it into a 4xx.

I tried the suggestions in the issue first:

  • rescue_responses[...] = :not_acceptable is already the Rails default, so it doesn't change anything.
  • rescue_from in ApplicationController doesn't catch it. The exception comes from
    ActionController::Instrumentation#process_action calling request.format, and that
    runs outside rescue_from.

So this adds ActionDispatch::Http::MimeNegotiation::InvalidType to
errors_ignored_exceptions in the production block of config/scout_apm.yml. Setting
that key replaces Scout's default list, so I added the two defaults back
(ActiveRecord::RecordNotFound, ActionController::RoutingError).

If you'd rather these get rejected before reaching Scout at all, I can switch this
to a small Rack middleware instead. It's more code, and it has to avoid calling
request.formats before routing.

How is this tested? (please write rspec and jest tests!) 💖💪

  • New spec/config/scout_apm_spec.rb loads config/scout_apm.yml for production
    through Scout's own config loader and checks its ignore list: InvalidType is
    ignored, the two Scout defaults are still ignored, and a plain StandardError
    is still reported. The InvalidType example fails against the current config
    and passes with this change.
  • Added two examples to spec/requests/static_spec.rb: GET / with a junk Accept
    header and with a junk Content-Type header both return 406. These also pass on
    main, so they're regression coverage for the behaviour the issue asked about.
  • Ran bundle exec rspec spec/requests spec/controllers spec/config (all green) and
    bundle exec standardrb (clean).
  • Not run: system specs, the rest of the suite, erb_lint and npm lint (no ERB or JS changes).

Screenshots please :)

No UI changes.

This branch has not been deployed

No deployments
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.

Scanner probes cause MimeNegotiation::InvalidType 500s on the home page: return 4xx instead

1 participant