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

Đang mở Phù hợp với người mới
#7,404 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rails, ruby
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc trình xử lý unsupported_media_type hiện có trong app/controllers/application_controller.rb, sau đó kiểm tra cách config.action_dispatch.rescue_responses được thiết lập trong config/application.rb. Thêm một request spec cho GET / với tiêu đề Accept sai định dạng và xác nhận rằng nó trả về phản hồi 4xx. Hoàn tất khi spec chạy đạt và kiểu MIME không hợp lệ không còn gây ra lỗi 500.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug

Problem

Scout APM Errors (7 days to 2026-11-15): ActionDispatch::Http::MimeNegotiation::InvalidType on StaticController#index (the home page). 4 all-time, 1 in the last 7 days, latest 2026-11-10. The message is a path-traversal probe: "../../../../../../../../../../etc/services{{" is not a valid MIME type.

Root cause

This is an automated scanner sending a junk Accept or Content-Type header. Rails raises while reading request.format and returns a 500, which pages us and fills the error list with noise. It is not a vulnerability: Rails rejects the value. It should be a 4xx, not an error.

Suggested fix

  • In ApplicationController, add rescue_from ActionDispatch::Http::MimeNegotiation::InvalidType with a handler that does head :not_acceptable (406) or head :bad_request (400). Look at the existing unsupported_media_type handler in app/controllers/application_controller.rb first; it may be reusable.
  • Note the exception can be raised before the controller runs (in middleware). If a controller rescue_from does not catch it in a spec, add the handler as a small Rack middleware or use config.action_dispatch.rescue_responses["ActionDispatch::Http::MimeNegotiation::InvalidType"] = :not_acceptable in config/application.rb. That one line is the simplest option, try it first.
  • Add a request spec: get "/", headers: {"Accept" => "../../etc/passwd{{"} returns 4xx, not 500.
  • Mark Scout error group 124280 resolved after deploy.

Difficulty: easy. Good first issue.

Ngôn ngữ chính
Ruby
Star
384
Fork
558
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
63

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rubyforgood/casa

Tất cả issue của rubyforgood/casa

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.