nginx - ModSecurity 子请求白名单

标签 nginx nginx-reverse-proxy mod-security2

我有带有 ModSecurity 的 Nginx 和 OWASP CRS 设置,用作几个不同 Web 服务器的反向代理。我正在使用 add_after_body/gdprmessage.html; 将 GDPR 接受附加到每个页面。一切都运行得很好,但偶尔在 POST 请求中,生成的页面会呈现丑陋的 403 错误,而不是我的 GDPR 消息。我在日志中收到此消息:

2020/07/24 22:42:42 [error] 19576#0: *1664601 [client 10.0.0.10] ModSecurity: Access denied with code 403 (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/etc/nginx/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "80"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver "OWASP_CRS/3.2.0"] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "10.0.0.2"] [uri "/wp-login.php"] [unique_id "159562336247.351441"] [ref ""], client: 10.0.0.10, server: test.com, request: "POST /wp-login.php HTTP/1.1", subrequest: "/gdprmessage.html", host: "www.test.com", referrer: "https://www.test.com/wp-login.php"

登录页面内容呈现良好,但 GDPR 子请求却不然。我尝试通过将以下内容添加到我的 ModSec 规则中来解决此问题:

SecRule REQUEST_URI "/gdprmessage.html" "id:33000,phase:1,nolog,allow,ctl:ruleRemoveById=949110"

这不起作用,所以我尝试使用以下方法将请求完全列入白名单:

SecRule REQUEST_URI "/gdprmessage.html" "id:33000,phase:1,log,allow,ctl:ruleEngine=Off"

这也不起作用。我推断 REQUEST_URI 可能只有原始请求,所以我测试了:

SecRule REQUEST_URI "/wp-login.php" "id:33000,phase:1,log,allow,ctl:ruleEngine=Off"

这“有效”,但不是解决方案。我查看了 https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual-%28v2.x%29#Variables 上的所有变量可用于 SecRule,但没有看到任何可以提供“子请求”值的内容。

有没有办法可以将我的 /gdprmessage.html 子请求列入白名单,而将 CRS 留给请求本身?

最佳答案

我试图通过 ModSecurity 异常来解决问题。事实证明,答案只是将 modsecurity off 添加到该位置。

如果对其他人有帮助,请参阅我的 GDPR 代码段,其中包含在我的网站定义中:

add_after_body /gdprmessage.html;

location = /gdprmessage.html {
    root /etc/nginx/snippets/;
    modsecurity off;

    if ($http_x_requested_with = XMLHttpRequest) {
        return 200;
    }
}

测试 XMLHttpRequests 确保我的 GDPR 消息不会附加到 ajax 查询中。

关于nginx - ModSecurity 子请求白名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63084317/

相关文章:

ubuntu - 子域的通配符证书?

nginx - 将请求 header 变量作为查询参数传递给上游 URL

nginx反向代理禁用缓存

wordpress - WordPress 的 mod_security2 规则

php - url 作为参数的 Mod-安全异常(exception)规则

Nginx 为 prestashop 重写规则,如何设置、调试和启用?

linux - nginx 将所有页面 301 重定向到另一个域/主页添加查询字符串

php - Nginx Docker容器(作为Laradock的一部分)返回 'ERR_CONNECTION_CLOSED'

基于响应的 Nginx 上游重试

php - 带连字符的 GET 引发错误 403