tags:

views:

45

answers:

2

Hello,

I have encountered what I expect is a common issue in web development. I have an ASP.NET MVC 2.0 ecommerce site. I pass the cost of an item to the product page view via a viewmodel - this cost may vary based on user type, user history, quantity purchased, etc.

I want to guarantee that when the user submits the form to purchase said product, the cost that I originally sent is the same i.e. the cost property in the viewmodel has not changed. For a normal user this is not a problem, but for someone malicious it is relatively simple to change the value en route so that my product costs, for example $1 instead of $999.

Obviously, I could go back to the DB and recalculate the cost once the form has been submitted - but this seems like an expensive operation and I'm wondering how this is normally done. The obvious solution in my mind is getting the hashcode (or just encrypt the value) of the field and add it as a hidden input to the form and ensure that the hashcode (or encrypted value) of the cost field is the same.

Can anyone tell me how this is regularly done and/or if there are issues with my proposed solution?

Thanks in advance,

JP

+4  A: 

It's normally done by recalculating on the server (whether that means hitting the DB or not depends on your business & caching layers on the server). Anything you store on or send to the client is open to tampering, so you're absolutely right not to trust it. The security/reliability of your site is worth that expensive operation!

Besides which: it's unlikely to be as expensive as you think, in the grand scheme of things. I'd suggest you worry about the expense when it becomes a proven issue, and not before.

Dan Puzey
A: 

Always go back to the DB. Available quantities, prices, etc. can change at anytime and you would want to inform the user prior to checkout if their requested goods are no longer available.

Todd Smith