我已經安裝了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 –