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

未关闭 适合新手
#7,404 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rails, ruby
领域
api, backend

调研方向

先阅读 app/controllers/application_controller.rb 中现有的 unsupported_media_type 处理程序,然后检查 config/application.rb 中如何设置 config.action_dispatch.rescue_responses。为带有格式错误的 Accept 标头的 GET / 添加一个 request spec,并确认它返回 4xx 响应。spec 通过且无效 MIME 类型不再导致 500 时,即为完成。

由索引模型根据 Issue 内容生成。

描述

⛓️ 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.

主要语言
Ruby
星标
384
派生
558
平均合并
1 天 7 小时
30 天内合并 PR
63

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rubyforgood/casa 的其他 Issue

查看 rubyforgood/casa 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。