I have a webpage with a query string.
In PHP I have:
$querystring=$_SERVER["QUERY_STRING"];
echo "<html><head></head><body>
<a href='index.php?$querystring'>test</a>
</body></html>";
Do I need to sanitize the querystring?
If yes, how do I sanitize and what are some possible attacks if I don’t?
You should use
htmlspecialchars($query, ENT_QUOTES)to prevent any XSS attacks.But still, you should white list any parameters, because a smart attacker could forge a query and attempt a CSRF attack.