Apache/ModSecurity - 当 HTML 文本区域包含换行符(输入键)时,是否会阻止它并显示 403?

Apache/ModSecurity - 当 HTML 文本区域包含换行符(输入键)时,是否会阻止它并显示 403?

我有一个联系表格,该联系表格内有一个文本区域。

如果我填写联系表格并在测试区域输入一行文本,例如

Example

表格填写完毕后,我会收到电子邮件通知。但是,如果我在文本区域内执行以下操作:

Example

Example

我得到以下信息:

403 - Forbidden

Forbidden
You don't have permission to access /contact_us.php on this server.

我在 Apache 错误日志中收到此信息:

[Thu Mar 13 08:06:54 2014] [error] [client my.ip.my.ip] ModSecurity: Rule 7fd0751d6280 [id "950901"][file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"][line "77"] - Execution error - PCRE limits exceeded (-8): (null). [hostname "www.test.com"] [uri "/index.php"] [unique_id "UyFK-mAcYdcAACwKBI8AAAAE"]
[Thu Mar 13 08:06:59 2014] [error] [client my.ip.my.ip] ModSecurity: Rule 7fd0751d6280 [id "950901"][file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"][line "77"] - Execution error - PCRE limits exceeded (-8): (null). [hostname "www.test.com"] [uri "/contact_us.php"] [unique_id "UyFLA2AcYdcAACwKBJAAAAAE"]
[Thu Mar 13 08:06:59 2014] [error] [client my.ip.my.ip] ModSecurity: Rule 7fd075bb3940 [id "-"][file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_55_application_defects.conf"][line "27"] - Execution error - PCRE limits exceeded (-8): (null). [hostname "www.test.com"] [uri "/contact_us.php"] [unique_id "UyFLA2AcYdcAACwKBJAAAAAE"]
[Thu Mar 13 08:06:59 2014] [error] [client my.ip.my.ip] ModSecurity: Warning. Match of "rx (?i:(<meta.*?(content|value)=\\"text/html;\\\\s?charset=|<\\\\?xml.*?encoding=))" against "RESPONSE_BODY" required. [file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_55_application_defects.conf"] [line "23"] [id "981220"] [msg "[Watcher Check] No charset was specified in the HTTP Content-Type header nor the HTML content's meta tag."] [data "Content-Type Response Header: text/html"] [tag "WASCTC/WASC-15"] [tag "APP_DEFECT/MISCONFIGURATION"] [tag "http://code.google.com/p/browsersec/wiki/Part2#Content_handling_mechanisms"] [hostname "www.test.com"] [uri "/contact_us.php"] [unique_id "UyFLA2AcYdcAACwKBJAAAAAE"]
[Thu Mar 13 08:06:59 2014] [error] [client my.ip.my.ip] ModSecurity: Rule 7fd074f08b10 [id "-"][file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_55_application_defects.conf"][line "41"] - Execution error - PCRE limits exceeded (-8): (null). [hostname "www.test.com"] [uri "/contact_us.php"] [unique_id "UyFLA2AcYdcAACwKBJAAAAAE"]
[Thu Mar 13 08:06:59 2014] [error] [client my.ip.my.ip] ModSecurity: Warning. Match of "rx (<meta.*?(content|value)=\\"text/html;\\\\s?charset=utf-8|<\\\\?xml.*?encoding=\\"utf-8\\")" against "RESPONSE_BODY" required. [file "/etc/modsecurity/owasp-crs/activated_rules/modsecurity_crs_55_application_defects.conf"] [line "36"] [id "981222"] [msg "[Watcher Check]  The charset specified was not utf-8 in the HTTP Content-Type header nor the HTML content's meta tag."] [data "Content-Type Response Header: text/html"] [tag "WASCTC/WASC-15"] [tag "MISCONFIGURATION"] [tag "http://websecuritytool.codeplex.com/wikipage?title=Checks#charset-not-utf8"] [hostname "www.test.com"] [uri "/contact_us.php"] [unique_id "UyFLA2AcYdcAACwKBJAAAAAE"]

我该如何修复此问题以便表单能够顺利提交?

答案1

您可以通过向 nodsecurity.conf 文件添加SecPcreMatchLimit和语句来调整 PCRE 匹配和递归限制,例如SecPcreMatchLimitRecursion

SecPcreMatchLimit 10000
SecPcreMatchLimitRecursion 10000

但请注意,这可能会引起性能问题,所以不要将其设置得太大。

对于其他错误,modsecurity_crs_55_application_defects.conf您应该阅读文件,然后查看它提供的链接以了解问题并(在本例中)对您的应用程序进行必要的更改。

相关内容