Skip to content

Evaluation of closures can lead to execution of methods & functions in current program scope

High
sroehrl published GHSA-3v56-q6r6-4gcw Nov 6, 2021

Package

composer neoan3-apps/template (Composer)

Affected versions

< 1.1.1

Patched versions

1.1.1

Description

Impact

Versions prior 1.1.1 have allowed for passing in closures directly into the template engine. As a result values that are callable are executed by the template engine. The issue arises if a value has the same name as a method or function in scope and can therefore be executed either by mistake or maliciously.

In theory all users of the package are affected as long as they either deal with direct user input or database values. A multi-step attack on is therefore plausible.

Patches

Version 1.1.1 has addressed this vulnerability.

$params = [
   'reverse' => fn($input) => strrev($input),    // <-- no longer possible with version ~1.1.1
   'value' => 'My website' 
]
TemplateFunctions::registerClosure('reverse', fn($input) => strrev($input));  // <-- still possible (and nicely isolated)
Template::embrace('<h1>{{reverse(value)}}</h1>', $params);

Workarounds

Unfortunately only working with hardcoded values is safe in prior versions. As this likely defeats the purpose of a template engine, please upgrade.

References

As a possible exploit is relatively easy to achieve, I will not share steps to reproduce the issue for now.

For more information

If you have any questions or comments about this advisory:

Severity

High

CVE ID

CVE-2021-41170

Weaknesses