No, double-URL-decoding your input (which is effectively what urldecode($_GET['param'])
does, since the values in $_GET
have already been URL-decoded) does nothing to prevent any kind of injection attacks. After all, the following identity holds for all strings:
$string === urldecode( urlencode( $string ) )
Thus, if an attacker wants to feed you any string as input, all they need to do to work around your extra urldecode()
is to URL-encode the input string.
Using urlencode()
(once!) on strings which you want to include in a URL is, of course, the right thing to do in any case, since it ensures that the resulting URL will be well-formed and that the parameters in it will be correctly decoded by PHP when it populates the $_GET
array. There's generally no point in URL-encoding anything twice, however.