Why is PHP 7 eval() still not safe after strict preg_match?
So I have a code that strictly filters so that only operators, parenthesis, and numbers are allowed. People still seem to be against using it, but no one has explained to me specifically why, other than "Oh it is dangerous."
So how can one exploit the below code for example?
The following program
1. grabs query string from the URL
2. Filters it through preg_match
3. eval()
<?php
$exp = $_SERVER["QUERY_STRING"];
if(preg_match('~^[0-9()+\-*\/]+$~', $exp)){
eval("echo $exp;");
} else {
echo "ERROR";
}
?>
Edit: https://www.exakat.io/land-where-php-uses-eval/
This website also talks about how eval()
could be used for Evaluating math or logical expression
Is this wrong?