10 points · by brianr · 18y ago · 21 comments
I don't really know anything about hashing... my ideas so far are to use the last 20 bits of MD5, or maybe the first 20 bits of Adler32. Even distribution is more important than speed. Can anyone offer any advice here?
Weaker options may or may not be secure; speaking as someone who is professionally paranoid, I suggest not trying to invent your own mechanisms. If you don't have an implementation of HMAC-SHA256 readily available, HMAC-SHA1 or HMAC-MD5 are probably adequate, depending on how paranoid you are. (Or if C code works for you, let me know and I'll point you towards my BSD licensed HMAC-SHA256 code.)
If the user has to login to your application, couldn't you just limit it based on that? Or by IP address? (of course that won't help against DDOS, but that's another problem all together...)
As far as hashing algorithms go, if you're just trying to keep an attacker from pounding your server in a DOS attack, any of the SHA1, SHA2, or MD5 should be fine, since even though there may be weaknesses, in reality it takes a long time to find collisions.
The legitimate URLs are for 'static' images (static in the sense that once they have been generated, they will never need to be generated again) that are stored on disk using the filesystem. For example, an image url might look like:
http://example.com/1e/2f/c/(image generation parameters).png
The idea is that 1e2fc (the hash) serves as both the path on disk (so that files are roughly evenly distributed among the 2^20 directories) and as a checksum to prevent DOS.That is more of a crawl that you are trying to prevent, which could be quite taxing on your system but it is not intended to be.
So, that being said, your approach should be roughly good enough to prevent that.