mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibWeb: Add Web Worker Origin Inheritance
Fetch requests from web workers fail CORS checks because the origin is not inherited from the outside settings. Ensure web worker origin is correctly inherited from outside settings
This commit is contained in:
parent
176e3ba16a
commit
24adb1c452
Notes:
sideshowbarker
2024-07-16 20:39:14 +09:00
Author: https://github.com/braydnm 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/24adb1c452 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/408 Issue: https://github.com/LadybirdBrowser/ladybird/issues/189 Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 18 additions and 5 deletions
|
@ -7,15 +7,20 @@
|
||||||
|
|
||||||
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
|
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
|
||||||
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
||||||
|
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
|
||||||
|
#include <WebWorker/DedicatedWorkerHost.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
JS_DEFINE_ALLOCATOR(WorkerEnvironmentSettingsObject);
|
JS_DEFINE_ALLOCATOR(WorkerEnvironmentSettingsObject);
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/workers.html#set-up-a-worker-environment-settings-object
|
// https://html.spec.whatwg.org/multipage/workers.html#set-up-a-worker-environment-settings-object
|
||||||
JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObject::setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */)
|
JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObject::setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time)
|
||||||
{
|
{
|
||||||
// 1. FIXME: Let inherited origin be outside settings's origin.
|
(void)unsafe_worker_creation_time;
|
||||||
|
|
||||||
|
// 1. Let inherited origin be outside settings's origin.
|
||||||
|
auto inherited_origin = outside_settings.origin;
|
||||||
|
|
||||||
// 2. Let realm be the value of execution context's Realm component.
|
// 2. Let realm be the value of execution context's Realm component.
|
||||||
auto realm = execution_context->realm;
|
auto realm = execution_context->realm;
|
||||||
|
@ -28,9 +33,13 @@ JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObjec
|
||||||
// NOTE: See the functions defined for this class.
|
// NOTE: See the functions defined for this class.
|
||||||
auto settings_object = realm->heap().allocate<WorkerEnvironmentSettingsObject>(*realm, move(execution_context), worker);
|
auto settings_object = realm->heap().allocate<WorkerEnvironmentSettingsObject>(*realm, move(execution_context), worker);
|
||||||
settings_object->target_browsing_context = nullptr;
|
settings_object->target_browsing_context = nullptr;
|
||||||
|
settings_object->m_origin = move(inherited_origin);
|
||||||
|
|
||||||
// FIXME: 5. Set settings object's id to a new unique opaque string, creation URL to worker global scope's url, top-level creation URL to null, target browsing context to null, and active service worker to null.
|
// FIXME: 5. Set settings object's id to a new unique opaque string, creation URL to worker global scope's url, top-level creation URL to null, target browsing context to null, and active service worker to null.
|
||||||
// FIXME: 6. If worker global scope is a DedicatedWorkerGlobalScope object, then set settings object's top-level origin to outside settings's top-level origin.
|
// 6. If worker global scope is a DedicatedWorkerGlobalScope object, then set settings object's top-level origin to outside settings's top-level origin.
|
||||||
|
if (is<WebWorker::DedicatedWorkerHost>(worker)) {
|
||||||
|
settings_object->top_level_origin = outside_settings.top_level_origin;
|
||||||
|
}
|
||||||
// FIXME: 7. Otherwise, set settings object's top-level origin to an implementation-defined value.
|
// FIXME: 7. Otherwise, set settings object's top-level origin to an implementation-defined value.
|
||||||
|
|
||||||
// 8. Set realm's [[HostDefined]] field to settings object.
|
// 8. Set realm's [[HostDefined]] field to settings object.
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */);
|
static JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time);
|
||||||
|
|
||||||
virtual ~WorkerEnvironmentSettingsObject() override = default;
|
virtual ~WorkerEnvironmentSettingsObject() override = default;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
|
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
|
||||||
#include <LibWeb/HTML/WorkerDebugConsoleClient.h>
|
#include <LibWeb/HTML/WorkerDebugConsoleClient.h>
|
||||||
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
||||||
|
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
|
||||||
#include <LibWeb/Loader/ResourceLoader.h>
|
#include <LibWeb/Loader/ResourceLoader.h>
|
||||||
#include <WebWorker/DedicatedWorkerHost.h>
|
#include <WebWorker/DedicatedWorkerHost.h>
|
||||||
|
|
||||||
|
@ -33,6 +34,9 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans
|
||||||
{
|
{
|
||||||
bool const is_shared = false;
|
bool const is_shared = false;
|
||||||
|
|
||||||
|
// 3. Let unsafeWorkerCreationTime be the unsafe shared current time.
|
||||||
|
auto unsafe_worker_creation_time = Web::HighResolutionTime::unsafe_shared_current_time();
|
||||||
|
|
||||||
// 7. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
// 7. Let realm execution context be the result of creating a new JavaScript realm given agent and the following customizations:
|
||||||
auto realm_execution_context = Web::Bindings::create_a_new_javascript_realm(
|
auto realm_execution_context = Web::Bindings::create_a_new_javascript_realm(
|
||||||
Web::Bindings::main_thread_vm(),
|
Web::Bindings::main_thread_vm(),
|
||||||
|
@ -52,7 +56,7 @@ void DedicatedWorkerHost::run(JS::NonnullGCPtr<Web::Page> page, Web::HTML::Trans
|
||||||
|
|
||||||
// 9. Set up a worker environment settings object with realm execution context,
|
// 9. Set up a worker environment settings object with realm execution context,
|
||||||
// outside settings, and unsafeWorkerCreationTime, and let inside settings be the result.
|
// outside settings, and unsafeWorkerCreationTime, and let inside settings be the result.
|
||||||
auto inner_settings = Web::HTML::WorkerEnvironmentSettingsObject::setup(page, move(realm_execution_context));
|
auto inner_settings = Web::HTML::WorkerEnvironmentSettingsObject::setup(page, move(realm_execution_context), outside_settings_snapshot, unsafe_worker_creation_time);
|
||||||
|
|
||||||
auto& console_object = *inner_settings->realm().intrinsics().console_object();
|
auto& console_object = *inner_settings->realm().intrinsics().console_object();
|
||||||
m_console = console_object.heap().allocate_without_realm<Web::HTML::WorkerDebugConsoleClient>(console_object.console());
|
m_console = console_object.heap().allocate_without_realm<Web::HTML::WorkerDebugConsoleClient>(console_object.console());
|
||||||
|
|
Loading…
Reference in a new issue