From 6c1a9b28f13cab38730baf6c75bc537e5ec58491 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Oct 2022 19:09:14 +0200 Subject: [PATCH] LibWeb: Implement 'Is url potentially trustworthy?' AO --- .../LibWeb/SecureContexts/AbstractOperations.cpp | 16 ++++++++++++++++ .../LibWeb/SecureContexts/AbstractOperations.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp b/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp index 0bf70a1ed1..6e94b6f44f 100644 --- a/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -57,4 +58,19 @@ Trustworthiness is_origin_potentially_trustworthy(HTML::Origin const& origin) return Trustworthiness::NotTrustworthy; } +// https://w3c.github.io/webappsec-secure-contexts/#is-url-trustworthy +Trustworthiness is_url_potentially_trustworthy(AK::URL const& url) +{ + // 1. If url is "about:blank" or "about:srcdoc", return "Potentially Trustworthy". + if (url == "about:blank"sv || url == "about:srcdoc"sv) + return Trustworthiness::PotentiallyTrustworthy; + + // 2. If url’s scheme is "data", return "Potentially Trustworthy". + if (url.scheme() == "data"sv) + return Trustworthiness::PotentiallyTrustworthy; + + // 3. Return the result of executing § 3.1 Is origin potentially trustworthy? on url’s origin. + return is_origin_potentially_trustworthy(URL::url_origin(url)); +} + } diff --git a/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.h b/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.h index f753e62114..2c42d451ee 100644 --- a/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/SecureContexts/AbstractOperations.h @@ -6,6 +6,7 @@ #pragma once +#include #include namespace Web::SecureContexts { @@ -16,5 +17,6 @@ enum class Trustworthiness { }; [[nodiscard]] Trustworthiness is_origin_potentially_trustworthy(HTML::Origin const&); +[[nodiscard]] Trustworthiness is_url_potentially_trustworthy(AK::URL const&); }