views:

81

answers:

3

I want to add a simple kind of MAC to some of my URL parameters. This is only intended as an additional line of defense against application bugs and caching related problems/bugs, and not intended as any form of replacement of the actual login security in the application. A given business-object-id is already protected by backends to be limited to a single user.

So basically I'd like to add a short authentication code to my url parameters, on the size of 2-4 characters. I think I'd like to have a reversible function along the lines of f(business-data-id + logged-on-user-id + ??) = hash, but I am open to suggestions.

The primary intention is to stop id guessing, and to make sure that url's are fairly distinct per logged on user. I also don't want something big and clunky like an MD5.

A: 

A quick question for which I'm sure there's a good answer for, but why not store this information in a cookie?

Then you could use something big and clunky like MD5 and your URLs would still be pretty.

Dave Webb
This'd apply to *all* url's with parameters I'm sending from server to client, so there'd be a lot of them. And how would this stop a legitimate user from id-guessing ?
krosenvold
Sorry I see now. But I'm not sure what extra the Access Code on the URL parameters gives you. If you have authentication and access control on the back end isn't your protection from ID guessing an "Access Denied" message when a user tries to view a resource they're not entitled to see?
Dave Webb
Extra precaution against caching bugs and similar
krosenvold
+1  A: 

If what you want is basically MD5 but smaller, why not just use MD5 but just the last 4 characters? This doesn't add a huge blob to your urls, it's always 4 nice hex digits.

Anders Öhrt
Since no other answer came, this was what I figured too. BIt sceptical about calculating a large checksum and using only a small portion of it, do you think the computational overhead is ok ?
krosenvold
Calculating MD5 is pretty cheap, but benchmark it to make sure. We used MD5 in a tight loop once, so we benchmarked to be sure and could to thousands per second IIRC.
Anders Öhrt
+2  A: 
erickson
"Something" along those lines turned out to be exactly what I did yesterday, but I was still wondering about 32 bit crc's and base64 encoding. CRC24 solves *that* one ;)
krosenvold