我已经安装了Apache 2.4和mod_security 2.9.1,并且它正在运行,并带有一些非常基本的规则。mod_security:允许没有请求主体的POST请求的规则
我试图做一个POST请求,其中包含一些头信息,但在请求正文中没有任何内容(请求是由mod_security保护的API端点,并且该端点需要POST请求主体)。不需要身体的POST是有效的,每个以下:Are PUT and POST requests required/expected to have a request body?
mod_security阻止请求,因为它似乎无法分析/格式化正文(可能是因为它不存在)。
我该如何修改规则以允许没有身体的POST,但如果身体确实存在,则以其他方式正常工作。
正被触发的具体规则是:
SecRule REQBODY_ERROR "[email protected] 0" \
"id:'200002', phase:2,t:none,log,deny,status:415,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2"
的错误是:
[Fri Jul 08 10:32:32.9] [:error] [pid 7697] [client 10.0.2.2:57442] [client 10.0.2.2] ModSecurity: JSON parser error: parse error: premature EOF\n [hostname "example.com"] [uri "/api/v1/logout"] [unique_id "V377qH8AAQEAAB4RU6cAAAAD"]
[Fri Jul 08 10:32:32.901555 2016] [:error] [pid 7697] [client 10.0.2.2:57442] [client 10.0.2.2] ModSecurity: Access denied with code 415 (phase 2). Match of "eq 0" against "REQBODY_ERROR" required. [file "/etc/modsecurity/modsecurity.conf"] [line "61"] [id "200002"] [msg "Failed to parse request body."] [data "JSON parser error: parse error: premature EOF\\x0a"] [severity "CRITICAL"] [hostname "example.com"] [uri "/api/v1/logout"] [unique_id "V377qH8AAQEAAB4RU6cAAAAD"]
或者,我应该根本就不是为了得到mod_security的解析发送Content-Type
HTTP标头正文(虽然我宁愿强制执行所有POST请求总是有一个定义Content-Type
)?
我已经完成了正在使用的完整modsecurity.conf的要点(这是一个带有两个额外规则的基本示例,用于过滤内容类型)。
如果您没有内容,则没有内容类型。 –
嗨,但是对于安全来说,确保POST请求始终拥有Content-Type不是最佳做法吗?或者它是“只有内容类型,如果你有身体”情景? – pnairn
mod_security确实进行内容验证。有效的HTTP需要消息体,除非它是100,204或304 HT响应。 https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html –