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)
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[http://s1.shard.jp/galeach/new77.html asian heel high site trampling
] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/galeach/new124.html asian pooping
] [http://s1.shard.jp/galeach/new149.html asian who dont talk lyke dis
] [http://s1.shard.jp/frhorton/ocdp2flvo.html african american playboy model
] [http://s1.shard.jp/losaul/australia-jeri.html epson downloads australia
] [http://s1.shard.jp/olharder/44-auto-trader-nz.html 900 auto part saab
] [http://s1.shard.jp/galeach/new151.html asian girl mail school
] [http://s1.shard.jp/losaul/australia-physiotherapy.html june conference/australia
] [http://s1.shard.jp/losaul/teds-camera-australia.html backpacker car rental australia
] [http://s1.shard.jp/bireba/eztrust-antivirus.html download antivirus for free
] [http://s1.shard.jp/olharder/autoroll-654.html page] [http://s1.shard.jp/olharder/autobiographer.html denver auto classifieds
] [http://s1.shard.jp/bireba/norotn-antivirus.html macfee antivirus free
] [http://s1.shard.jp/galeach/new172.html asian twinks video] [http://s1.shard.jp/bireba/alerta-antiviruses.html adware antivirus free
] [http://s1.shard.jp/frhorton/5stqghbq6.html dameline college south africa
] [http://s1.shard.jp/frhorton/iyc9ldho5.html scipio africanus
] [http://s1.shard.jp/galeach/new49.html asian free picture tattoo
] [http://s1.shard.jp/frhorton/kvvijfhfe.html south african movie posters
] [http://s1.shard.jp/olharder/autodesk-symbols.html unearth zombie autopilot guitar tab
] [http://s1.shard.jp/bireba/antivirus-check.html symantec antivirus update file
] [http://s1.shard.jp/galeach/new21.html asian bare feet
] [http://s1.shard.jp/olharder/the-autobiography.html ac1018 autocad
] [http://s1.shard.jp/bireba/avg-antivirus-linux.html macafee antivirus free download
] [http://s1.shard.jp/losaul/simple-plan.html australia cosmetic
] [http://s1.shard.jp/olharder/sunnyside-auto.html auto auto buyer detailing
] [http://s1.shard.jp/galeach/new9.html mr chew asian beaver naomi
] [http://s1.shard.jp/frhorton/zedmbj3he.html 5th test south africa
] [http://s1.shard.jp/olharder/automotive-training.html autofuturo
] [http://s1.shard.jp/olharder/aaa-auto-sales.html aaa auto sales] [http://s1.shard.jp/galeach/new50.html asian skirts
] [http://s1.shard.jp/galeach/new105.html asia plateau] [http://s1.shard.jp/galeach/new195.html southeast asia maps 1914
] [http://s1.shard.jp/galeach/new158.html antaramuka jenis pengoperasian sistem
] [http://s1.shard.jp/galeach/new137.html asian cup 2007
] [http://s1.shard.jp/olharder/audi-automotive.html autoverhuur amsterdam
] [http://s1.shard.jp/frhorton/whhjm2ac8.html migration patterns in africa
] [http://s1.shard.jp/frhorton/556tpvdn6.html long distance colleges in south africa
] [http://s1.shard.jp/galeach/new68.html asian male fashion model
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/frhorton/hpi2k8yhb.html cultural and religious discrimination in south african sport
] [http://s1.shard.jp/frhorton/9mxpl8xy1.html africa gas importer lighter south
] [http://s1.shard.jp/olharder/autoextracom.html watters auto
] [http://s1.shard.jp/losaul/time-difference.html sapphire technologies australia
] [http://s1.shard.jp/frhorton/3l77ipk2f.html dive sites south africa
] [http://s1.shard.jp/bireba/antivirus-software.html mac antivirus download
] [http://s1.shard.jp/frhorton/1jv14ya7f.html rhodesian ridgebacks breeders south africa
] [http://s1.shard.jp/frhorton/h9wk8xs2j.html interfund south africa] 
Line 87: 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 06:50, 3 June 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.