Skip to main content

CVE-2022-23614: CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') in twigphp Twig

Medium
Published: Fri Feb 04 2022 (02/04/2022, 22:25:11 UTC)
Source: CVE
Vendor/Project: twigphp
Product: Twig

Description

Twig is an open source template language for PHP. When in a sandbox mode, the `arrow` parameter of the `sort` filter must be a closure to avoid attackers being able to run arbitrary PHP functions. In affected versions this constraint was not properly enforced and could lead to code injection of arbitrary PHP code. Patched versions now disallow calling non Closure in the `sort` filter as is the case for some other filters. Users are advised to upgrade.

AI-Powered Analysis

AILast updated: 06/23/2025, 17:48:01 UTC

Technical Analysis

CVE-2022-23614 is a code injection vulnerability in Twig, an open-source templating engine widely used in PHP applications. Twig allows developers to separate application logic from presentation by using templates. The vulnerability arises in the sandbox mode of Twig, specifically in the implementation of the `sort` filter. The `sort` filter accepts an `arrow` parameter, which is intended to be a closure (anonymous function) to define custom sorting behavior. However, in affected versions (Twig >= 3.0.0 and < 3.3.8, and >= 2.0.0 and < 2.14.11), the enforcement that the `arrow` parameter must be a closure was insufficient. This flaw allows attackers to pass non-closure values, potentially enabling the execution of arbitrary PHP code within the context of the application. This improper neutralization of special elements (CWE-74) leads to a code injection vulnerability, which can compromise the confidentiality, integrity, and availability of the affected system. The vulnerability was addressed by disallowing non-closure calls in the `sort` filter, aligning it with the behavior of other filters in Twig. No known exploits have been reported in the wild to date, but the risk remains significant due to the potential for remote code execution if an attacker can control template inputs or parameters. Users of affected Twig versions are strongly advised to upgrade to patched versions to mitigate this risk.

Potential Impact

For European organizations, the impact of this vulnerability can be substantial, especially for those relying on PHP-based web applications that utilize Twig for templating. Successful exploitation could allow attackers to execute arbitrary PHP code, leading to full system compromise, data theft, defacement, or disruption of services. This is particularly critical for sectors handling sensitive data such as finance, healthcare, government, and e-commerce. The vulnerability undermines the integrity and confidentiality of applications and can lead to significant reputational damage and regulatory penalties under GDPR if personal data is exposed. Additionally, availability may be impacted if attackers deploy ransomware or disrupt services. Since Twig is commonly used in popular PHP frameworks and CMS platforms, the scope of affected systems is broad, increasing the potential attack surface within European enterprises. The absence of known exploits suggests that proactive patching can effectively prevent exploitation, but the medium severity rating indicates that organizations should prioritize remediation to avoid potential future attacks.

Mitigation Recommendations

1. Immediate upgrade to the latest patched versions of Twig (>= 3.3.8 or >= 2.14.11) to ensure the `sort` filter enforces closure-only parameters. 2. Conduct a thorough audit of all PHP applications using Twig to identify affected versions and usage of the `sort` filter, especially in sandbox mode. 3. Implement strict input validation and sanitization on any user-controllable data that might influence template parameters to reduce injection risk. 4. Employ runtime application self-protection (RASP) or web application firewalls (WAF) with custom rules to detect and block suspicious template injection attempts. 5. Review and restrict PHP function execution permissions and disable dangerous PHP functions where feasible to limit impact of potential code execution. 6. Monitor application logs for unusual behavior or errors related to template processing that could indicate exploitation attempts. 7. Educate development teams on secure template usage and the risks of improper closure handling in Twig filters. 8. Integrate Twig version checks into continuous integration pipelines to prevent deployment of vulnerable versions.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-01-19T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9842c4522896dcbf23e6

Added to database: 5/21/2025, 9:09:22 AM

Last enriched: 6/23/2025, 5:48:01 PM

Last updated: 7/27/2025, 12:13:19 AM

Views: 10

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats