DeleteConfirmed could be more secure
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.
- ID: 97234f18-4009-0ebf-a379-9b63125529cd
- Version Independent ID: 1bf4792d-dab4-e03d-2021-3dcdcaff6a0f
- Content: Examine the Details and Delete methods of an ASP.NET Core app
- Content Source: aspnetcore/tutorials/first-mvc-app/details.md
- Product: aspnet-core
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
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 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 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
@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 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:
then
then
I change the ID to some random number
then click the delete button
then

It is clearly used. So what is the point of having duplicate code?
See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data?view=aspnetcore-2.1
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
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.