Validate fraud attempt while editing registry with C # MVC

0

In my applications I was leaving the entity ID inside HTML being a hidden object. Example:

@Html.HiddenFor(m => m.EntidadeID)

But, I have identified that I can edit the HTML easily and in POST I can receive an invalid value.

Before Action of controller was like this:

[HttpPost]
[Authorize]
public ActionResult Detalhar(Entidade model)
    using (var db = new Conexao())
    {
        var registro = db.Entidade.Find(id);
        // continuação do código

If I get the ID by the URL, I have identified that even changed before POST the value sent was not the changed but the original.

I changed the Action to look like this:

[HttpPost]
[Authorize]
public ActionResult Detalhar(int id, Entidade model)
{
    using (var db = new Conexao())
    {
        var registro = db.Entidade.Find(id);
        // continuação do código

But I have identified another situation, which when using @using (Html.BeginForm()) , is set to <form action="/Entidade/Detalhar/5" method="post"> and the user can change the value of 5 to whatever value he wants, thus generating an invalid data change.

Doubt

Is taking the entity ID by "URL" safer? Or what would be the alternatives to slow attempts at data fraud.

Updated question

If the user asks for ID 5, it will be http://site/Registro/Detalhar/5 , if he changes ID to 10 before doing POST , I saw that controller understands ID is 5 , but is there any way to circumvent the number and try to change from 5 to 10, and controller get 10? Similar we could do with HTML.

    
asked by anonymous 14.02.2018 / 17:51

1 answer

0

If the user requests ID 5, he will be link , if he changes the ID to 10 before doing the POST, I have seen that the controller understands that the ID is 5.

Yes, it remains 5 because the value passed in the route is used in the Model that is loaded even before HTML, which in turn is populated in HiddenFor.

But is there any way to circumvent the number and try to change from 5 to 10, and the controller receives 10?

Changing the value in the URL path would not have to reload the page so that the new Entity ID was loaded into HidderFor. But, you can circumvent this by simulating an AJAX / POST script and sending any values to your application. One way to block this type of submission is by correctly configuring Cross Domain Requests. There are a number of security settings you can apply. Take a look here on this site .

    
15.02.2018 / 21:27