Osm Admin: Don't Obfuscate ID In URL
1 year ago ∙ 1 minute read
Some people worry that providing ID in the URL is bad for security. For example:
- If you see
/orders/?id=9in the browser's URL bar, you can enter
/orders/?id=8manually, and see the order that doesn't belong to you.
- You can easily scrape the whole website by just enumerating through all
id=2, and so on until you start getting 404 responses.
Instead of ID, they propose generating a random GUID, something like
f9224f30-592e-4801-88d4-6790c4ebbbdd, store it in the database record as an unique key, and use it in the URL for addressing database records.
Frankly, I don't think so:
Security by obscurity is bad type of security. It means that your data is not safe if a malicious user just doesn't know its URL. Much better way of handling this is to check if the current user is authorized to access a given ID, and if not, deny them with 403 response.
I'll implement to the object-level security later, but the general idea is that every object should have an owner, the object owner may share it with other users, and all such information is stored in the object's properties.
Scraping of a public website can be done by following links on its pages, and for the sake of preventing scraping hiding object ID doesn't help.
SQL injections are prevented by sanitizing input and using SQL query bindings. XSS injections are prevented by escaping output. Using raw object IDs doesn't make prevention of such attacks easier or harder.
To sum up, I don't really see any reason why you shouldn't use ID in the URL. Compared to GUID it's much more readable.
Oh, there is a reason. If someone sees
/orders/?id=9 in the URL, they might understand that you don't have that many orders. However, I wouldn't worry about that - make more sales, don't try to look bigger than you are, and you'll be just fine!