Open
Description
Description
$pattern = '/[[name]]/';
$template = 'My name is [[name]]';
preg_replace($pattern, $_POST['name'], $template);
This is prone to injection of any match from the pattern if user supplies for example Tomas$1Fejfar
. There is a preg_quote function that can be used to escape special chars in template. There should be same function that would escape the replacement.
preg_quote_replacement($_POST['name']); // Tomas\$1Fejfar
IMHO it is enough to escape backslash and dollars with backslash, but I am not sure.
Currently the replacement must be escaped using userland function that makes it prone to mistakes.