Salve a tutti,
Una domanda che potrebbe sembrare un pò cretina:
Volendo evitare che in un $_GET possa essere passato stringhe che siano poi dannose non è possible fare la cosa seguente?:
Codice PHP:
define(SECRET_KEY,"una qualunques stringa con numeri e()6778a888a890");
function create_hash($array)
{
$data = '';
/* Construct the string with our key/value pairs */
foreach ($array as $key => $value) {
$data .= $key . $value;
}
$h = new Crypt_HMAC(SECRET_KEY, 'md5');
$hash = $h->hash($data);
return $hash;
}
function BuiltLink($uri,$params)
{
return ($uri.'?'.$params);
}
function create_parameters($array)
{
$data = '';
$ret = array();
/* Construct the string with our key/value pairs */
foreach ($array as $key => $value) {
$data .= $key . $value;
$ret[] = "$key=$value";
}
$h = new Crypt_HMAC(SECRET_KEY, 'md5');
$hash = $h->hash($data);
$ret[] = "hash=$hash";
return join ("&", $ret);
}
function verify_parameters($array)
{
$data = '';
$ret = array();
/* Store the hash in a separate variable and unset the hash from
* the array itself (as it was not used in constructing the hash
*/
$hash = $array['hash'];
unset ($array['hash']);
/* Construct the string with our key/value pairs */
foreach ($array as $key => $value) {
$data .= $key . $value;
$ret[] = "$key=$value";
}
$h = new Crypt_HMAC(SECRET_KEY, 'md5');
if ($hash != $h->hash($data)) {
return FALSE;
} else {
return TRUE;
}
}
In ogni script
il primo comando è:
Codice PHP:
if (tep_is_null($_GET) {
........
} else
if (!verify_parameters($_GET)) { die(PARAMETRI_NOT_OK);}
se nelle varie pagine dove faccio i link costruisco il link nel modo seguente:
Codice PHP:
$k = array ("page" => "nome",
"application" => $_SESSION["application"],
"action" => "begin",
"id" => Get_session_id());
$link=BuiltLink (INDEX,create_parameters($k));
Evito o no qualsiasi possibilità di trasformare i miei get con attraverso il Cross-site scripting ?
Grazie per l'aiuto
Paolo