CVE-2026-46628

Updated on 21 May 2026

Severity

Awaiting Analysis

Details

Overview

About vulnerability

Description

The spaceless filter is registered with is_safe => ['html'], which means Twig’s autoescaper does not escape its output in an HTML context. As a result, applying spaceless to attacker-controlled input that contains markup emits the markup unescaped even when the developer never wrote |raw and autoescape is enabled.

Example:

{% set payload = '<script>alert()</script>' %}
&#123;&#123; payload &#125;&#125;          {# escaped #}
&#123;&#123; payload|spaceless &#125;&#125; {# not escaped #}

The filter is deprecated but still functional. With the deprecation, some downstream projects (e.g. Drupal modules) have duplicated the filter and inherited the same is_safe flag.

Resolution

The spaceless filter no longer marks its output as safe. Documentation has been updated to warn that spaceless should not be applied to unsanitised user input.

Credits

Twig would like to thank Pierre Rudloff for reporting the issue.

Details

Affected product:
drupal/core , twig/twig
Affected packages:
twig @ v2.16.1 (+1 more)

Description

The spaceless filter is registered with is_safe => ['html'], which means Twig’s autoescaper does not escape its output in an HTML context. As a result, applying spaceless to attacker-controlled input that contains markup emits the markup unescaped even when the developer never wrote |raw and autoescape is enabled.

Example:

{% set payload = '<script>alert()</script>' %}
&#123;&#123; payload &#125;&#125;          {# escaped #}
&#123;&#123; payload|spaceless &#125;&#125; {# not escaped #}

The filter is deprecated but still functional. With the deprecation, some downstream projects (e.g. Drupal modules) have duplicated the filter and inherited the same is_safe flag.

Resolution

The spaceless filter no longer marks its output as safe. Documentation has been updated to warn that spaceless should not be applied to unsanitised user input.

Credits

Twig would like to thank Pierre Rudloff for reporting the issue.