Skip to content

Commit 3f8fbc4

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

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/Latte/Compiler/PhpWriter.php

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

229+
} elseif (
230+
$tokens->isCurrent($tokens::T_STRING)
231+
&& $tokenValue[0] === '"'
232+
&& (strpos($tokenValue, '{$') !== false || strpos($tokenValue, '${') !== false)
233+
) {
234+
throw new CompileException('Forbidden complex expressions in strings.');
235+
229236
} elseif (
230237
Helpers::startsWith($tokenValue, '$ʟ_')
231238
|| ($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)