Skip to content

Commit 8c2c1cb

Browse files
committed
better SSTI in |map and |filter
1 parent 9d01140 commit 8c2c1cb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Diff for: CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
1. [](#new)
55
* Added a new `system.languages.debug` option that adds a `<span class="translate-debug"></span>` around strings translated with `|t`. This can be styled by the theme as needed.
6+
1. [](#improved)
7+
* More robust SSTI handling in `|filter` and `|map`
68
1. [](#bugfix)
7-
* * Fixed Twig `|map()` allowing code execution
9+
* Fixed Twig `|map()` allowing code execution
810

911
# v1.7.41.2
1012
## 06/01/2023

Diff for: system/src/Grav/Common/Twig/Extension/GravExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ public function ofTypeFunc($var, $typeTest = null, $className = null)
17081708
*/
17091709
function filterFilter(Environment $env, $array, $arrow)
17101710
{
1711-
if (is_string($arrow) && Utils::isDangerousFunction($arrow)) {
1711+
if (!$arrow instanceof \Closure && !is_string($arrow) || Utils::isDangerousFunction($arrow)) {
17121712
throw new RuntimeError('Twig |filter("' . $arrow . '") is not allowed.');
17131713
}
17141714

@@ -1724,7 +1724,7 @@ function filterFilter(Environment $env, $array, $arrow)
17241724
*/
17251725
function mapFilter(Environment $env, $array, $arrow)
17261726
{
1727-
if (is_string($arrow) && Utils::isDangerousFunction($arrow)) {
1727+
if (!$arrow instanceof \Closure && !is_string($arrow) || Utils::isDangerousFunction($arrow)) {
17281728
throw new RuntimeError('Twig |map("' . $arrow . '") is not allowed.');
17291729
}
17301730

Diff for: system/src/Grav/Common/Utils.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -1950,10 +1950,10 @@ public static function getSupportPageTypes(array $defaults = null)
19501950
}
19511951

19521952
/**
1953-
* @param string $name
1953+
* @param string|array $name
19541954
* @return bool
19551955
*/
1956-
public static function isDangerousFunction(string $name): bool
1956+
public static function isDangerousFunction($name): bool
19571957
{
19581958
static $commandExecutionFunctions = [
19591959
'exec',
@@ -2050,6 +2050,10 @@ public static function isDangerousFunction(string $name): bool
20502050
'posix_setuid',
20512051
];
20522052

2053+
if (is_array($name) || strpos($name, ":") !== false) {
2054+
return false;
2055+
}
2056+
20532057
if (in_array($name, $commandExecutionFunctions)) {
20542058
return true;
20552059
}

0 commit comments

Comments
 (0)