Commit 75c79e5a authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Set request mode for beacon request with non-cors-safelisted blob

I removed the restriction on beacon with a blob with a non-CORS
safelisted content type at https://crrev.com/c/2011786 but forgot to
set the request mode. Fix that.

Bug: 1051368
Change-Id: Ibb843c2232af09390ca1155bd8a807c453c61683
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050410Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740611}
parent 21a5fb93
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/html/forms/form_data.h" #include "third_party/blink/renderer/core/html/forms/form_data.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/platform/loader/cors/cors.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h"
...@@ -110,8 +111,12 @@ class BeaconBlob final : public Beacon { ...@@ -110,8 +111,12 @@ class BeaconBlob final : public Beacon {
request.SetHttpBody(std::move(entity_body)); request.SetHttpBody(std::move(entity_body));
if (!content_type_.IsEmpty()) if (!content_type_.IsEmpty()) {
if (!cors::IsCorsSafelistedContentType(content_type_)) {
request.SetMode(network::mojom::blink::RequestMode::kCors);
}
request.SetHTTPContentType(content_type_); request.SetHTTPContentType(content_type_);
}
} }
const AtomicString GetContentType() const override { return content_type_; } const AtomicString GetContentType() const override { return content_type_; }
......
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js
promise_test(async (test) => {
const sid = token();
const tid = token();
const origin = get_host_info().REMOTE_ORIGIN;
const store =
`${origin}/beacon/resources/beacon.py?cmd=store&sid=${sid}&tid=${tid}&tidx=0`;
const monitor =
`/beacon/resources/beacon.py?cmd=stat&sid=${sid}&tidx_min=0&tidx_max=0`;
assert_true(navigator.sendBeacon(store, new Blob([], {type: 'x/y'})));
let actual;
for (let i = 0; i < 30; ++i) {
await new Promise(resolve => test.step_timeout(resolve, 10));
const response = await fetch(monitor);
const obj = await response.json();
if (obj.length > 0) {
actual = JSON.stringify(obj);
break;
}
}
const expected =
JSON.stringify([{id: tid, error: 'Preflight not expected.'}]);
assert_equals(actual, expected);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment