dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / content_security_policy / directives / child_source_directive.lucb
#==============================================================================================
#
# child_source_directive - ContentSecurityPolicy::Directives::ChildSourceDirective
# (the child-src directive): it runs the checks of the request's effective directive with its own value
#
# DESCRIPTION:
# Port of Libraries/LibWeb/ContentSecurityPolicy/Directives/ChildSourceDirective.cpp
# (lines 1-56).
#
# Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/ChildSourceDirective.cpp:17 Web::ContentSecurityPolicy::Directives::ChildSourceDirective::ChildSourceDirective.
func content_security_policy_child_source_directive_construct(this: ContentSecurityPolicyChildSourceDirective*, 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/ChildSourceDirective.cpp:23 Web::ContentSecurityPolicy::Directives::ChildSourceDirective::pre_request_check (override).
# https://w3c.github.io/webappsec-csp/#child-src-pre-request
pub func content_security_policy_child_source_directive_pre_request_check_impl(base: ContentSecurityPolicyDirective*, heap: 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, child-src and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_child_src, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. Return the result of executing the pre-request check for the directive whose name is name on request and
# policy, using this directive’s value for the comparison.
let name_value = name else trap("VERIFY: Optional::value of the effective directive")
let directive = content_security_policy_directives_create_directive(heap, ak.fly_string_to_string_const(&name_value), base.m_value)
return content_security_policy_directive_pre_request_check(directive, heap, request, policy)
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/ChildSourceDirective.cpp:40 Web::ContentSecurityPolicy::Directives::ChildSourceDirective::post_request_check (override).
# https://w3c.github.io/webappsec-csp/#child-src-post-request
pub func content_security_policy_child_source_directive_post_request_check_impl(base: ContentSecurityPolicyDirective*, heap: 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, child-src and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_child_src, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. Return the result of executing the post-request check for the directive whose name is name on request,
# response, and policy, using this directive’s value for the comparison.
let name_value = name else trap("VERIFY: Optional::value of the effective directive")
let directive = content_security_policy_directives_create_directive(heap, ak.fly_string_to_string_const(&name_value), base.m_value)
return content_security_policy_directive_post_request_check(directive, heap, request, response, policy)