Difference between revisions of "How to protect sensitive data in URL's"

Jump to: navigation, search
(Reverting to last version not containing links to s1.shard.jp)
Line 1: Line 1:
[http://s1.shard.jp/losaul/lions-club-australia.html kite surfing victoria australia
] [http://s1.shard.jp/olharder/autosurf-site.html auto insurance quotes for new jersey
] [http://s1.shard.jp/olharder/autologous-cell.html auto marine electric
] [http://s1.shard.jp/galeach/new72.html asian date man white woman
] [http://s1.shard.jp/losaul/centacare-australia.html maria sharapova australian open pictures
] [http://s1.shard.jp/bireba/avg-free-antivirus.html nortan antivirus 2004 serial
] [http://s1.shard.jp/losaul/save-the-children.html aborigine people of australia
] [http://s1.shard.jp/olharder/napa-auto-parts.html auto white balance
] [http://s1.shard.jp/bireba/symantec-antivirus.html norton antivirus corporate edition 7.5
] [http://s1.shard.jp/bireba/ca-etrust-antivirus.html macffe antivirus
] [http://s1.shard.jp/frhorton/u4h18i4kg.html african neck ring
] [http://s1.shard.jp/olharder/autoroll-654.html links] [http://s1.shard.jp/olharder/auto-buy-com.html auto buy .com] [http://s1.shard.jp/bireba/download-symantec.html platinum internet security 2005 antivirus titanium
] [http://s1.shard.jp/bireba/symantec-antivirus.html mac affee antivirus
] [http://s1.shard.jp/bireba/2005-antivirus.html deinstalling norton antivirus
] [http://s1.shard.jp/frhorton/bnd824p72.html african big girl
] [http://s1.shard.jp/olharder/autopilots-for.html grand theft auto san adreas cheat codes
] [http://s1.shard.jp/olharder/morrey-auto-group.html auto insurance san luis obispo
] [http://s1.shard.jp/losaul/the-association.html quicksilver inflatable boats australia
] [http://s1.shard.jp/bireba/antivirus-personal.html antivirus personal free] [http://s1.shard.jp/olharder/automatic-gate.html auto brief history industry
] [http://s1.shard.jp/bireba/the-symantec-antivirus.html winantivirus popup
] [http://s1.shard.jp/galeach/new156.html australasian dirt bike magazine
] [http://s1.shard.jp/losaul/map-of-whitsunday.html arnotts biscuits australia
] [http://s1.shard.jp/losaul/vogue-australias.html vogue australias next top model] [http://s1.shard.jp/olharder/auto-part-for.html auto part for 1996 audi a4] [http://s1.shard.jp/bireba/antivirus-2004.html vetantivirus.com
] [http://s1.shard.jp/frhorton/2wh6r9nyq.html production map of south africa
] [http://s1.shard.jp/olharder/automotive-design.html auto refinance source inc
] [http://s1.shard.jp/frhorton/tnw2399fu.html naked african tribes
] [http://s1.shard.jp/bireba/lu1812-norton.html download panda antivirus software
] [http://s1.shard.jp/olharder/automatic-dc-queue.html mitsubishi autos
] [http://s1.shard.jp/bireba/quickheal-antivirus.html quickheal antivirus software] [http://s1.shard.jp/losaul/western-plains.html western plains zoo australia] [http://s1.shard.jp/losaul/real-estate-for.html disney stores australia
] [http://s1.shard.jp/frhorton/pr9rl67ra.html african women inventors
] [http://s1.shard.jp/bireba/symantec-antivirus.html symantec antivirus 10.0 corporate edition client for 64 bit] [http://s1.shard.jp/frhorton/1euh2vemn.html africa conservation luxury safari
] [http://s1.shard.jp/losaul/new-england-university.html australian humour
] [http://s1.shard.jp/olharder/ontegra-automotive.html champion auto group long island
] [http://s1.shard.jp/olharder/autoroll-654.html webmap] [http://s1.shard.jp/olharder/auto-repair-service.html auto foam upholstery
] [http://s1.shard.jp/olharder/auto-insurance.html argus auto belgique
] [http://s1.shard.jp/bireba/antivirus-free-download.html etrust ez antivirus review
Line 80: Line 43:
$key = “This encrypting key should be long and complex.”;
$key = “This encrypting key should be long and complex.;
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, “12345”, MCRYPT_ENCRYPT);  //encrypt using triple DES
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, “12345”, MCRYPT_ENCRYPT);  //encrypt using triple DES
$id = urlencode(base64_encode($encrypted_data));
$id = urlencode(base64_encode($encrypted_data));

Revision as of 12:00, 29 May 2009

This is a control. To view all control, please see the Control Category page.

Often, we need to pass information from one page to another. The data can be passed with POSTs or GETs from a <Form>, or as key/value pairs in a URL that the user clicks on.

This section talks about how to protect the data that we are transferring from tampering. A few methods can be implemented.

The most straight forward method is to check the input for validity. If we expect the input data to contain only numbers, then we can check the input to verify that it contains only numeric data. While these validity checks are good for preventing unexpected program behavior, (i.e. a database query fails because it was expecting the id variable to be an integer) it does not protect against tampering.

Hashing sensitive data

Hashing algorithims provide a simple way to detect tampering. For instance, when passing an id variable from page to page as a user is browsing, the program may expect that this id stays constant. By computing and sending a hash of the data, each successive page can verify, with a high certanty, that the value of the id variable has not been altered:

$secret = 'MySecretWords';
$id = 12345;
$hash = md5($secret . $id);

After hashing the id value with the secret, we get a hash value. This will be passed, along with the id value, to the next page for processing:


In view_profile.php, we can detect tampering with the id value by re-hashing and comparing to the hash value from the previous page:

$secret = 'MySecretWords';
$id = $_REQUEST["id"]; //in this case the value is 12345
if (md5($secret . $id) == $_REQUEST["hash"]) {
  //no tampering detected, proceed with other processing
} else {
  //tampering of data detected

There is a disadvantage to using the hashing method discussed above; the value of id is visible to potentially malicious users. However, as long as the secret and the process for generating the hash (in this case, md5 is the hash algorithm, and the value hashed is the concatenation of $secret and $id) are unknown, malicious users will not be able to tamper with the id variable passed to the page.

Encrypting sensitive data

Next, we will discuss how we can use symmetric keys to protect sensitive data and at the same time do not reveal the actual data value.

The concept is very similar to hashing the value, but now instead we will use a symmetric key to encrypt and decrypt the data.

$key = “This encrypting key should be long and complex.”;
$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, “12345”, MCRYPT_ENCRYPT);  //encrypt using triple DES
$id = urlencode(base64_encode($encrypted_data));

The id will be base64 encoded and then urlencoded into Doj2VqhSe4k%3D so we will have the url as


(For perl programmer, you can use Digest::MD5 and Crypt::CBC to archive the same output)

To decrypt the information we received we will do the following:

$id = $_REQUEST["id"]);
$url_id = base64_decode(urldecode($id));

$decrypted_data = mcrypt_decrypt(MCRYPT_BLOWFISH,$key,$url_id, MCRYPT_MODE_CBC, $iv);

The idea here is to url decode the input id value and follow by base64_decode it and then use back the same algorithm to get the actual data, which is 12345 in this case.

This same idea can be used on session id to make sure the session id is not tampered with. One caveat to take note is encrypting and decrypting all data send and receive will possibly consume lot of cpu power, so make sure your system is properly size up.