AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

DeleteConfirmed could be more secure

Open JohnCOsborne opened this issue 8 years ago • 8 comments

I'm not sure how secure the examples should be but technically a user could use developer tools and modify the hidden value of the Id, then submit. If error pages are turned on then no stack trace... if not then stack trace.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

JohnCOsborne avatar Jun 24 '18 02:06 JohnCOsborne

The id is not hidden, it's a route value. All you need to do is change the URL. A real app would verify the user owned the data. See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.1

Rick-Anderson avatar Jun 24 '18 02:06 Rick-Anderson

@Rick-Anderson I was referring to the form in Delete.cshtml -- in hindsight the stack trace comment was not relevant, I was just thinking out loud.

<form asp-action="Delete"> <input type="hidden" asp-for="ID" /> <input type="submit" value="Delete" class="btn btn-default" /> | <a asp-action="Index">Back to List</a> </form>

I used Chrome's developer tools and changed the id to some garble of numbers, e.g. 2938493

JohnCOsborne avatar Jun 24 '18 04:06 JohnCOsborne

@JohnCOsborne comment out the hidden markup. That code is not used. Hover over a delete link. It's passed explicitly.

It wouldn't matter if it was hidden anyway, it's the responsibility of the app to verify the data. See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.1

Rick-Anderson avatar Jun 24 '18 15:06 Rick-Anderson

@JohnCOsborne it is hidden in the Edit - but it's not hidden for security reasons. It's hidden because you don't display the ID.

Rick-Anderson avatar Jun 24 '18 15:06 Rick-Anderson

@Rick-Anderson hmm, well that's odd. It was obviously being used because if I modified the hidden ID via developer tools and that is the ID that was submitted. I comment it out, as you said, and it is retrieved via the form action attribute(Seems model binding chooses form elements over the action attribute). The first point I was trying to make is what you're saying: The app should verify the data and my second point is that it isn't. I just wanted to point it out. I'm not sure how secure MSFT wants their examples to be... Please see the images below to see what i was doing and see below the images for my other question:

image then image then image I change the ID to some random number image then click the delete button image then image

It is clearly used. So what is the point of having duplicate code?

JohnCOsborne avatar Jun 24 '18 22:06 JohnCOsborne

See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.1

Rick-Anderson avatar Jun 24 '18 22:06 Rick-Anderson

If I recall correctly, that code was made via scaffolding. Which means the scaffolding is creating duplicate/unused code. A small little issue, but I think an issue none-the-less. @guardrex Am I seeing this right, is the scaffolding creating duplicate/unused code? TL;DR - The Delete View renders both an action="Movies/Delete/7" in the form element and an hidden input with name="ID". The hidden input seems to have higher priority when being bound. Why have two IDs being passed when you only need one?

*Duplicate in the sense that the code already there provides the same functionality

JohnCOsborne avatar Jun 26 '18 19:06 JohnCOsborne

The scaffolder is creating correct code. I was pointing out that even if you removed hidden the latent value will carry the ID. The question you raised on security is answered in the links I sent you.

Rick-Anderson avatar Jun 26 '18 20:06 Rick-Anderson