{# Copyright 2024, 2025 New Vector Ltd. Copyright 2023, 2024 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. -#} {# Macro to remove 'safe' scope from a scope list. Usage: {% call(scopes) scope.unsafe_scopes(scopes=["openid", "urn:matrix:client:api:*", "urn:synapse:admin:*", "urn:mas:admin"]) %} `scopes` only has unsafe scopes: ["urn:synapse:admin:*", "urn:mas:admin"] {% endcall %} #} {% macro unsafe_scopes(scopes) -%} {% set ns = namespace(unsafe_scopes=[]) %} {% set safe_scope_prefixes = ["openid", "urn:matrix:client:api:", "urn:matrix:org.matrix.msc2967.client:api:", "urn:matrix:client:device:", "urn:matrix:org.matrix.msc2967.client:device:"] %} {% for scope in scopes %} {% set ns.is_safe = False %} {% for safe_scope_prefix in safe_scope_prefixes %} {% if scope.startswith(safe_scope_prefix) %} {% set ns.is_safe = True %} {% endif %} {% endfor %} {% if not ns.is_safe %} {% set ns.unsafe_scopes = ns.unsafe_scopes + [scope] %} {% endif %} {% endfor %} {{ caller(ns.unsafe_scopes) }} {%- endmacro %} {% macro list(scopes) %} {% endmacro %}