wood burning stoves
The moose likes Struts and the fly likes Database Ids and Forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Database Ids and Forms" Watch "Database Ids and Forms" New topic

Database Ids and Forms

Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I am looking for a 'best practices' approach to avoid placing database ids in my forms (either as hidden variables or in my query strings).
With tools such as firebug, it becomes easy for someone to change a hidden form value and submit against some other record in the database.

The only thing I can think of is to have a database column that houses a UUID and use that in my forms, but I don't think I want to use UUIDs throughout my system since I'd rather leverage my database id's rather than UUIDs...

I'm coding a new app from scratch (Struts 2, Spring, Hibernate), so the sky's the limit.



Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Just a thought, you could keep your DB IDs in your session object, associate them with some alternate ID, then put the alternate ID in the form. When the next request came back from the client you would have to translate the alternate keys back into the actual DB IDs (Probably using a hashmap to do the translation). You could make some framework utilities to ease generating the alternate IDs and translating them. Maybe a custom tag that would generate the alternate key, put it in the hashmap with the real ID, and then write the alternate key out in the html for the hidden tag. Actually, for the value of the hidden field, you could just set it to the name of the hidden field. Then you could write a struts2 interceptor that would loop through the hashmap (which would have the field name as the key and the actualy DB ID as the value) and use the key to do an OGNL look up to find the right varriable in your action class and then set it to the value from the hashmap. Actually, your custom tag wouldn't even need to generate any html if you did it this way.

Like I said, just a thought. Maybe there is a tool out there or part of a framework that will do this automatically, but would think this would allow you to avoid relying on the database IDs that are returned by clients.
I agree. Here's the link: http://aspose.com/file-tools
subject: Database Ids and Forms
It's not a secret anymore!