1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57:35 +00:00

LibWeb: Implement 'Is url potentially trustworthy?' AO

This commit is contained in:
Linus Groh 2022-10-13 19:09:14 +02:00
parent d56a6eb508
commit 6c1a9b28f1
2 changed files with 18 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <AK/IPv4Address.h>
#include <AK/IPv6Address.h>
#include <AK/URL.h>
#include <LibWeb/HTML/Origin.h>
#include <LibWeb/SecureContexts/AbstractOperations.h>
#include <LibWeb/URL/URL.h>
@ -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 urls 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 urls origin.
return is_origin_potentially_trustworthy(URL::url_origin(url));
}
}