From 9701128145059ac360e32c6c363eac16fee05ac6 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 10 May 2023 16:24:52 -0400 Subject: [PATCH] LibWeb: Implement the CORS settings attribute credentials mode AO --- .../LibWeb/HTML/CORSSettingAttribute.cpp | 20 +++++++++++++++++++ .../LibWeb/HTML/CORSSettingAttribute.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.cpp b/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.cpp index 6eee57613d..097a4cadf2 100644 --- a/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.cpp +++ b/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.cpp @@ -26,4 +26,24 @@ CORSSettingAttribute cors_setting_attribute_from_keyword(Optional const& return CORSSettingAttribute::Anonymous; } +// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attribute-credentials-mode +Fetch::Infrastructure::Request::CredentialsMode cors_settings_attribute_credentials_mode(CORSSettingAttribute attribute) +{ + switch (attribute) { + // -> No CORS + // -> Anonymous + case CORSSettingAttribute::NoCORS: + case CORSSettingAttribute::Anonymous: + // "same-origin" + return Fetch::Infrastructure::Request::CredentialsMode::SameOrigin; + + // -> Use Credentials + case CORSSettingAttribute::UseCredentials: + // "include" + return Fetch::Infrastructure::Request::CredentialsMode::Include; + } + + VERIFY_NOT_REACHED(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.h b/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.h index 5d60e13052..73ea94eeee 100644 --- a/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.h +++ b/Userland/Libraries/LibWeb/HTML/CORSSettingAttribute.h @@ -8,6 +8,7 @@ #include #include +#include namespace Web::HTML { @@ -19,5 +20,6 @@ enum class CORSSettingAttribute { }; [[nodiscard]] CORSSettingAttribute cors_setting_attribute_from_keyword(Optional const& keyword); +[[nodiscard]] Fetch::Infrastructure::Request::CredentialsMode cors_settings_attribute_credentials_mode(CORSSettingAttribute); }