1

关于网络浏览器的基本身份验证,我有点困惑。我原以为 Web 浏览器只会在上一个响应中收到 HTTP 401 状态后才发送 Authorization 标头。但是,Chrome 似乎在此后的每个请求中都发送了 Authorization 标头。它包含我曾经输入的数据,以响应我网站上的 401,并与每条消息一起发送(根据 Chrome 和我的网络服务器附带的开发人员工具)。这是预期的行为吗?是否有一些我应该与我的 401 一起使用的标头来推断授权内容不应该被缓存?我目前正在使用 WWW-Authenticate 标头。

4

2 回答 2

8

这是RFC 2617(第 2 节)中定义的浏览器的预期行为:

A client SHOULD assume that all paths at or deeper than the depth of
the last symbolic element in the path field of the Request-URI also
are within the protection space specified by the Basic realm value of
the current challenge. A client MAY preemptively send the
corresponding Authorization header with requests for resources in
that space without receipt of another challenge from the server.
Similarly, when a client sends a request to a proxy, it may reuse a
userid and password in the Proxy-Authorization header field without
receiving another challenge from the proxy server. See section 4 for
security considerations associated with Basic authentication.

据我所知,基本 HTTP 身份验证无法执行注销/重新身份验证。这与 HTTP 基本身份验证缺乏安全性一起,是大多数网站现在使用表单和 cookie 进行身份验证解决方案的原因。

于 2012-12-24T19:22:31.260 回答
1

来自RFC 2617

如果先前的请求已被授权,则相同的凭证可以在由身份验证方案、参数和/或用户偏好确定的时间段内用于该保护空间内的所有其他请求。

根据我的经验,浏览器会自动为后续请求发送基本凭据是很常见的。它可以避免为额外的资源进行额外的往返。

于 2012-12-24T19:22:07.617 回答