GHSA-5v5v-ww74-355v: Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
A vulnerability in twig/twig prior to version 3.27.0 allows sandboxed templates to bypass the sandbox __toString() policy via dynamic mapping keys. This occurs because dynamic keys in array expressions were not properly checked before PHP coerced them to strings, enabling unauthorized __toString() calls. The issue was fixed by marking dynamic mapping keys as string-coercion sites, ensuring sandbox policy enforcement before string conversion.
AI Analysis
Technical Summary
This vulnerability is a residual bypass of a previous fix for unguarded __toString() calls in twig/twig. In version 3.26.0, the sandbox visitor was extended to wrap child nodes coerced to strings with a check node, but ArrayExpression did not implement the required interface for its dynamic mapping keys. When a dynamic key resolves to a Stringable object, PHP invokes __toString() directly without sandbox policy checks, allowing sandboxed template authors to trigger __toString() on any object reachable in the render context. The fix in version 3.27.0 adds the interface to ArrayExpression's dynamic keys, ensuring sandbox policy checks occur before string coercion, closing the enforcement gap.
Potential Impact
The vulnerability allows unauthorized disclosure of data returned by __toString() methods on objects accessible in the sandboxed template context. This is a policy enforcement gap that can lead to information leakage within sandboxed Twig templates. Direct output of objects is correctly blocked, so the impact is limited to dynamic mapping keys used as string keys in arrays.
Mitigation Recommendations
A fix is available in twig/twig version 3.27.0 that properly enforces sandbox __toString() policy on dynamic mapping keys. Users should upgrade to version 3.27.0 or later to remediate this vulnerability. No other mitigation is indicated.
GHSA-5v5v-ww74-355v: Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
Description
A vulnerability in twig/twig prior to version 3.27.0 allows sandboxed templates to bypass the sandbox __toString() policy via dynamic mapping keys. This occurs because dynamic keys in array expressions were not properly checked before PHP coerced them to strings, enabling unauthorized __toString() calls. The issue was fixed by marking dynamic mapping keys as string-coercion sites, ensuring sandbox policy enforcement before string conversion.
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
This vulnerability is a residual bypass of a previous fix for unguarded __toString() calls in twig/twig. In version 3.26.0, the sandbox visitor was extended to wrap child nodes coerced to strings with a check node, but ArrayExpression did not implement the required interface for its dynamic mapping keys. When a dynamic key resolves to a Stringable object, PHP invokes __toString() directly without sandbox policy checks, allowing sandboxed template authors to trigger __toString() on any object reachable in the render context. The fix in version 3.27.0 adds the interface to ArrayExpression's dynamic keys, ensuring sandbox policy checks occur before string coercion, closing the enforcement gap.
Potential Impact
The vulnerability allows unauthorized disclosure of data returned by __toString() methods on objects accessible in the sandboxed template context. This is a policy enforcement gap that can lead to information leakage within sandboxed Twig templates. Direct output of objects is correctly blocked, so the impact is limited to dynamic mapping keys used as string keys in arrays.
Mitigation Recommendations
A fix is available in twig/twig version 3.27.0 that properly enforces sandbox __toString() policy on dynamic mapping keys. Users should upgrade to version 3.27.0 or later to remediate this vulnerability. No other mitigation is indicated.
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-5v5v-ww74-355v
- Osv Schema Version
- 1.4.0
- Aliases
- ["CVE-2026-48806"]
- Ecosystems
- ["Packagist"]
- Database Specific Severity
- MODERATE
- Cvss Version
- null
Threat ID: 6a4452e027e9c797198e108d
Added to database: 06/30/2026, 23:36:00 UTC
Last enriched: 06/30/2026, 23:47:14 UTC
Last updated: 06/30/2026, 23:47:14 UTC
Views: 2
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.