删除WWW-Authenticate标头

时间:2017-09-14 13:11:36

标签: apache .htaccess http-authentication

我的apache上有一个页面,我用Basic Auth保护。

使用JavaScript,我想检查浏览器是否有该页面的任何凭据,因此我想通过jQuery ajax调用加载页面,希望获得页面或{{ 1}}错误。 不幸的是,浏览器总是要求我提供后一种情况下的凭据,我不想要 - 我只是想知道我是否需要凭据!

我读过浏览器只询问是否设置了401标头,所以我想要禁止或编辑它,以便浏览器不知道它。

这是我的WWW-Authenticate:(编辑行来自coderwall.com):

.htaccess

这是(部分)我用Authtype Basic AuthName "abcdef" AuthUserFile some/folder/at/the/xampp/.htpasswd Require valid-user Header always add HelloHello "Blupp" Header always edit WWW-Authenticate ^Basic SR_Basic 得到的:

curl -I <url>

您看,HTTP/1.1 401 Unauthorized Date: Thu, 14 Sep 2017 12:48:52 GMT Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.21 WWW-Authenticate: Basic realm="abcdef" Vary: accept-language,accept-charset Accept-Ranges: bytes Content-Type: text/html; charset=utf-8 Content-Language: en 标头未被修改,并且WWW-Authenticate标头尚未应用!当我注释掉前4行(基本身份验证)时,我正确地得到HelloHello

使用行HelloHello: Blupp代替不会改变。

如何修改/删除标题?

2 个答案:

答案 0 :(得分:2)

我追溯到Apache 2.4.25(如Debian 9“stretch”)在mod_auth_basic.c中添加了“WWW-Authenticate”标题(到r-&gt; err_headers_out),然后处理Apache配置“Header”指令不幸的是,mod_headers.c在mod_headers.c中的r-&gt; err_headers_out的不同副本上运行:ap_headers_error_filter()。

在ap_headers_output_filter()中向ap_headers_error_filter()添加第二个do_headers_fixup()以对r-&gt; headers_out进行操作时,问题就消失了。

不确定Apache是​​否将此问题视为错误或功能。

更新:apache.org上的相应问题报告,包括建议的补丁,位于: https://bz.apache.org/bugzilla/show_bug.cgi?id=62025

答案 1 :(得分:1)

这里的问题是Apache模块的加载和处理顺序。

您可以看到运行此命令的模块顺序:

apache2ctl -M

您会看到auth _ * _ module在headers_module之前已加载,因此您无法添加标头或修改现有的标头

Loaded Modules:
...
...
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
...
...
 headers_module (shared)
...
...

查看Apache documentation时,模块的加载顺序由模块自身的源代码确定。