[BUG] Real time update reporting HTTP 401 error #27

Closed
opened 2026-01-15 11:34:35 +08:00 by yan · 18 comments
Owner

Originally created by @FrankHCY on GitHub (Oct 10, 2019).

Originally assigned to: @kmvan on GitHub.

  • OS: Debian 10.0u1
  • PHP version: 7.3.9

Just updated from version 2.1 to 3.3 but got some errors.
My website has a classic HTTP authentication (provided by nginx) and it was working fine in version 2.1
but in version 3.3 after I input the username and password on browser I can see the main page of the prober loaded but there is an alert saying "errors on gathering information, please refresh the page" (I am using simplified chinese so the english version may be different) and real time updating is not working. I checked dev tools of my browser and it says your /?action=fetch encounters a HTTP 401 error (authentication error). It was working fine in version 2.1 so I suppose this is a problem of the new version. Thank you for your work.

Originally created by @FrankHCY on GitHub (Oct 10, 2019). Originally assigned to: @kmvan on GitHub. - OS: Debian 10.0u1 - PHP version: 7.3.9 Just updated from version 2.1 to 3.3 but got some errors. My website has a classic HTTP authentication (provided by nginx) and it was working fine in version 2.1 but in version 3.3 after I input the username and password on browser I can see the main page of the prober loaded but there is an alert saying "errors on gathering information, please refresh the page" (I am using simplified chinese so the english version may be different) and real time updating is not working. I checked dev tools of my browser and it says your /?action=fetch encounters a HTTP 401 error (authentication error). It was working fine in version 2.1 so I suppose this is a problem of the new version. Thank you for your work.
yan added the bug label 2026-01-15 11:34:35 +08:00
yan closed this issue 2026-01-15 11:34:36 +08:00
Author
Owner

@kmvan commented on GitHub (Oct 10, 2019):

猜测因为3.0版本开始使用了restful api,fetch 请求是无状态的,不带cookies额外header,所以导致了与展示页面的cookie不一致,从而fetch请求不被nginx认可的问题发生。

这个问题的解决可以直接在fetch中加上cookies额外header,但这样会导致不够“纯API”。如果我找不到更好的解决方法,就会在下个版本使用该方法来解决。

更好的方法近期我会去研究研究。

@kmvan commented on GitHub (Oct 10, 2019): 猜测因为3.0版本开始使用了restful api,fetch 请求是无状态的,不带<del>cookies</del>额外header,所以导致了与展示页面的cookie不一致,从而fetch请求不被nginx认可的问题发生。 这个问题的解决可以直接在fetch中加上<del>cookies</del>额外header,但这样会导致不够“纯API”。如果我找不到更好的解决方法,就会在下个版本使用该方法来解决。 更好的方法近期我会去研究研究。
Author
Owner

@kmvan commented on GitHub (Oct 10, 2019):

能贴一下你的nginx http身份验证配置吗?

@kmvan commented on GitHub (Oct 10, 2019): 能贴一下你的nginx http身份验证配置吗?
Author
Owner

@FrankHCY commented on GitHub (Oct 10, 2019):

感谢回复!
nginx site 配置(在server块里):

auth_basic "Admin Only";
auth_basic_user_file /etc/nginx/.htpasswd;

.htpasswd 文件:
<用户名>:$apr1$<密码阿帕奇散列>

就是那种最简单的http验证

@FrankHCY commented on GitHub (Oct 10, 2019): 感谢回复! nginx site 配置(在`server`块里): ``` auth_basic "Admin Only"; auth_basic_user_file /etc/nginx/.htpasswd; ``` .htpasswd 文件: `<用户名>:$apr1$<密码阿帕奇散列>` 就是那种最简单的http验证
Author
Owner

@kmvan commented on GitHub (Oct 10, 2019):

感谢回复!
nginx site 配置(在server块里):

auth_basic "Admin Only";
auth_basic_user_file /etc/nginx/.htpasswd;

.htpasswd 文件:
<用户名>:$apr1$<密码阿帕奇散列>

就是那种最简单的http验证

有一个思路,就是对url参数进行判断。使用了 ?action= 参数就不进行验证

