LibWeb/CSP: Implement URL matching algorithms

These are used by all the *-src attributes, to check if a given URL,
origin and redirect count matches a source list entry specified in
the *-src attribute's values, if it's allowed to.
This commit is contained in:
Luke Wilde 2024-11-26 11:24:11 +00:00 committed by Shannon Booth
commit 1edf7a8aa2
Notes: github-actions[bot] 2025-06-30 22:25:59 +00:00
2 changed files with 364 additions and 0 deletions

View file

@ -8,6 +8,7 @@
#include <AK/StringView.h>
#include <LibGC/Ptr.h>
#include <LibURL/Forward.h>
#include <LibWeb/ContentSecurityPolicy/Directives/Directive.h>
#include <LibWeb/Forward.h>
@ -18,10 +19,18 @@ enum class ShouldExecute {
Yes,
};
enum class MatchResult {
DoesNotMatch,
Matches,
};
[[nodiscard]] Optional<FlyString> get_the_effective_directive_for_request(GC::Ref<Fetch::Infrastructure::Request const> request);
[[nodiscard]] Vector<StringView> get_fetch_directive_fallback_list(Optional<FlyString> directive_name);
[[nodiscard]] ShouldExecute should_fetch_directive_execute(Optional<FlyString> effective_directive_name, FlyString const& directive_name, GC::Ref<Policy const> policy);
[[nodiscard]] FlyString get_the_effective_directive_for_inline_checks(Directive::InlineType type);
[[nodiscard]] MatchResult does_url_match_expression_in_origin_with_redirect_count(URL::URL const& url, String const& expression, URL::Origin const& origin, u8 redirect_count);
[[nodiscard]] MatchResult does_url_match_source_list_in_origin_with_redirect_count(URL::URL const& url, Vector<String> const& source_list, URL::Origin const& origin, u8 redirect_count);
}