mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-16 05:51:55 +00:00
LibWeb: Introduce Content Security Policy policies and directives
These form the basis of Content Security Policy. A policy is a collection of directives that are parsed from either the Content-Security-Policy(-Report-Only) HTTP header, or the `<meta>` element. The directives are what restrict the operations can be performed in the current global execution context. For example, "frame-ancestors: none" tells us to prevent the page from being loaded in an embedded context, such as `<iframe>`. You can see it a bit like OpenBSD's pledge() functionality, but for the web platform: https://man.openbsd.org/pledge.2
This commit is contained in:
parent
d17bd2c5f1
commit
e34a6c86b9
Notes:
github-actions[bot]
2025-03-04 13:28:21 +00:00
Author: https://github.com/Lubrsi
Commit: e34a6c86b9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3662
20 changed files with 846 additions and 3 deletions
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
#include <LibWeb/ContentSecurityPolicy/Directives/SerializedDirective.h>
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::ContentSecurityPolicy::Directives::SerializedDirective const& serialized_directive)
|
||||
{
|
||||
TRY(encoder.encode(serialized_directive.name));
|
||||
TRY(encoder.encode(serialized_directive.value));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::ContentSecurityPolicy::Directives::SerializedDirective> decode(Decoder& decoder)
|
||||
{
|
||||
Web::ContentSecurityPolicy::Directives::SerializedDirective serialized_directive {};
|
||||
|
||||
serialized_directive.name = TRY(decoder.decode<String>());
|
||||
serialized_directive.value = TRY(decoder.decode<Vector<String>>());
|
||||
|
||||
return serialized_directive;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue