diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 4fd706ca08b..827d64151bd 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -39,6 +39,7 @@ set(SOURCES ContentSecurityPolicy/Directives/Directive.cpp ContentSecurityPolicy/Directives/DirectiveFactory.cpp ContentSecurityPolicy/Directives/DirectiveOperations.cpp + ContentSecurityPolicy/Directives/KeywordSources.cpp ContentSecurityPolicy/Directives/Names.cpp ContentSecurityPolicy/Directives/SerializedDirective.cpp ContentSecurityPolicy/Policy.cpp diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.cpp new file mode 100644 index 00000000000..5ec0532e333 --- /dev/null +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::ContentSecurityPolicy::Directives::KeywordSources { + +#define __ENUMERATE_KEYWORD_SOURCE(name, value) \ + FlyString name = value##_fly_string; +ENUMERATE_KEYWORD_SOURCES +#undef __ENUMERATE_KEYWORD_SOURCE + +} diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.h b/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.h new file mode 100644 index 00000000000..ab753f318ed --- /dev/null +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/KeywordSources.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::ContentSecurityPolicy::Directives::KeywordSources { + +// https://w3c.github.io/webappsec-csp/#grammardef-keyword-source +#define ENUMERATE_KEYWORD_SOURCES \ + __ENUMERATE_KEYWORD_SOURCE(Self, "'self'") \ + __ENUMERATE_KEYWORD_SOURCE(UnsafeInline, "'unsafe-inline'") \ + __ENUMERATE_KEYWORD_SOURCE(UnsafeEval, "'unsafe-eval'") \ + __ENUMERATE_KEYWORD_SOURCE(StrictDynamic, "'strict-dynamic'") \ + __ENUMERATE_KEYWORD_SOURCE(UnsafeHashes, "'unsafe-hashes'") \ + __ENUMERATE_KEYWORD_SOURCE(ReportSample, "'report-sample'") \ + __ENUMERATE_KEYWORD_SOURCE(UnsafeAllowRedirects, "'unsafe-allow-redirects'") \ + __ENUMERATE_KEYWORD_SOURCE(WasmUnsafeEval, "'wasm-unsafe-eval'") + +#define __ENUMERATE_KEYWORD_SOURCE(name, value) extern FlyString name; +ENUMERATE_KEYWORD_SOURCES +#undef __ENUMERATE_KEYWORD_SOURCE + +} diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/Names.h b/Libraries/LibWeb/ContentSecurityPolicy/Directives/Names.h index ee26d3386f9..8022bcfd372 100644 --- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/Names.h +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/Names.h @@ -39,6 +39,4 @@ namespace Web::ContentSecurityPolicy::Directives::Names { ENUMERATE_DIRECTIVE_NAMES #undef __ENUMERATE_DIRECTIVE_NAME -void initialize_strings(); - }