Skip to content

Commit 9d01140

Browse files
committed
Fix for dangerous tags in |map filter
1 parent 259e775 commit 9d01140

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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. [](#bugfix)
7+
* * Fixed Twig `|map()` allowing code execution
68

79
# v1.7.41.2
810
## 06/01/2023

system/src/Grav/Common/Twig/Extension/GravExtension.php

+17
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public function getFilters(): array
173173

174174
// Security fix
175175
new TwigFilter('filter', [$this, 'filterFilter'], ['needs_environment' => true]),
176+
new TwigFilter('map', [$this, 'mapFilter'], ['needs_environment' => true]),
176177
];
177178
}
178179

@@ -1713,4 +1714,20 @@ function filterFilter(Environment $env, $array, $arrow)
17131714

17141715
return twig_array_filter($env, $array, $arrow);
17151716
}
1717+
1718+
/**
1719+
* @param Environment $env
1720+
* @param array $array
1721+
* @param callable|string $arrow
1722+
* @return array|CallbackFilterIterator
1723+
* @throws RuntimeError
1724+
*/
1725+
function mapFilter(Environment $env, $array, $arrow)
1726+
{
1727+
if (is_string($arrow) && Utils::isDangerousFunction($arrow)) {
1728+
throw new RuntimeError('Twig |map("' . $arrow . '") is not allowed.');
1729+
}
1730+
1731+
return twig_array_map($env, $array, $arrow);
1732+
}
17161733
}

0 commit comments

Comments
 (0)