Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anything more secure than hidden form fields in ASP.NET MVC?

Tags:

In ASP.NET MVC (default routing),I'd like to use a URL like this to return a View with a form to edit a customer:

/Customers/Edit/5 

I need to make use of CustomerId=5, but I don't want to permit a customer to change it.Right now I make the id hidden using:

<%= Html.Hidden("CustomerId") %> 

This accomplishes what I want,but I'm under the impression that hidden form variables are not secure and can be manipulated by the end user.

So, what's the best way to allow a customer to edit their information but not their ID?

like image 849
royco Avatar asked Apr 13 '09 04:04

royco


People also ask

Are hidden fields secure?

Overview. Hidden fields allow developers to process application data without having to display it on the screen. Using hidden fields to pass data in forms is a common practice among web applications and by itself is not a security risk. However, hidden fields are not secure and can be easily manipulated by users.

Which is correct about hidden form fields?

The <input type="hidden"> defines a hidden input field. A hidden field let web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

Is ASP.NET MVC secure?

MVC provides a lot of infrastructure support for Forms Authentication. Forms authentication is highly customizable, you can customize everything from the sign in form, to where the credentials are stored and how those credentials are validated. Forms Authentication in ASP.NET relies on cookies by default.


1 Answers

My solution was to use the Tamper Proofing code from Steven Sanderson's ASP.NET MVC book. The idea is that you create a hash of any hidden form field you want to tamper proof:

<%= Html.Hidden("CustomerId") %> <%= Html.Hidden("CustomerIdHash") %> 

When the form is submitted, Steven's code then computes another hash of CustomerId and makes certain it equals CustomerIdHash. If it does, then no tampering has occurred. It's great code, and worth the price of the book.

like image 140
royco Avatar answered Oct 12 '22 23:10

royco