I need to vent a little guys!
I have just been asked to look at a PHP script that takes a number of arguments via $_GET, loads some data from the database, and then checks that a checksum (also passed via $_GET) matches, before deciding to display the information or not. Fairly straightforward (though I do NOT approve of only using an auth key in the URL) but then I stumbled upon something like this:
if ($_GET['hash'] !== $calculatedHash){
die('Incorrect hash '.$_GET['hash'].' - Should be '.$calculatedHash);
} ...
Now, apart from the fact that the guy who wrote this is clearly a tool, how’s about we turn this in to a positive for new developers to teach them why NOT to do this? How about one point per person?
I’ll start with why I disagree with passing any kind of auth-token in a URL when it’s the only method required:
It’s far too easy to allow people access who shouldn’t be able to. Your URLs could be recorded on a proxy or a firewall log. They could be captured in the history of the browser that you just used at the coffee shop. If someone can work out the logic involved in generating the hash (ie it’s something as simple as md5($firstname.$lastname)) then they’ll be able to get in to your system and look at pretty much anything that they want. If you send the link by email then what happens if it’s intercepted somehow? Gets redirected or sent to the wrong address? If it’s sensitive data then even more so than ever, you should verify that a person is who they claim to be. So even if you do pass some easily cracked hash via URL, then have the user confirm that they are who they say they are with a password, or a one-time-key that you can email or SMS to them when the page is loaded (so only genuine users intended to receive the email can view it).
Anyone else care to add comment?