dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / content_security_policy / directives / media_source_directive.lucb
#==============================================================================================
#
# media_source_directive - ContentSecurityPolicy::Directives::MediaSourceDirective
# (the media-src directive): its pre- and post-request checks match the request and the response to its source list
#
# DESCRIPTION:
# Port of Libraries/LibWeb/ContentSecurityPolicy/Directives/MediaSourceDirective.cpp
# (lines 1-61).
#
# Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/MediaSourceDirective.cpp:16 Web::ContentSecurityPolicy::Directives::MediaSourceDirective::MediaSourceDirective.
func content_security_policy_media_source_directive_construct(this: ContentSecurityPolicyMediaSourceDirective*, name: ak.String, value: ak.Vector[ak.String]):
content_security_policy_directive_construct(this.content_security_policy_directive(), name, value)
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/MediaSourceDirective.cpp:22 Web::ContentSecurityPolicy::Directives::MediaSourceDirective::pre_request_check (override).
# https://w3c.github.io/webappsec-csp/#media-src-pre-request
pub func content_security_policy_media_source_directive_pre_request_check_impl(base: ContentSecurityPolicyDirective*, arg0: gc.Heap*, request: FetchRequest*, policy: ContentSecurityPolicyPolicy*) -> ContentSecurityPolicyResult:
# 1. Let name be the result of executing § 6.8.1 Get the effective directive for request on request.
let name = content_security_policy_directives_get_the_effective_directive_for_request(request)
# 2. If the result of executing § 6.8.4 Should fetch directive execute on name, media-src and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_media_src, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.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 content_security_policy_directives_does_request_match_source_list(request, &base.m_value, policy) == ContentSecurityPolicyDirectivesMatchResult.does_not_match:
return ContentSecurityPolicyResult.blocked
# 4. Return "Allowed".
return ContentSecurityPolicyResult.allowed
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/MediaSourceDirective.cpp:42 Web::ContentSecurityPolicy::Directives::MediaSourceDirective::post_request_check (override).
# https://w3c.github.io/webappsec-csp/#media-src-post-request
pub func content_security_policy_media_source_directive_post_request_check_impl(base: ContentSecurityPolicyDirective*, arg0: gc.Heap*, request: FetchRequest*, response: FetchResponse*, policy: ContentSecurityPolicyPolicy*) -> ContentSecurityPolicyResult:
# 1. Let name be the result of executing § 6.8.1 Get the effective directive for request on request.
let name = content_security_policy_directives_get_the_effective_directive_for_request(request)
# 2. If the result of executing § 6.8.4 Should fetch directive execute on name, media-src and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_media_src, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.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 content_security_policy_directives_does_response_match_source_list(response, request, &base.m_value, policy) == ContentSecurityPolicyDirectivesMatchResult.does_not_match:
return ContentSecurityPolicyResult.blocked
# 4. Return "Allowed".
return ContentSecurityPolicyResult.allowed