dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / content_security_policy / directives / style_source_element_directive.lucb
#==============================================================================================
#
# style_source_element_directive - ContentSecurityPolicy::Directives::StyleSourceElementDirective
# (the style-src-elem directive): nonces, the request and response checks and the inline check of its source list
#
# DESCRIPTION:
# Port of Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceElementDirective.cpp
# (lines 1-91).
#
# Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceElementDirective.cpp:16 Web::ContentSecurityPolicy::Directives::StyleSourceElementDirective::StyleSourceElementDirective.
func content_security_policy_style_source_element_directive_construct(this: ContentSecurityPolicyStyleSourceElementDirective*, 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/StyleSourceElementDirective.cpp:22 Web::ContentSecurityPolicy::Directives::StyleSourceElementDirective::pre_request_check (override).
# https://w3c.github.io/webappsec-csp/#style-src-elem-pre-request
pub func content_security_policy_style_source_element_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, style-src-elem and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_style_src_elem, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. If the result of executing § 6.7.2.3 Does nonce match source list? on request’s cryptographic nonce metadata
# and this directive’s value is "Matches", return "Allowed".
if content_security_policy_directives_does_nonce_match_source_list(fetch_request_cryptographic_nonce_metadata(request), &base.m_value) == ContentSecurityPolicyDirectivesMatchResult.matches:
return ContentSecurityPolicyResult.allowed
# 4. 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
# 5. Return "Allowed".
return ContentSecurityPolicyResult.allowed
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceElementDirective.cpp:47 Web::ContentSecurityPolicy::Directives::StyleSourceElementDirective::post_request_check (override).
# https://w3c.github.io/webappsec-csp/#style-src-elem-post-request
pub func content_security_policy_style_source_element_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, style-src-elem and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_style_src_elem, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. If the result of executing § 6.7.2.3 Does nonce match source list? on request’s cryptographic nonce metadata
# and this directive’s value is "Matches", return "Allowed".
if content_security_policy_directives_does_nonce_match_source_list(fetch_request_cryptographic_nonce_metadata(request), &base.m_value) == ContentSecurityPolicyDirectivesMatchResult.matches:
return ContentSecurityPolicyResult.allowed
# 4. 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
# 5. Return "Allowed".
return ContentSecurityPolicyResult.allowed
## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/StyleSourceElementDirective.cpp:72 Web::ContentSecurityPolicy::Directives::StyleSourceElementDirective::inline_check (override).
# https://w3c.github.io/webappsec-csp/#style-src-elem-inline
pub func content_security_policy_style_source_element_directive_inline_check_impl(base: ContentSecurityPolicyDirective*, arg0: gc.Heap*, element: DomElement*?, type_: ContentSecurityPolicyInlineType, policy: ContentSecurityPolicyPolicy*, source: ak.String) -> ContentSecurityPolicyResult:
# 1. Let name be the result of executing § 6.8.2 Get the effective directive for inline checks on type.
let name = content_security_policy_directives_get_the_effective_directive_for_inline_checks(type_)
# 2. If the result of executing § 6.8.4 Should fetch directive execute on name, style-src-elem and policy is "No",
# return "Allowed".
if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_style_src_elem, policy) == ContentSecurityPolicyShouldExecute.no:
return ContentSecurityPolicyResult.allowed
# 3. If the result of executing § 6.7.3.3 Does element match source list for type and source? on element, this
# directive’s value, type, and source, is "Does Not Match", return "Blocked".
if content_security_policy_directives_does_element_match_source_list_for_type_and_source(element, &base.m_value, type_, source) == ContentSecurityPolicyDirectivesMatchResult.does_not_match:
return ContentSecurityPolicyResult.blocked
# 4. Return "Allowed".
return ContentSecurityPolicyResult.allowed