[GH-ISSUE #134] waf_captcha开启后,每次在浏览器刷新首页都需要验证 #102

Closed
opened 2026-03-04 12:18:55 +03:00 by kerem · 6 comments
Owner

Originally created by @aidyou on GitHub (Jan 6, 2024).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/134

下面这个配置,设置后,每次刷新页面(本地开发环境)都会要求CAPTCHA验证,点击后才可以正常访问:

# 主要是下面这行,设置为 off 就不会
waf_captcha on prov=reCAPTCHAv3; 
waf_action cc_deny=CAPTCHA zone=waf:action;

ngx_waf为昨天(2024-01-05)拉取的 current分支 源码在nginx:1.25.3-alpine编译,下面是一些环境及版本信息:

macos 14.2.1
Docker version 24.0.7, build afdd53
nginx 1.25.3
ngx_waf current(2024-01-05拉取)
sodium 1.0.18-RELEASE
ModSecurity v3/master
cjson v1.7.15
uthash v2.3.0

nginx -V:

built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) 
built with OpenSSL 3.1.3 19 Sep 2023 (running with OpenSSL 3.1.4 24 Oct 2023)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -Wformat -Werror=format-security -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common

nginx日志:

192.168.65.1 - - [06/Jan/2024:16:02:49 +0800] "GET / HTTP/1.1" 503 3471 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" "-"
2024/01/06 16:02:49 [alert] 54#54: *1 ngx_waf: [CAPTCHA][CHALLENGE] while logging request, client: 192.168.65.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost", referrer: "http://localhost/"
Originally created by @aidyou on GitHub (Jan 6, 2024). Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/134 下面这个配置,设置后,每次刷新页面(本地开发环境)都会要求CAPTCHA验证,点击后才可以正常访问: ``` # 主要是下面这行,设置为 off 就不会 waf_captcha on prov=reCAPTCHAv3; waf_action cc_deny=CAPTCHA zone=waf:action; ``` `ngx_waf`为昨天(2024-01-05)拉取的 `current`分支 源码在`nginx:1.25.3-alpine`编译,下面是一些环境及版本信息: ``` macos 14.2.1 Docker version 24.0.7, build afdd53 nginx 1.25.3 ngx_waf current(2024-01-05拉取) sodium 1.0.18-RELEASE ModSecurity v3/master cjson v1.7.15 uthash v2.3.0 ``` `nginx -V`: ```nginx version: nginx/1.25.3 built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10) built with OpenSSL 3.1.3 19 Sep 2023 (running with OpenSSL 3.1.4 24 Oct 2023) TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -Wformat -Werror=format-security -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common ``` nginx日志: ``` 192.168.65.1 - - [06/Jan/2024:16:02:49 +0800] "GET / HTTP/1.1" 503 3471 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0" "-" 2024/01/06 16:02:49 [alert] 54#54: *1 ngx_waf: [CAPTCHA][CHALLENGE] while logging request, client: 192.168.65.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost", referrer: "http://localhost/" ```
kerem 2026-03-04 12:18:55 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@ADD-SP commented on GitHub (Jan 6, 2024):

一般来说短时间内重复验证 CAPTCHA 可能是因为 Cookie 被删除,失效,或无法通过验证。

请检查浏览器是否自动删除了 Cookie,如果在执行验证时 Cookie 依然存在(waf_captcha_xxxxx),那可能是因为 Cookie 验证失败,最有可能的情况是 restart 或者 reload Nginx,导致用于验证 Cookie 的随机数变化。

<!-- gh-comment-id:1879615650 --> @ADD-SP commented on GitHub (Jan 6, 2024): 一般来说短时间内重复验证 CAPTCHA 可能是因为 Cookie 被删除,失效,或无法通过验证。 请检查浏览器是否自动删除了 Cookie,如果在执行验证时 Cookie 依然存在(`waf_captcha_xxxxx`),那可能是因为 Cookie 验证失败,最有可能的情况是 `restart` 或者 `reload` Nginx,导致用于验证 Cookie 的随机数变化。
Author
Owner

@aidyou commented on GitHub (Jan 7, 2024):

不是短时间重复。是只要重启 nginx 后进入网站就会导致要验证。如果按您所说的,验证是以 cookie 基础,那么任何一个用户刚进入网站应该不存在waf_captcha_xxx这个 cookie,这意味着所有人只要是第一次进入一定要验证?如果是这样的话,我觉得那么可能不太符合常规

<!-- gh-comment-id:1879904481 --> @aidyou commented on GitHub (Jan 7, 2024): 不是短时间重复。是只要重启 nginx 后进入网站就会导致要验证。如果按您所说的,验证是以 cookie 基础,那么任何一个用户刚进入网站应该不存在`waf_captcha_xxx`这个 cookie,这意味着所有人只要是第一次进入一定要验证?如果是这样的话,我觉得那么可能不太符合常规
Author
Owner

@ADD-SP commented on GitHub (Jan 7, 2024):

