Nginx模块代码error_page指令问题

时间:2020-05-14 19:29:43

标签: c nginx mod-security nginx-module

我正在利用ModSecurity WAF帮助阻止tx在NGINX上的危险: https://github.com/SpiderLabs/ModSecurity https://github.com/SpiderLabs/ModSecurity-nginx

我的问题可以在这里找到: https://github.com/SpiderLabs/ModSecurity-nginx/issues/182

我遇到的问题的TLDR是nginx error_page伪指令,它重置由始发客户端重定向到GET期间发送的HTTP请求方法标头。这会导致WAF误报日志,以报告客户端使用GET等方式发送了HTTP正文。当客户端确实发送了POST时,由于某些情况,NGINX命中了error_page重定向,而上游代理在反向代理调用上超时了。

要解决此问题,我似乎需要在此文件部分中侵入或PR某些内容: https://github.com/SpiderLabs/ModSecurity-nginx/blob/master/src/ngx_http_modsecurity_rewrite.c#L145

以sudo代码中的类似目标为目标:

//SAFE to trust this value as its the originating client HTTP REQUEST Method HEADER when not error_page
if(!r->error_page){
   const char *n_method = ngx_str_to_char(r->method_name, r->pool);
  //HOW to add a transaction persistent context value here to store STORED_CTX_HTTP_REQUEST_METHOD_HEADER_VALUE???
}
else {  //IF ERROR_PAGE, then we need to grab the original stored CTX request http method header value.
  const char *n_method = ngx_str_to_char(STORED_CTX_HTTP_REQUEST_METHOD_HEADER_VALUE); 
}

在这里,我无法解决上面的sudo代码。如何在这里创建一个tx上下文安全变量,该变量可以在各个阶段持续存在,并且内部error_page重定向以存储原始客户端http方法标头?

我登陆了这些NGINX页面指南,但是到目前为止,还没有任何骰子真正看到任何切入我想要的东西: https://www.evanmiller.org/nginx-modules-guide.html

寻找任何了解该问题的NGINX / C专家,也许可以将sudo代码转换为可以在沙盒环境中测试的东西。

请注意,我无法摆脱NGINX error_page指令调用。因此,我确实需要解决我相信的上述sudo代码的方法。

谢谢!

2 个答案:

答案 0 :(得分:1)

我最终得到的修复可以在这里看到: https://github.com/SpiderLabs/ModSecurity-nginx/pull/204

没有理由在最早阶段重新处理客户请求。这是最简单的方法。我只需要退后一步,考虑一下这里发生的事情,这是最优雅的解决方案。

答案 1 :(得分:0)

感谢分享! 我们在开发Wallarm Nginx模块时解决了一些类似的问题。 简短的答案是肯定的,这里使用了错误的Nginx阶段。原因很简单-这是Apache的ModSecurity端口,与Nginx阶段无关。

我会问我们的开发团队是否可以提供补丁帮助。