Skip to content

Commit b3a848a

Browse files
committed
LibWeb: Ensure WWW-Authenticate header is present during fetch
If the HTTP 401 response we get does not contain a `WWW-Authenticate` header, we should not trigger the logic to ask the user for credentials and retry the request. This part is hinted at in a TODO / 'Needs testing' remark in the spec but needs to be fleshes out. Raised an upstream issue to do so: whatwg/fetch#1766 This fixes login forms triggering an infinite fetch loop when providing incorrect credentials.
1 parent d755a83 commit b3a848a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
19871987
if (response->status() == 401
19881988
&& http_request->response_tainting() != Infrastructure::Request::ResponseTainting::CORS
19891989
&& include_credentials == IncludeCredentials::Yes
1990-
&& request->window().has<JS::GCPtr<HTML::EnvironmentSettingsObject>>()) {
1990+
&& request->window().has<JS::GCPtr<HTML::EnvironmentSettingsObject>>()
1991+
// AD-HOC: Require at least one WWW-Authenticate header to be set before automatically retrying an authenticated
1992+
// request (see rule 1 below). See: https://github.com/whatwg/fetch/issues/1766
1993+
&& request->header_list()->contains("WWW-Authenticate"sv.bytes())) {
19911994
// 1. Needs testing: multiple `WWW-Authenticate` headers, missing, parsing issues.
19921995
// (Red box in the spec, no-op)
19931996

0 commit comments

Comments
 (0)