Skip to content

Truly independent web browser

LibWeb: Prepare callback settings when processing fetch responses

Andreas Kling84a273cf57f5
diff --git a/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Libraries/LibWeb/Fetch/FetchMethod.cpp
index 75d74858155..1fcbcdc88ad 100644
--- a/Libraries/LibWeb/Fetch/FetchMethod.cpp
+++ b/Libraries/LibWeb/Fetch/FetchMethod.cpp
@@ -128,8 +128,8 @@ GC::Ref<WebIDL::Promise> fetch(JS::Realm& realm, RequestInfo const& input, Bindi
if (locally_aborted->value())
return;
- // AD-HOC: An execution context is required for Promise functions.
- HTML::TemporaryExecutionContext execution_context { relevant_realm };
+ // AD-HOC: Promise reactions need an execution context and incumbent callback settings.
+ HTML::TemporaryExecutionContext execution_context { relevant_realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
// 2. If response’s aborted flag is set, then:
if (response->aborted()) {
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index c61f4765ff1..722bfd5087e 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -307,6 +307,9 @@ Text/input/HTML/canvas-toDataURL-toBlob-origin-clean.html
; Tests cross-origin Resource Timing.
Text/input/Fetch/cross-origin-resource-timing-duration.html
+; Authentication challenges need same-origin credentials.
+Text/input/Fetch/post-auth-challenge-abort.html
+
; URL credentials are only sent on same-origin requests.
Text/input/Fetch/url-credentials-authorization-header.html
Text/input/Fetch/url-credentials-preserve-arbitrary-bytes.html
diff --git a/Tests/LibWeb/Text/expected/Fetch/post-auth-challenge-abort.txt b/Tests/LibWeb/Text/expected/Fetch/post-auth-challenge-abort.txt
new file mode 100644
index 00000000000..d4ab45a9393
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Fetch/post-auth-challenge-abort.txt
@@ -0,0 +1,3 @@
+GET challenge: AbortError
+POST challenge: AbortError
+POST control: 200, ordinary response
diff --git a/Tests/LibWeb/Text/input/Fetch/post-auth-challenge-abort.html b/Tests/LibWeb/Text/input/Fetch/post-auth-challenge-abort.html
new file mode 100644
index 00000000000..e0d62328eab
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Fetch/post-auth-challenge-abort.html
@@ -0,0 +1,34 @@
+<!doctype html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ const server = httpTestServer();
+ const body = "replayable-body";
+
+ async function challenge(method) {
+ const url = await server.createEcho(method, `/post-auth-challenge-abort-${method}`, {
+ status: 401,
+ headers: { "WWW-Authenticate": 'Basic realm="post-auth-challenge-abort"' },
+ });
+ try {
+ const response = await fetch(url, { method, ...(method === "POST" ? { body } : {}) });
+ println(`${method} challenge: status ${response.status}`);
+ } catch (error) {
+ println(`${method} challenge: ${error.name}`);
+ }
+ }
+
+ // The GET control has no request body to cancel.
+ await challenge("GET");
+ // The POST challenge aborts while its JS Request still owns a readable body stream.
+ await challenge("POST");
+
+ const url = await server.createEcho("POST", "/post-auth-challenge-abort-control", {
+ status: 200,
+ headers: { "Content-Type": "text/plain" },
+ body: "ordinary response",
+ });
+ const response = await fetch(url, { method: "POST", body });
+ println(`POST control: ${response.status}, ${await response.text()}`);
+ });
+</script>