mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWeb/CSP: Implement the manifest-src directive
This commit is contained in:
parent
002e993f68
commit
5addbcd61b
Notes:
github-actions[bot]
2025-07-06 12:17:22 +00:00
Author: https://github.com/Lubrsi
Commit: 5addbcd61b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5308
Reviewed-by: https://github.com/shannonbooth
5 changed files with 95 additions and 0 deletions
|
@ -44,6 +44,7 @@ set(SOURCES
|
||||||
ContentSecurityPolicy/Directives/FrameSourceDirective.cpp
|
ContentSecurityPolicy/Directives/FrameSourceDirective.cpp
|
||||||
ContentSecurityPolicy/Directives/ImageSourceDirective.cpp
|
ContentSecurityPolicy/Directives/ImageSourceDirective.cpp
|
||||||
ContentSecurityPolicy/Directives/KeywordSources.cpp
|
ContentSecurityPolicy/Directives/KeywordSources.cpp
|
||||||
|
ContentSecurityPolicy/Directives/ManifestSourceDirective.cpp
|
||||||
ContentSecurityPolicy/Directives/Names.cpp
|
ContentSecurityPolicy/Directives/Names.cpp
|
||||||
ContentSecurityPolicy/Directives/SerializedDirective.cpp
|
ContentSecurityPolicy/Directives/SerializedDirective.cpp
|
||||||
ContentSecurityPolicy/Directives/SourceExpression.cpp
|
ContentSecurityPolicy/Directives/SourceExpression.cpp
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <LibWeb/ContentSecurityPolicy/Directives/FontSourceDirective.h>
|
#include <LibWeb/ContentSecurityPolicy/Directives/FontSourceDirective.h>
|
||||||
#include <LibWeb/ContentSecurityPolicy/Directives/FrameSourceDirective.h>
|
#include <LibWeb/ContentSecurityPolicy/Directives/FrameSourceDirective.h>
|
||||||
#include <LibWeb/ContentSecurityPolicy/Directives/ImageSourceDirective.h>
|
#include <LibWeb/ContentSecurityPolicy/Directives/ImageSourceDirective.h>
|
||||||
|
#include <LibWeb/ContentSecurityPolicy/Directives/ManifestSourceDirective.h>
|
||||||
#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>
|
#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>
|
||||||
|
|
||||||
namespace Web::ContentSecurityPolicy::Directives {
|
namespace Web::ContentSecurityPolicy::Directives {
|
||||||
|
@ -29,6 +30,9 @@ GC::Ref<Directive> create_directive(GC::Heap& heap, String name, Vector<String>
|
||||||
if (name == Names::ImgSrc)
|
if (name == Names::ImgSrc)
|
||||||
return heap.allocate<ImageSourceDirective>(move(name), move(value));
|
return heap.allocate<ImageSourceDirective>(move(name), move(value));
|
||||||
|
|
||||||
|
if (name == Names::ManifestSrc)
|
||||||
|
return heap.allocate<ManifestSourceDirective>(move(name), move(value));
|
||||||
|
|
||||||
return heap.allocate<Directive>(move(name), move(value));
|
return heap.allocate<Directive>(move(name), move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h>
|
||||||
|
#include <LibWeb/ContentSecurityPolicy/Directives/ManifestSourceDirective.h>
|
||||||
|
#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>
|
||||||
|
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
|
||||||
|
|
||||||
|
namespace Web::ContentSecurityPolicy::Directives {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(ManifestSourceDirective);
|
||||||
|
|
||||||
|
ManifestSourceDirective::ManifestSourceDirective(String name, Vector<String> value)
|
||||||
|
: Directive(move(name), move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webappsec-csp/#manifest-src-pre-request
|
||||||
|
Directive::Result ManifestSourceDirective::pre_request_check(GC::Heap&, GC::Ref<Fetch::Infrastructure::Request const> request, GC::Ref<Policy const> policy) const
|
||||||
|
{
|
||||||
|
// 1. Let name be the result of executing § 6.8.1 Get the effective directive for request on request.
|
||||||
|
auto name = get_the_effective_directive_for_request(request);
|
||||||
|
|
||||||
|
// 2. If the result of executing § 6.8.4 Should fetch directive execute on name, manifest-src and policy is "No",
|
||||||
|
// return "Allowed".
|
||||||
|
if (should_fetch_directive_execute(name, Names::ManifestSrc, policy) == ShouldExecute::No)
|
||||||
|
return Result::Allowed;
|
||||||
|
|
||||||
|
// 3. If the result of executing § 6.7.2.5 Does request match source list? on request, this directive’s value,
|
||||||
|
// and policy, is "Does Not Match", return "Blocked".
|
||||||
|
if (does_request_match_source_list(request, value(), policy) == MatchResult::DoesNotMatch)
|
||||||
|
return Result::Blocked;
|
||||||
|
|
||||||
|
// 4. Return "Allowed".
|
||||||
|
return Result::Allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webappsec-csp/#manifest-src-post-request
|
||||||
|
Directive::Result ManifestSourceDirective::post_request_check(GC::Heap&, GC::Ref<Fetch::Infrastructure::Request const> request, GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ref<Policy const> policy) const
|
||||||
|
{
|
||||||
|
// 1. Let name be the result of executing § 6.8.1 Get the effective directive for request on request.
|
||||||
|
auto name = get_the_effective_directive_for_request(request);
|
||||||
|
|
||||||
|
// 2. If the result of executing § 6.8.4 Should fetch directive execute on name, manifest-src and policy is "No",
|
||||||
|
// return "Allowed".
|
||||||
|
if (should_fetch_directive_execute(name, Names::ManifestSrc, policy) == ShouldExecute::No)
|
||||||
|
return Result::Allowed;
|
||||||
|
|
||||||
|
// 3. If the result of executing § 6.7.2.6 Does response to request match source list? on response, request, this
|
||||||
|
// directive’s value, and policy, is "Does Not Match", return "Blocked".
|
||||||
|
if (does_response_match_source_list(response, request, value(), policy) == MatchResult::DoesNotMatch)
|
||||||
|
return Result::Blocked;
|
||||||
|
|
||||||
|
// 4. Return "Allowed".
|
||||||
|
return Result::Allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/ContentSecurityPolicy/Directives/Directive.h>
|
||||||
|
|
||||||
|
namespace Web::ContentSecurityPolicy::Directives {
|
||||||
|
|
||||||
|
// https://w3c.github.io/webappsec-csp/#directive-manifest-src
|
||||||
|
class ManifestSourceDirective final : public Directive {
|
||||||
|
GC_CELL(ManifestSourceDirective, Directive)
|
||||||
|
GC_DECLARE_ALLOCATOR(ManifestSourceDirective);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ManifestSourceDirective() = default;
|
||||||
|
|
||||||
|
virtual Result pre_request_check(GC::Heap&, GC::Ref<Fetch::Infrastructure::Request const>, GC::Ref<Policy const>) const override;
|
||||||
|
virtual Result post_request_check(GC::Heap&, GC::Ref<Fetch::Infrastructure::Request const>, GC::Ref<Fetch::Infrastructure::Response const>, GC::Ref<Policy const>) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ManifestSourceDirective(String name, Vector<String> value);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -135,6 +135,7 @@ class Directive;
|
||||||
class FontSourceDirective;
|
class FontSourceDirective;
|
||||||
class FrameSourceDirective;
|
class FrameSourceDirective;
|
||||||
class ImageSourceDirective;
|
class ImageSourceDirective;
|
||||||
|
class ManifestSourceDirective;
|
||||||
struct SerializedDirective;
|
struct SerializedDirective;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue