Summary
Twig's sandbox mode can be bypassed when using the column filter because it fails to forward the current template Source to the sandbox policy checks.
Under certain configurations, a template author may read public or magic object properties that should be blocked by the sandbox, weakening isolation between untrusted templates and application internals.
Affected context
This vulnerability appears in PHP applications that embed Twig templates with sandbox mode enabled and use the column filter on objects or arrays of objects.
It is most relevant in environments where template authors are partially untrusted or where templates are treated as less-privileged code compared to the host application.
The issue surfaces when sandbox policies rely on Source-aware decisions via SourcePolicyInterface, but the column filter only passes a boolean and omits the current Source, causing policy checks to be evaluated without full context.
Exploit preconditions
- Attack surface: Template execution paths that use Twig with sandbox mode and the
columnfilter. - Required access: Ability to author or modify Twig templates, such as in CMS, multi-tenant, or user-customizable templating scenarios.
- Trigger point: Rendering a template that calls the
columnfilter on objects whose properties are expected to be restricted by sandbox policy. - Why exploitation is possible: The sandbox extension receives an incomplete policy context (no Source object), causing
SandboxExtension::checkPropertyAllowed()to ignore Source-specific rules and allow reading of properties that should be denied.
Why this happens
The underlying problem is a mismatch between the sandbox policy contract and how the column filter invokes sandbox checks.
Sandbox enforcement depends on SourcePolicyInterface to decide if a property access is allowed, requiring both the active sandbox state and the current Source.
The column filter passes only a boolean flag rather than the full Source object into SandboxExtension::checkPropertyAllowed(), degrading the policy evaluation.
This is a classic CWE-693: Protection Mechanism Failure, where a security control (sandbox) is implemented but not correctly wired into all code paths, allowing restricted data access.
Potential impact
- A template author may read public properties that were intended to be blocked by sandbox rules.
- A template author could access magic properties exposing internal state or configuration details.
- Sensitive application data may be disclosed via templates that should have limited visibility.
- Defense-in-depth provided by sandboxing can be weakened, increasing the blast radius of template misuse.
General mitigation guidance
Mitigation generally focuses on ensuring sandbox policies are consistently applied and context-complete across all template operations.
Patterns that help reduce risk include:
- Auditing template helpers and filters to confirm they pass full policy context (including Source) into sandbox checks.
- Designing sandbox rules so they fail closed when context is missing or ambiguous.
- Limiting the set of objects and properties exposed to untrusted templates by default and using explicit whitelists.
- Treating template authors as potentially untrusted and assigning them least-privilege access to the data model surfaced in templates.
How teams detect issues like this
Detection usually involves:
- Static analysis and code review of custom Twig extensions, filters, and functions to verify that sandbox-aware APIs are invoked with complete context.
- Searching for calls to
SandboxExtension::checkPropertyAllowed()(or equivalent checks) that omit Source information or rely solely on boolean flags. - Implementing security-focused test cases where untrusted templates attempt to read prohibited properties, validating that sandbox rules are enforced.
- Integrating automated review tools or CI policies that flag changes in sandbox-related code paths and template-access surfaces.

