Skip to content

Commit 9e1b4f7

Browse files
committed
PhpWriter: complex expression in strings prohibited in sandbox mode
1 parent a69d0b9 commit 9e1b4f7

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Latte/Compiler/PhpWriter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ public function validateTokens(MacroTokens $tokens): void
226226
} elseif ($tokens->isCurrent('`')) {
227227
throw new CompileException('Backtick operator is forbidden in Latte.');
228228

229+
} elseif (
230+
$this->policy
231+
&& $tokens->isCurrent($tokens::T_STRING)
232+
&& $tokenValue[0] === '"'
233+
&& (strpos($tokenValue, '{$') !== false || strpos($tokenValue, '${') !== false)
234+
) {
235+
throw new CompileException('Forbidden complex expressions in strings.');
236+
229237
} elseif (
230238
Helpers::startsWith($tokenValue, '$ʟ_')
231239
|| ($this->policy && $tokens->isCurrent('$this'))

tests/Latte/Policy.violations.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,15 @@ Assert::exception(function () use ($latte) {
128128
Assert::exception(function () use ($latte) {
129129
$latte->compile('{do new stdClass}');
130130
}, Latte\CompileException::class, "Forbidden keyword 'new' inside tag.");
131+
132+
Assert::exception(function () use ($latte) {
133+
$latte->compile('{="{$var}"}');
134+
}, Latte\CompileException::class, 'Forbidden complex expressions in strings.');
135+
136+
Assert::exception(function () use ($latte) {
137+
$latte->compile('{="${var}"}');
138+
}, Latte\CompileException::class, 'Forbidden complex expressions in strings.');
139+
140+
Assert::noError(function () use ($latte) {
141+
$latte->compile('{=\'${var}\'}');
142+
});

0 commit comments

Comments
 (0)