ModSecurity 2.7.1是否可以与ASP.NET MVC 3一起使用?

我试图让ModSecurity 2.7.1与ASP.NET MVC 3网站一起工作。 安装运行没有错误,并查看事件日志,ModSecurity成功启动。 我正在使用modsecurity.conf-recommended文件来设置基本规则。

我遇到的问题是,每当我张贴一些表单数据,它不会通过控制器操作(或模型联编程序)。

我有SecRuleEngine设置为DetectionOnly

我有SecRequestBodyAccess设置为On

使用这些设置,POST的主体永远不会到达控制器操作。 如果我将SecRequestBodyAccess设置为Off它就可以工作,所以这肯定是ModSecurity转发正文数据的方法。 ModSecuritydebugging显示以下内容(看起来好像全部通过):

 Second phase starting (dcfg 94b750). Input filter: Reading request body. Adding request argument (BODY): name "[0].IsSelected", value "on" Adding request argument (BODY): name "[0].Quantity", value "1" Adding request argument (BODY): name "[0].VariantSku", value "047861" Adding request argument (BODY): name "[1].Quantity", value "0" Adding request argument (BODY): name "[1].VariantSku", value "047862" Input filter: Completed receiving request body (length 115). Starting phase REQUEST_BODY. Recipe: Invoking rule 94c620; [file "*********************"] [line "54"] [id "200001"]. Rule 94c620: SecRule "REQBODY_ERROR" "!@eq 0" "phase:2,auditlog,id:200001,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:%{reqbody_error_msg},severity:2" Transformation completed in 0 usec. Executing operator "!eq" with param "0" against REQBODY_ERROR. Operator completed in 0 usec. Rule returned 0. Recipe: Invoking rule 5549c38; [file "*********************"] [line "75"] [id "200002"]. Rule 5549c38: SecRule "MULTIPART_STRICT_ERROR" "!@eq 0" "phase:2,auditlog,id:200002,t:none,log,deny,status:44,msg:'Multipart request body failed strict validation: PE %{REQBODY_PROCESSOR_ERROR}, BQ %{MULTIPART_BOUNDARY_QUOTED}, BW %{MULTIPART_BOUNDARY_WHITESPACE}, DB %{MULTIPART_DATA_BEFORE}, DA %{MULTIPART_DATA_AFTER}, HF %{MULTIPART_HEADER_FOLDING}, LF %{MULTIPART_LF_LINE}, SM %{MULTIPART_MISSING_SEMICOLON}, IQ %{MULTIPART_INVALID_QUOTING}, IP %{MULTIPART_INVALID_PART}, IH %{MULTIPART_INVALID_HEADER_FOLDING}, FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'" Transformation completed in 0 usec. Executing operator "!eq" with param "0" against MULTIPART_STRICT_ERROR. Operator completed in 0 usec. Rule returned 0. Recipe: Invoking rule 554bd70; [file "********************"] [line "80"] [id "200003"]. Rule 554bd70: SecRule "MULTIPART_UNMATCHED_BOUNDARY" "!@eq 0" "phase:2,auditlog,id:200003,t:none,log,deny,status:44,msg:'Multipart parser detected a possible unmatched boundary.'" Transformation completed in 0 usec. Executing operator "!eq" with param "0" against MULTIPART_UNMATCHED_BOUNDARY. Operator completed in 0 usec. Rule returned 0. Recipe: Invoking rule 554cbe0; [file "*********************************"] [line "94"] [id "200004"]. Rule 554cbe0: SecRule "TX:/^MSC_/" "!@streq 0" "phase:2,log,auditlog,id:200004,t:none,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'" Rule returned 0. Hook insert_filter: Adding input forwarding filter (r 5541fc0). Hook insert_filter: Adding output filter (r 5541fc0). Initialising logging. Starting phase LOGGING. Recording persistent data took 0 microseconds. Audit log: Ignoring a non-relevant request. 

我在小提琴手里看不到什么不寻常的东西。 我在我的动作参数中使用ViewModel 。 如果SecRequestBodyAccess设置为On SecRequestBodyAccess绑定任何数据。 我甚至logging所有的Request.Form.Keys和值通过log4net,但没有得到任何值。

我开始怀疑ModSecurity实际上是否适用于ASP.NET MVC,或者是否与ModSecurity http模块和模型绑定器有冲突。

有没有人有任何build议,或任何人都可以确认他们ModSecurity与ASP.NET MVC网站工作?

我提交了一个关于这个问题的bug报告,现在已经在modsecurity 2.7.2中修复了。 https://www.modsecurity.org/tracker/browse/MODSEC-371

所以,我晚了几年,但我现在正在通过类似的问题,并认为我会分享我发现的。

这不是一个真正的MVC问题。 这可能是一个IIS的问题,虽然类似的东西似乎影响NGINX(基于这个: https : //github.com/SpiderLabs/ModSecurity/issues/664 )它似乎仍然是ModSecurity版本中的一个问题通过Web Platform Installer实用程序安装,Azure AppService中自动提供的版本,所以如果有可用的补丁,可能没有广泛部署。

基于( https://github.com/SpiderLabs/ModSecurity/issues/562 ),我一直在设置:

 SecStreamInBodyInspection On 

虽然我没有发现任何明确的迹象, 为什么允许POST机构通过 这有点令人不安,因为我也不确定可能会有什么缺点,但是这个魔法似乎有效。

有趣的是,ModSecurity的OWASP CRS规则设置了SecRequestBodyInspection而不是SecStreamInBodyInspection,这向我build议,这个bug不会影响所有主机,但绝对是IIS用户的陷阱。

HTH