if ($args ~ action=(fetch|latest-php-version)) {
    set $auth_basic off;
}

if ($args !~ action=(fetch|latest-php-version)) {
    set $auth_basic "Admin Only";
}

auth_basic_user_file /etc/nginx/.htpasswd;
auth_basic $auth_basic;

这样的话,访问探针页面,不带action的,就需要验证,带action参数的就不需要。虽然多了几行判断,但这样至少能保持探针请求的纯净性和安全性。当然具体的判断规则,也可以自行更加深入优化。

@kmvan commented on GitHub (Oct 10, 2019): > 感谢回复! > nginx site 配置(在`server`块里): > > ``` > auth_basic "Admin Only"; > auth_basic_user_file /etc/nginx/.htpasswd; > ``` > > .htpasswd 文件: > `<用户名>:$apr1$<密码阿帕奇散列>` > > 就是那种最简单的http验证 有一个思路,就是对url参数进行判断。使用了 ?action= 参数就不进行验证 ```javascript if ($args ~ action=(fetch|latest-php-version)) { set $auth_basic off; } if ($args !~ action=(fetch|latest-php-version)) { set $auth_basic "Admin Only"; } auth_basic_user_file /etc/nginx/.htpasswd; auth_basic $auth_basic; ``` 这样的话,访问探针页面,不带action的,就需要验证,带action参数的就不需要。虽然多了几行判断,但这样至少能保持探针请求的纯净性和安全性。当然具体的判断规则,也可以自行更加深入优化。
Author
Owner

@loveyu commented on GitHub (Nov 17, 2019):

遇到了同样的问题。nginx下启动了http身份认证

@loveyu commented on GitHub (Nov 17, 2019): 遇到了同样的问题。nginx下启动了http身份认证
Author
Owner

@kmvan commented on GitHub (Nov 17, 2019):

遇到了同样的问题。nginx下启动了http身份认证

试试 https://github.com/kmvan/x-prober/issues/45#issuecomment-540542011

@kmvan commented on GitHub (Nov 17, 2019): > 遇到了同样的问题。nginx下启动了http身份认证 试试 https://github.com/kmvan/x-prober/issues/45#issuecomment-540542011
Author
Owner

@loveyu commented on GitHub (Nov 17, 2019):

遇到了同样的问题。nginx下启动了http身份认证

试试 #45 (comment)

我知道这个方案可以解决问题,但问题是我并不想取消这个认证

