views:

62

answers:

3

In my asp.net MVC application I am using in place editors to allow users to edit fields without having a standard form view. Unfortunately, since I am using Linq to Sql combined with my data mapping layer I cannot just update one field at a time and instead need to send all fields over at once.

So the solution I came up with was to store all my model fields into hidden fields, and provide span tags that contain the visible data (these span tags become editable due to my jquery plugin). When a user triggers a save of their edits of a field, jquery then takes their value and places it in the hidden form, and sends the whole form to the server to commit via ajax.

When the data goes into the hidden field originally (page load) and into the span tags the data is properly encoded, but upon the user changing the data in the contenteditable span field, I just run

$("#hiddenfield").val($("#spanfield").html();

Am I opening any holes this method? Obviously the server also properly encodes stuff prior to database entry.

+2  A: 

Assuming your server is properly detecting and dealing with XSS attempts, there's no way a malicious user could submit an attack for another user. Unless someone wants to hack themselves(?), it seems secure to me.

Allain Lalonde
That's what I was thinking but I wanted to make sure before I made any assumptions! :)
KallDrexx
A: 

There's no difference here than if you were providing visible input fields and having that form submitted. Simply shuffling the data into hidden fields vs. visible ones would not make a difference.

BradBrening
Except that the content of the fields gets interpreted when it's embedded in the page. A field containing <img src="..." onload="alert('test')"> will behave differently then having that code embedded in your page.
Allain Lalonde
+2  A: 

I find this approach pretty unsavory. I guess the overall soundness of this scheme depends on what fields you're actually populating this way --

For example, if you store fields that are supposed to be set only once (at the time of record creation) and never changed, this will allow a (malicious) user to change the field values mid-stream by editing a hidden field before posting (very easy to do, for example, with Firebug).

Bosh
I agree, but I'm running out of ideas of how to handle this without retrieving a whole record just to update one field.
KallDrexx