diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index e2826f05eb4..5f83ec696ca 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -70,6 +70,7 @@ set(SOURCES ContentSecurityPolicy/Directives/StyleSourceAttributeDirective.cpp ContentSecurityPolicy/Directives/StyleSourceDirective.cpp ContentSecurityPolicy/Directives/StyleSourceElementDirective.cpp + ContentSecurityPolicy/Directives/WebRTCDirective.cpp ContentSecurityPolicy/Directives/WorkerSourceDirective.cpp ContentSecurityPolicy/Policy.cpp ContentSecurityPolicy/PolicyList.cpp diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveFactory.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveFactory.cpp index cff65cbdfe1..3ae8a611a00 100644 --- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveFactory.cpp +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveFactory.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace Web::ContentSecurityPolicy::Directives { @@ -94,6 +95,9 @@ GC::Ref create_directive(GC::Heap& heap, String name, Vector if (name == Names::StyleSrcElem) return heap.allocate(move(name), move(value)); + if (name == Names::WebRTC) + return heap.allocate(move(name), move(value)); + if (name == Names::WorkerSrc) return heap.allocate(move(name), move(value)); diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.cpp new file mode 100644 index 00000000000..94d78a4893c --- /dev/null +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::ContentSecurityPolicy::Directives { + +GC_DEFINE_ALLOCATOR(WebRTCDirective); + +WebRTCDirective::WebRTCDirective(String name, Vector value) + : Directive(move(name), move(value)) +{ +} + +// https://w3c.github.io/webappsec-csp/#webrtc-pre-connect +Directive::Result WebRTCDirective::webrtc_pre_connect_check(GC::Ref) const +{ + // 1. If this directive’s value contains a single item which is an ASCII case-insensitive match for the string + // "'allow'", return "Allowed". + if (value().size() == 1 && value().first().equals_ignoring_ascii_case("'allow'"sv)) + return Result::Allowed; + + // 2. Return "Blocked". + return Result::Blocked; +} + +} diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.h b/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.h new file mode 100644 index 00000000000..f5b135bf0cb --- /dev/null +++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/WebRTCDirective.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::ContentSecurityPolicy::Directives { + +// https://w3c.github.io/webappsec-csp/#directive-webrtc +class WebRTCDirective final : public Directive { + GC_CELL(WebRTCDirective, Directive) + GC_DECLARE_ALLOCATOR(WebRTCDirective); + +public: + virtual ~WebRTCDirective() = default; + + [[nodiscard]] virtual Result webrtc_pre_connect_check(GC::Ref) const override; + +private: + WebRTCDirective(String name, Vector value); +}; + +} diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 57cdc7d8c1c..681a5fa0f0d 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -157,6 +157,7 @@ class ScriptSourceElementDirective; class StyleSourceAttributeDirective; class StyleSourceDirective; class StyleSourceElementDirective; +class WebRTCDirective; class WorkerSourceDirective; struct SerializedDirective;