I have a question related to security and manipulating the parameters of controls during a postback. The very contrived example below explains it.
I have a business object which has the following properties:
- ID
- AddedBy
In an aspx page, I have a delete button. In the 'OnClick' event I call a BLL method which deletes this object from my underlying datastore. The 'delete' method just takes a single parameter, that being the 'ID' for the object.
However, only the user who created the object should be allowed to delete it. Depending on the currently logged on user, in PageLoad the 'CommandArgument' of the Delete button is being set to the appropriate ID value. I then retrieve the CommandArgument value in the 'OnClick' event for passing to the BLL delete method.
For example:
- User 'foo' has already created an object. It is given ID of 24 and AddedBy of 'foo'.
- User 'foo' logs on and goes to the 'delete object' page.
- In PageLoad, the logged on Username is used to retrieve the correct object, using a method created for this called 'GetObjectByUsername'.
- Also in PageLoad, the CommandArgument of the 'Delete' button is set to the ID of the retrieved object. In this case the CommandArgument is set to 24.
- When user 'foo' clicks on the 'Delete' button, the OnClick event is fired, whereby the ID parameter of the 'delete' method is passed the value 24. The object is deleted.
Now, this is all well and good. But how secure is it? Would it be possible to use an HTTP proxy tool such as Fiddler to replace the value 24 with the value 25, thereby deleting the wrong object?
A way to prevent this would be to do a security check. In the Delete method, first check that the object in question really was added by the currently logged on user.
For example, use something like:
MyObject myObject = GetObjectByID(24);
if (Page.User.Identity.Name == myObject.AddedBy)
{ go ahead and delete the object }
else
{ give the user an appropriate error message }
Or, cache the ID from the object retrieved in PageLoad in a private page variable, and check against this before calling the 'delete' method.
However, doing any of this incurs overhead.
So, are these sorts of checks necessary? Or, by doing them, am I wasting server resources?
Any thoughts much appreciated.