LibWeb: Finish algorithm to block trusted type policy creation with CSP

This is the mechanism that should pages to determine what kind of
policies can be created on their domains mostly based around the HTTP
headers the server responds with.
This commit is contained in:
Tete17
2025-07-31 10:57:02 +02:00
committed by Luke Wilde
parent 6398e771a3
commit 966e00fd69
Notes: github-actions[bot] 2025-08-11 11:23:27 +00:00
8 changed files with 111 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/ContentSecurityPolicy/Directives/KeywordTrustedTypes.h>
namespace Web::ContentSecurityPolicy::Directives::KeywordTrustedTypes {
#define __ENUMERATE_KEYWORD_TRUSTED_TYPE(name, value) \
FlyString name = value##_fly_string;
ENUMERATE_KEYWORD_TRUSTED_TYPES
#undef __ENUMERATE_KEYWORD_TRUSTED_TYPE
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
namespace Web::ContentSecurityPolicy::Directives::KeywordTrustedTypes {
// https://www.w3.org/TR/trusted-types/#tt-keyword
#define ENUMERATE_KEYWORD_TRUSTED_TYPES \
__ENUMERATE_KEYWORD_TRUSTED_TYPE(AllowDuplicates, "'allow-duplicates'") \
__ENUMERATE_KEYWORD_TRUSTED_TYPE(None, "'none'") \
__ENUMERATE_KEYWORD_TRUSTED_TYPE(WildCard, "*")
#define __ENUMERATE_KEYWORD_TRUSTED_TYPE(name, value) extern FlyString name;
ENUMERATE_KEYWORD_TRUSTED_TYPES
#undef __ENUMERATE_KEYWORD_TRUSTED_TYPE
}

View File

@@ -32,6 +32,7 @@ namespace Web::ContentSecurityPolicy::Directives::Names {
__ENUMERATE_DIRECTIVE_NAME(StyleSrc, "style-src") \
__ENUMERATE_DIRECTIVE_NAME(StyleSrcElem, "style-src-elem") \
__ENUMERATE_DIRECTIVE_NAME(StyleSrcAttr, "style-src-attr") \
__ENUMERATE_DIRECTIVE_NAME(TrustedTypes, "trusted-types") \
__ENUMERATE_DIRECTIVE_NAME(WebRTC, "webrtc") \
__ENUMERATE_DIRECTIVE_NAME(WorkerSrc, "worker-src")