Truly independent web browser
LibWeb: Ignore XMLHttpRequest upload progress after the upload completed
Shannon Boothd2f01214d084
diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cppindex 1efe0c386f1..fc0b68e57c2 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp@@ -872,6 +872,12 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB// NOTE: request_body_length is captured by copy as to not UAF it when we leave `send()` and the callback gets called.// NOTE: `this` is kept alive by FetchAlgorithms using GC::HeapFunction.auto process_request_body_chunk_length = [this, request_body_length](u64 bytes_length) {+ // AD-HOC: Fetch transmits the body again for each redirect, and runs process request end-of-body for a+ // null body, so ignore everything after the upload completed.+ // Spec issue: https://github.com/whatwg/xhr/issues/242+ if (m_upload_complete)+ return;+// 1. Increase requestBodyTransmitted by bytesLength.m_request_body_transmitted += bytes_length;@@ -892,6 +898,12 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB// NOTE: request_body_length is captured by copy as to not UAF it when we leave `send()` and the callback gets called.// NOTE: `this` is kept alive by FetchAlgorithms using GC::HeapFunction.auto process_request_end_of_body = [this, request_body_length]() {+ // AD-HOC: Fetch transmits the body again for each redirect, and runs process request end-of-body for a+ // null body, so ignore everything after the upload completed.+ // Spec issue: https://github.com/whatwg/xhr/issues/242+ if (m_upload_complete)+ return;+// 1. Set this’s upload complete flag.m_upload_complete = true;diff --git a/Tests/LibWeb/Text/expected/wpt-import/xhr/send-redirect-post-upload.txt b/Tests/LibWeb/Text/expected/wpt-import/xhr/send-redirect-post-upload.txtindex 6ff8279fbf4..b868e585478 100644--- a/Tests/LibWeb/Text/expected/wpt-import/xhr/send-redirect-post-upload.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/xhr/send-redirect-post-upload.txt@@ -2,9 +2,9 @@ Harness status: OKFound 5 tests-5 Fail-Fail XMLHttpRequest: The send() method: POSTing to URL that redirects (301)-Fail XMLHttpRequest: The send() method: POSTing to URL that redirects (302)-Fail XMLHttpRequest: The send() method: POSTing to URL that redirects (303)-Fail XMLHttpRequest: The send() method: POSTing to URL that redirects (307 (string))-Fail XMLHttpRequest: The send() method: POSTing to URL that redirects (307 (blob))\ No newline at end of file+5 Pass+Pass XMLHttpRequest: The send() method: POSTing to URL that redirects (301)+Pass XMLHttpRequest: The send() method: POSTing to URL that redirects (302)+Pass XMLHttpRequest: The send() method: POSTing to URL that redirects (303)+Pass XMLHttpRequest: The send() method: POSTing to URL that redirects (307 (string))+Pass XMLHttpRequest: The send() method: POSTing to URL that redirects (307 (blob))\ No newline at end of file