CVE-2022-23614

8.8 HIGH

📋 TL;DR

CVE-2022-23614 is a code injection vulnerability in Twig's sandbox mode that allows attackers to execute arbitrary PHP functions when using the sort filter with a non-closure arrow parameter. This affects PHP applications using Twig templates with sandbox mode enabled. The vulnerability could lead to remote code execution on affected systems.

💻 Affected Systems

Products:
  • Twig (PHP template engine)
Versions: Twig versions before 3.3.8 and 2.15.3
Operating Systems: All operating systems running PHP with Twig
Default Config Vulnerable: ✅ No
Notes: Only vulnerable when sandbox mode is enabled and the sort filter is used with user-controlled input for the arrow parameter.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete system compromise, data theft, and lateral movement within the network.

🟠

Likely Case

Arbitrary PHP code execution allowing attackers to read sensitive files, modify application behavior, or establish persistence.

🟢

If Mitigated

Limited impact if sandbox mode is disabled or proper input validation prevents malicious payloads from reaching the vulnerable filter.

🌐 Internet-Facing: HIGH - Web applications using Twig templates are typically internet-facing and could be directly exploited.
🏢 Internal Only: MEDIUM - Internal applications could be exploited by authenticated users or through other attack vectors.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires access to template rendering with user-controlled input in sandbox mode. Public proof-of-concept code is available in the advisory.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Twig 3.3.8 and 2.15.3

Vendor Advisory: https://github.com/twigphp/Twig/security/advisories/GHSA-5mv2-rx3q-4w2v

Restart Required: No

Instructions:

1. Update Twig via Composer: 'composer require twig/twig:^3.3.8' or 'composer require twig/twig:^2.15.3'. 2. Verify the update with 'composer show twig/twig'. 3. Clear any template caches if applicable.

🔧 Temporary Workarounds

Disable sandbox mode

all

Temporarily disable Twig sandbox mode if not required, though this reduces security for other threats.

Input validation for sort filter

all

Validate and sanitize all user input passed to the sort filter's arrow parameter.

🧯 If You Can't Patch

  • Implement strict input validation for all template variables, especially those used with the sort filter.
  • Use web application firewalls (WAF) to block suspicious patterns and restrict access to vulnerable endpoints.

🔍 How to Verify

Check if Vulnerable:

Check Twig version via Composer: 'composer show twig/twig | grep version'. If version is below 3.3.8 (for v3) or 2.15.3 (for v2), and sandbox mode is enabled, the system is vulnerable.

Check Version:

composer show twig/twig | grep version

Verify Fix Applied:

After updating, verify version is 3.3.8+ or 2.15.3+ with 'composer show twig/twig'. Test template rendering with controlled inputs to ensure no code execution occurs.

📡 Detection & Monitoring

Log Indicators:

  • Unusual PHP function calls in template rendering logs
  • Errors related to sort filter parameter validation
  • Unexpected process execution from web server context

Network Indicators:

  • HTTP requests with malicious payloads targeting template endpoints
  • Outbound connections from web server to suspicious IPs

SIEM Query:

source="web_logs" AND (uri="*twig*" OR uri="*template*") AND (message="*sort*" OR message="*arrow*") AND status=200

🔗 References

📤 Share & Export