Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / content_security_policy / directives / script_source_attribute_directive.lucb

#==============================================================================================
#
#   script_source_attribute_directive - ContentSecurityPolicy::Directives::ScriptSourceAttributeDirective
#   (the script-src-attr directive): the inline check of its source list
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/ContentSecurityPolicy/Directives/ScriptSourceAttributeDirective.cpp
#       (lines 1-44).
#
#       Copyright (c) 2024, Luke Wilde <luke@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/ContentSecurityPolicy/Directives/ScriptSourceAttributeDirective.cpp:16 Web::ContentSecurityPolicy::Directives::ScriptSourceAttributeDirective::ScriptSourceAttributeDirective.
func content_security_policy_script_source_attribute_directive_construct(this: ContentSecurityPolicyScriptSourceAttributeDirective*, 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/ScriptSourceAttributeDirective.cpp:22 Web::ContentSecurityPolicy::Directives::ScriptSourceAttributeDirective::inline_check (override).
# https://w3c.github.io/webappsec-csp/#script-src-attr-inline
pub func content_security_policy_script_source_attribute_directive_inline_check_impl(base: ContentSecurityPolicyDirective*, arg0: gc.Heap*, element: DomElement*?, type_: ContentSecurityPolicyInlineType, policy: ContentSecurityPolicyPolicy*, source: ak.String) -> ContentSecurityPolicyResult:
    # 1. Assert: element is not null or type is "navigation".
    assert(element != none or type_ == ContentSecurityPolicyInlineType.navigation)

    # 2. 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_)

    # 3. If the result of executing § 6.8.4 Should fetch directive execute on name, script-src-attr and policy is "No",
    #    return "Allowed".
    if content_security_policy_directives_should_fetch_directive_execute(name, content_security_policy_directives_names_script_src_attr, policy) == ContentSecurityPolicyShouldExecute.no:
        return ContentSecurityPolicyResult.allowed

    # 4. 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

    # 5. Return "Allowed".
    return ContentSecurityPolicyResult.allowed