@loveyu commented on GitHub (Nov 17, 2019): > > 遇到了同样的问题。nginx下启动了http身份认证 > > 试试 [#45 (comment)](https://github.com/kmvan/x-prober/issues/45#issuecomment-540542011) 我知道这个方案可以解决问题,但问题是我并不想取消这个认证
Author
Owner

@kmvan commented on GitHub (Nov 18, 2019):

遇到了同样的问题。nginx下启动了http身份认证

试试 #45 (comment)

我知道这个方案可以解决问题,但问题是我并不想取消这个认证

不是连界面都取消,是取消 fetch 获取信息的部分而已。

@kmvan commented on GitHub (Nov 18, 2019): > > > 遇到了同样的问题。nginx下启动了http身份认证 > > > > > > 试试 [#45 (comment)](https://github.com/kmvan/x-prober/issues/45#issuecomment-540542011) > > 我知道这个方案可以解决问题,但问题是我并不想取消这个认证 不是连界面都取消,是取消 fetch 获取信息的部分而已。
Author
Owner

@loveyu commented on GitHub (Nov 19, 2019):

遇到了同样的问题。nginx下启动了http身份认证

试试 #45 (comment)

我知道这个方案可以解决问题,但问题是我并不想取消这个认证

不是连界面都取消,是取消 fetch 获取信息的部分而已。

理解你说的意思,我只是单纯的不想去改服务器的配置而已,我主要看看基本信息而已。

@loveyu commented on GitHub (Nov 19, 2019): > > > > 遇到了同样的问题。nginx下启动了http身份认证 > > > > > > > > > 试试 [#45 (comment)](https://github.com/kmvan/x-prober/issues/45#issuecomment-540542011) > > > > > > 我知道这个方案可以解决问题,但问题是我并不想取消这个认证 > > 不是连界面都取消,是取消 fetch 获取信息的部分而已。 理解你说的意思,我只是单纯的不想去改服务器的配置而已,我主要看看基本信息而已。
Author
Owner

@FrankHCY commented on GitHub (Nov 19, 2019):

我很理解作者的想法 我也是程序员我也是这样的 程序的风格还是很重要的
我也理解取消fetch的认证可以解决问题 但是我这个服务器里还有其他东西 如果每个链接跟个?fetch就能访问了,我这个认证也就失去意义了
当然我也可以只设置探针url跟?fetch可以访问 但这样子的话还是会把一部分的信息暴露出去 还是违背了我设置认证的初衷 说白了就是 我把全站的authentication全去掉了岂不是用着更方便
而且开这种口子可能会有一些脑子一下想不到的bug 还是少开为好
我现在降级到v2的最新版了 还是非常感谢你的探针 用起来不错

@FrankHCY commented on GitHub (Nov 19, 2019): 我很理解作者的想法 我也是程序员我也是这样的 程序的风格还是很重要的 我也理解取消fetch的认证可以解决问题 但是我这个服务器里还有其他东西 如果每个链接跟个?fetch就能访问了,我这个认证也就失去意义了 当然我也可以只设置探针url跟?fetch可以访问 但这样子的话还是会把一部分的信息暴露出去 还是违背了我设置认证的初衷 说白了就是 我把全站的authentication全去掉了岂不是用着更方便 而且开这种口子可能会有一些脑子一下想不到的bug 还是少开为好 我现在降级到v2的最新版了 还是非常感谢你的探针 用起来不错
Author
Owner

@kmvan commented on GitHub (Nov 19, 2019):

主要是我还没想到如何获取 header request 的值,里面包含的 auth 的信息,只要能获取这个,不管从 PHP 或 JS,就能传递给 fetch 接口。

@kmvan commented on GitHub (Nov 19, 2019): 主要是我还没想到如何获取 header request 的值,里面包含的 auth 的信息,只要能获取这个,不管从 PHP 或 JS,就能传递给 fetch 接口。
Author
Owner

@kmvan commented on GitHub (Nov 19, 2019):

或者会考虑加一个配置文件php,里面能设置密码或相关的信息(多点服务器等等)

@kmvan commented on GitHub (Nov 19, 2019): 或者会考虑加一个配置文件php,里面能设置密码或相关的信息(多点服务器等等)
Author
Owner

@kmvan commented on GitHub (Nov 19, 2019):

貌似突然想到解决方法了,下个版本见证奇迹

@kmvan commented on GitHub (Nov 19, 2019): 貌似突然想到解决方法了,下个版本见证奇迹
Author
Owner

@kmvan commented on GitHub (Nov 20, 2019):

两位试试 3.5 版本?

@kmvan commented on GitHub (Nov 20, 2019): 两位试试 3.5 版本?
Author
Owner

@loveyu commented on GitHub (Nov 20, 2019):

两位试试 3.5 版本?

可以了,不过自动更新失败,只能手动更新

@loveyu commented on GitHub (Nov 20, 2019): > 两位试试 3.5 版本? 可以了,不过自动更新失败,只能手动更新
Author
Owner

@kmvan commented on GitHub (Nov 20, 2019):

肯定的,从3.5开始才兼容 authorization。

@kmvan commented on GitHub (Nov 20, 2019): 肯定的,从3.5开始才兼容 authorization。
Author
Owner

@FrankHCY commented on GitHub (Nov 20, 2019):

非常感谢 但php-latest-version 返回404不知道是哪的问题

@FrankHCY commented on GitHub (Nov 20, 2019): 非常感谢 但php-latest-version 返回404不知道是哪的问题
Author
Owner

@kmvan commented on GitHub (Nov 20, 2019):

非常感谢 但php-latest-version 返回404不知道是哪的问题

正常,因为是最新版php,所以找不到比它更新的版本,就404

@kmvan commented on GitHub (Nov 20, 2019): > 非常感谢 但php-latest-version 返回404不知道是哪的问题 正常,因为是最新版php,所以找不到比它更新的版本,就404
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yan/archived-x-prober#27