Skip to content

Commit

Permalink
Sandbox foreachVars in templates
Browse files Browse the repository at this point in the history
Nesting the same template inside a `foreach` loop that is also accessed inside the nested call will overwrite the values from the outer template due to identical identifiers being used.

The sandbox did not protected `$this->foreachVars` despite being stateful.

See #4431
Fixes #4444
  • Loading branch information
dtdesign committed Sep 8, 2021
1 parent 7dc40d2 commit 99c6a1a
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,11 @@ public function getPluginClassName($type, $tag) {
* Enables execution in sandbox.
*/
public function enableSandbox() {
$index = count($this->sandboxVars);
$this->sandboxVars[$index] = $this->v;
$index = \count($this->sandboxVars);
$this->sandboxVars[$index] = [
'foreachVars' => $this->foreachVars,
'v' => $this->v,
];
}

/**
Expand All @@ -532,8 +535,10 @@ public function disableSandbox() {
if (empty($this->sandboxVars)) {
throw new SystemException('TemplateEngine is currently not running in a sandbox.');
}

$this->v = array_pop($this->sandboxVars);

$values = \array_pop($this->sandboxVars);
$this->foreachVars = $values['foreachVars'];
$this->v = $values['v'];
}

/**
Expand Down

0 comments on commit 99c6a1a

Please sign in to comment.