-1
How do I block the ID of the URL parameter of a system I own, for example, when clicking on a record it shows as/Change/12 url where 12 would be the id for example, but if the user changes 12 for 13 it can edit the record 13, how do I block for him to edit only the record that he clicked, in case 12, how to block so that it is not replaced by the url?
Action Code in Controller:
[HttpGet]
[ActionName("Analisar")]
public async Task<ActionResult> Editar(long id)
{
var model = new AssociacaoCooperativaViewModel() { Id = id };
if (model.Id > 0)
{
try
{
var associacao = await AssociacaoCooperativaApplicationService.ObterAssociacaoCooperativaPorIdAsync(model.Id);
model = await AssociacaoCooperativaTransformer.TransformGravarAsync(associacao);
model.Action = this.ControllerContext.RouteData.Values["action"].ToString();
model.Situacao = EnumSituacaoAssociacaoCooperativa.EmAnalise;
}
catch (BusinessException e)
{
HandleBusinessException(e);
}
//catch(Exception e)
//{
// this.ErrorMessage = e.Message;
//}
}
await this.CarregarGravarViewModelAsync(model);
return View(model);
}
thank you in advance
If the case is permission to edit, it would not be more interesting that in the "action" of the "controller" you check if the user has the privilege to modify this record?
– SylvioT
it has the privilege to edit, but can only edit his record
– Stand Alone
Then you can check if the record is his and warn when it is not.
– SylvioT
I suggest you read the community guidelines, to ask a good question.
– user148754
@Sylviot he can edit any record, however he cannot edit by changing the URL, if he wants to delete he has to do the search again.
– Stand Alone
You can do nothing to stop the customer, the customer of your service is not under your control. If the user is allowed to modify record 12 and 13, let him modify it (if he changed "in hand" the url he knows that the result will be different than expected. If the user is only allowed pro 12 and not pro 13 it is the service’s obligation to check this on the server. The server should never trust the data sent by the client and should check everything on the server side.
– mari
@But, it has permission, it can change any record, only you need to change it by clicking it, if you pass through the url you cannot change. Pq is giving a lot of trouble for incredible that seems to user say click on a record in the list to change, then it changes the url and ends up changing another record and messing up the site.
– Stand Alone
I don’t get it. Why do you mess with the system? You can log to the server which url was called by which user, hence it could not claim to have tried to change the 12 and called by passing id 13.
– mari
@Standalone in your case would be more efficient you perform the critical operations through Posts methods, in GET methods you will always pass the information through the URL
– Killdary Aguiar de Santana
@Standalone you can then check in the edit action if the "referrer url" is different from an edit url... so it can’t come straight from the edit.
– SylvioT
@Killdary Aguiar de Santana These measures would be "palliative": the customer can always change both the content and the header of the post. There’s no way to control what the customer sends.
– mari
@Standalone if my answer helped you, don’t forget to mark it as accepted. Thank you!
– Alisson Marqui