不是短时间重复。是只要重启 nginx 后进入网站就会导致要验证。如果按您所说的,验证是以 cookie 基础,那么任何一个用户刚进入网站应该不存在waf_captcha_xxx这个 cookie,这意味着所有人只要是第一次进入一定要验证?如果是这样的话,我觉得那么可能不太符合常规

@insuns 所有人第一次进入一定要验证肯定是不符合常规,这实际上会破坏浏览体验。

所以实践中,对于非无感 CAPTCHA,通常需要前置条件来触发它。比如如果用户从不常用的城市登录,或正在进行敏感操作则使用 CAPTCHA 来进行人机识别,这需要明确 CAPTCHA 对应的业务,结合风控规则进行,这显然已经超出狭义 WAF 的能力范围。

当然我也做了一些缓解的尝试,比如触发访问频率限制时才调用 CAPTCHA,或者访问了黑名单的路径才调用 CAPTCHA,但这不解决根本问题。

因此,如果本项目的提供的 CAPTCHA 无法满足您的业务场景(糟糕的浏览体验,触发不够智能),那确实需要寻找其他的解决方案。

<!-- gh-comment-id:1880004282 --> @ADD-SP commented on GitHub (Jan 7, 2024): > 不是短时间重复。是只要重启 nginx 后进入网站就会导致要验证。如果按您所说的,验证是以 cookie 基础,那么任何一个用户刚进入网站应该不存在`waf_captcha_xxx`这个 cookie,这意味着所有人只要是第一次进入一定要验证?如果是这样的话,我觉得那么可能不太符合常规 @insuns 所有人第一次进入一定要验证肯定是不符合常规,这实际上会破坏浏览体验。 所以实践中,对于非无感 CAPTCHA,通常需要前置条件来触发它。比如如果用户从不常用的城市登录,或正在进行敏感操作则使用 CAPTCHA 来进行人机识别,这需要明确 CAPTCHA 对应的业务,结合风控规则进行,这显然已经超出狭义 WAF 的能力范围。 当然我也做了一些缓解的尝试,比如触发访问频率限制时才调用 CAPTCHA,或者访问了黑名单的路径才调用 CAPTCHA,但这不解决根本问题。 因此,如果本项目的提供的 CAPTCHA 无法满足您的业务场景(糟糕的浏览体验,触发不够智能),那确实需要寻找其他的解决方案。
Author
Owner

@aidyou commented on GitHub (Jan 7, 2024):

@ADD-SP 我是暂时关闭了这个验证码,不然确实影响正常体验。你这个项目非常好的,我没有其他的意思,只是询问下我是不是配置问题。不是配置问题我关掉即可。无论如何你这个项目的性能和功能肯定比我自己代码中检测来的强大,对我来说已经足够了。再次感谢!

<!-- gh-comment-id:1880037944 --> @aidyou commented on GitHub (Jan 7, 2024): @ADD-SP 我是暂时关闭了这个验证码,不然确实影响正常体验。你这个项目非常好的,我没有其他的意思,只是询问下我是不是配置问题。不是配置问题我关掉即可。无论如何你这个项目的性能和功能肯定比我自己代码中检测来的强大,对我来说已经足够了。再次感谢!
Author
Owner

@ADD-SP commented on GitHub (Jan 7, 2024):

@insuns 我也并没有别的意思,只是讨论一下 CAPTCHA 的典型使用场景。实际上从我的理解来看,要正确的使用 CAPTCHA 需要的不是开发人员的个人决策,这实际上是考验团队间协作能力的任务,前端,后端,风控等部门如何正确交流信息才是最重要的。

如果你没什么问题的话就饿可以 close issue 了。

不过其实过段时间我也会手动关掉的,虽然这个项目目前维护活跃度比较低,但对于已经解决的 issue 我还是会时不时关一下的。

<!-- gh-comment-id:1880050511 --> @ADD-SP commented on GitHub (Jan 7, 2024): @insuns 我也并没有别的意思,只是讨论一下 CAPTCHA 的典型使用场景。实际上从我的理解来看,要正确的使用 CAPTCHA 需要的不是开发人员的个人决策,这实际上是考验团队间协作能力的任务,前端,后端,风控等部门如何正确交流信息才是最重要的。 如果你没什么问题的话就饿可以 close issue 了。 不过其实过段时间我也会手动关掉的,虽然这个项目目前维护活跃度比较低,但对于已经解决的 issue 我还是会时不时关一下的。
Author
Owner

@aidyou commented on GitHub (Jan 7, 2024):

抱歉,忘记了关闭了,哈。

再次感谢!

等你rust版本出来了我研究下,c看着太累了😺

<!-- gh-comment-id:1880055952 --> @aidyou commented on GitHub (Jan 7, 2024): 抱歉,忘记了关闭了,哈。 再次感谢! 等你rust版本出来了我研究下,c看着太累了😺
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ngx_waf#102
No description provided.