Nginx 模块代码 error_page 指令问题
Nginx Module Code error_page directive problems
我正在利用 ModSecurity WAF 来帮助阻止 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 请求方法 Header。这会导致 WAF 的误报日志报告客户端发送了带有 GET 的 HTTP Body 等,而当他们真正发送了 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 方法 header?
我找到了这些 NGINX 页面指南,但到目前为止还没有真正看到任何切入我想要的东西:
https://www.evanmiller.org/nginx-modules-guide.html
正在寻找任何理解该问题并且可能能够将我的 sudo 代码变成我可以在我的沙箱环境中测试的东西的 NGINX / C 专家。
请注意,我没有取消 NGINX error_page 指令调用的奢侈。所以我确实需要一个解决上述 sudo 代码的方法,我相信。
谢谢!
感谢分享!
我们在开发 Wallarm Nginx 模块时解决了一些类似的问题。
简短的回答是肯定的,这里使用了错误的 Nginx 阶段。原因很简单——这是来自 Apache 的 ModSecurity 端口,其中 Nginx 阶段无关紧要。
我会询问我们的开发团队是否可以帮助打补丁。
可以在这里看到我最终进行的修复:
https://github.com/SpiderLabs/ModSecurity-nginx/pull/204
没有理由重新处理最早阶段的客户请求。这是最简单的方法。我只需要退后一步,考虑这里发生的事情以获得最优雅的解决方案。
我正在利用 ModSecurity WAF 来帮助阻止 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 请求方法 Header。这会导致 WAF 的误报日志报告客户端发送了带有 GET 的 HTTP Body 等,而当他们真正发送了 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 方法 header?
我找到了这些 NGINX 页面指南,但到目前为止还没有真正看到任何切入我想要的东西: https://www.evanmiller.org/nginx-modules-guide.html
正在寻找任何理解该问题并且可能能够将我的 sudo 代码变成我可以在我的沙箱环境中测试的东西的 NGINX / C 专家。
请注意,我没有取消 NGINX error_page 指令调用的奢侈。所以我确实需要一个解决上述 sudo 代码的方法,我相信。
谢谢!
感谢分享! 我们在开发 Wallarm Nginx 模块时解决了一些类似的问题。 简短的回答是肯定的,这里使用了错误的 Nginx 阶段。原因很简单——这是来自 Apache 的 ModSecurity 端口,其中 Nginx 阶段无关紧要。
我会询问我们的开发团队是否可以帮助打补丁。
可以在这里看到我最终进行的修复: https://github.com/SpiderLabs/ModSecurity-nginx/pull/204
没有理由重新处理最早阶段的客户请求。这是最简单的方法。我只需要退后一步,考虑这里发生的事情以获得最优雅的解决方案。