I am just reviewing a script I want to use for my website. The author filters all user entered data ($_POST
and $_GET
) with this function:
function XSSCheck($value) {
return preg_replace(
array('/&(?!amp;|quot;|nbsp;|gt;|lt;|laquo;|raquo;|copy;|reg;|#[0-9]{1,5};|#x[0-9A-F]{1,4};)/', '/#(?![0-9]{1,5};|x[0-9A-F]{1,4};)/', '|<|', '|>|', '|"|', "|'|" ),
array('&', '#', '<', '>', '"', '''),
stripslashes($value)
);
}
If I filter a string with that, is it possible to inject into this SQL query for example?
SELECT * FROM table WHERE ID = '{$_REQUEST['id']}'
I tried it already but did not find out any way to do so. Does anybody know an alternative or is this code secure?
If it is secure, what are the (dis)advantages to mysqli_real_escape_string()
? Should I change the projects code to the official function?
EDIT: You voted down my question, request to close it and sayed the code is bad. But no one has given me any example, how code can be injected! I do not think there is a way.