diff --git a/config/scout_apm.yml b/config/scout_apm.yml index 015e11c01e..0396592606 100644 --- a/config/scout_apm.yml +++ b/config/scout_apm.yml @@ -23,6 +23,12 @@ common: &defaults production: <<: *defaults errors_enabled: true + # Replaces Scout's default list (the first two). InvalidType is scanner noise from junk + # Accept/Content-Type headers; Rails already answers it with a 406. + errors_ignored_exceptions: + - ActiveRecord::RecordNotFound + - ActionController::RoutingError + - ActionDispatch::Http::MimeNegotiation::InvalidType development: <<: *defaults diff --git a/spec/config/scout_apm_spec.rb b/spec/config/scout_apm_spec.rb new file mode 100644 index 0000000000..582b7a5394 --- /dev/null +++ b/spec/config/scout_apm_spec.rb @@ -0,0 +1,26 @@ +require "rails_helper" + +RSpec.describe "Scout APM config" do + let(:context) { ScoutApm::Agent.instance.context } + let(:config) do + ScoutApm::Config.with_file(context, Rails.root.join("config/scout_apm.yml").to_s, environment: "production") + end + let(:ignored_exceptions) do + ScoutApm::ErrorService::IgnoredExceptions.new(context, config.value("errors_ignored_exceptions")) + end + + it "does not report invalid MIME types from junk Accept or Content-Type headers" do + exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new("not a valid MIME type") + + expect(ignored_exceptions.ignored?(exception)).to be true + end + + it "keeps ignoring Scout's default exceptions" do + expect(ignored_exceptions.ignored?(ActiveRecord::RecordNotFound.new)).to be true + expect(ignored_exceptions.ignored?(ActionController::RoutingError.new("not found"))).to be true + end + + it "still reports other errors" do + expect(ignored_exceptions.ignored?(StandardError.new)).to be false + end +end diff --git a/spec/requests/static_spec.rb b/spec/requests/static_spec.rb index 33147821f7..f2e2d73808 100644 --- a/spec/requests/static_spec.rb +++ b/spec/requests/static_spec.rb @@ -11,5 +11,25 @@ end it { is_expected.to be_successful } + + context "with an invalid Accept header" do + subject(:request) do + get root_path, headers: {"Accept" => "../../../../../../../../etc/passwd{{"} + + response + end + + it { is_expected.to have_http_status(:not_acceptable) } + end + + context "with an invalid Content-Type header" do + subject(:request) do + get root_path, headers: {"Content-Type" => "../../../../../../../../etc/passwd{{"} + + response + end + + it { is_expected.to have_http_status(:not_acceptable) } + end end end