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

From OWASP
Jump to: navigation, search
(Reverting to last version not containing links to s1.shard.jp)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[http://s1.shard.jp/frhorton/ocdp2flvo.html african leaf violet
 
] [http://s1.shard.jp/olharder/autoroll-654.html webmap] [http://s1.shard.jp/olharder/ak-auto-long.html automatic bibliography composers
 
] [http://s1.shard.jp/olharder/j-b-auto-salvage.html auto dumfries insurance
 
] [http://s1.shard.jp/olharder/value-of-groucho.html automotive electric fuel pump
 
] [http://s1.shard.jp/olharder/bxautozip.html auto market shares
 
] [http://s1.shard.jp/losaul/australian-walkabout.html australian walkabout inn bb] [http://s1.shard.jp/olharder/autoroll-654.html links] [http://s1.shard.jp/bireba/computer-antivirus.html norton antivirus 2005 cracked
 
] [http://s1.shard.jp/frhorton/u4h18i4kg.html africas capitals and countries
 
] [http://s1.shard.jp/losaul/south-african.html australian universities rankings
 
] [http://s1.shard.jp/bireba/antivirus-appliance.html house call antivirus free
 
] [http://s1.shard.jp/olharder/autoroll-654.html sitemap] [http://s1.shard.jp/olharder/autoroll-654.html index] [http://s1.shard.jp/losaul/australian-music.html mathers shoes australia
 
] [http://s1.shard.jp/losaul/australia-bank-fee.html australian meals made through the gold rush
 
] [http://s1.shard.jp/bireba/avg-60-antivirus.html avg 6.0 antivirus serial number] [http://s1.shard.jp/frhorton/x5dh8y75v.html art of african american man
 
] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/galeach/new67.html jewelry news asia
 
] [http://s1.shard.jp/losaul/moosehead-beer.html immigration australia and australia visa travel services
 
] [http://s1.shard.jp/losaul/australia-behringer.html travel voltage adapter for australia
 
] [http://s1.shard.jp/galeach/new161.html outdoor asian cooking
 
] [http://s1.shard.jp/frhorton/lt8tyfnvp.html african hymnals
 
] [http://s1.shard.jp/bireba/panda-software.html kasperskys antivirus firewall
 
] [http://s1.shard.jp/frhorton/rm22odke6.html african american braids styles] [http://s1.shard.jp/bireba/antivirus-comparison.html antivirus software adaware
 
] [http://s1.shard.jp/olharder/auto-emissions-test.html auto fenders part
 
] [http://s1.shard.jp/frhorton/1oj3zcvfn.html africa shox
 
] [http://s1.shard.jp/olharder/grand-theft-auto.html grand theft auto vice city pc download] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/frhorton/1aei449pv.html 5th test south africa england
 
] [http://s1.shard.jp/olharder/dariusz-wolski.html automobile spoiler
 
] [http://s1.shard.jp/olharder/pyles-auto-sales.html epinephrine auto injector
 
] [http://s1.shard.jp/losaul/used-car-price.html north ryde sydney australia
 
] [http://s1.shard.jp/galeach/new59.html a map of europe and asia
 
] [http://s1.shard.jp/losaul/australian-club.html car seat baby capsule australia
 
] [http://s1.shard.jp/losaul/auction-houses.html auction houses south australia] [http://s1.shard.jp/galeach/new16.html maps of europe and asia in the 1800's
 
] [http://s1.shard.jp/frhorton/9mxpl8xy1.html 10 african american inventor top
 
] [http://s1.shard.jp/frhorton/mz6vv73zx.html vandals in north africa
 
] [http://s1.shard.jp/bireba/antiviruscom.html symantec antivirus client removal tool
 
] [http://s1.shard.jp/olharder/autoroll-654.html site] [http://s1.shard.jp/bireba/antivirus-trials.html new antiviruses
 
] [http://s1.shard.jp/frhorton/54k2pi876.html african orphanage
 
] [http://s1.shard.jp/galeach/new101.html tales of phantasia ova
 
] [http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/olharder/autoroll-654.html map] [http://s1.shard.jp/olharder/automobile-essai.html auto inspection ny state
 
] [http://s1.shard.jp/olharder/pioneer-auto-part.html indiana autorv
 
 
 
{{Template:Control}}
 
{{Template:Control}}
  
Line 80: Line 43:
  
 
<pre>
 
<pre>
$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));
 
</pre>
 
</pre>

Latest revision as of 07: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:

http://www.example.com/view_profile?id=12345&hash=d6b0ab7f1c8ab8f514db9a6d85de160a

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

http://www.example.com/view_profile?id=Doj2VqhSe4k%3D

(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.