views:

98

answers:

3

i have created the controller :

    [Authorize]
    [AcceptVerbs(HttpVerbs.Delete)]
    public ActionResult Delete(int id)
    {
        try
        {
            db.DeleteObject(db.AEROLINEA.FirstOrDefault(x => x.AEROLINEAID == id));
            db.SaveChanges();
        }
        catch { /* TODO:Display message*/ }

        return View();
    }

if i execute in firebug the next javascript anyone logged could delete an airline even if he doesnt have permissions to delete

    var action = "/Airline/Delete/" + recordId;

    var request = new Sys.Net.WebRequest();
    request.set_httpVerb("DELETE");
    request.set_url(action);
    request.add_completed(deleteCompleted);
    request.invoke();

HOw can avoid this issue???

+2  A: 

You can filter the the roles:

Example:

[Authorize(Roles="Admin")]
    [AcceptVerbs(HttpVerbs.Delete)]
    public ActionResult Delete(int id)
    {
        try
        {
            db.DeleteObject(db.AEROLINEA.FirstOrDefault(x => x.AEROLINEAID == id));
            db.SaveChanges();
        }
        catch { /* TODO:Display message*/ }

        return View();
    }
Marwan Aouida
authorize verify if you have acces to that view? or only verify that you are logged?
It checks if the logged in user is in role e.g:"Admin" which means if he has access to that particular action method.But you have to create the role first.
Marwan Aouida
that would dont work for me because new roles can be created by the user dinamically.but the real problem is: if somebody have access to the delete method him could pass anything in the id and could delete any airline even if it wasnt listed in the View( because he doesnt have permissions over that airline.)
Then you can create an action filter that inherits from the AuthorizeAttribute in which you can choose the roles dynamically
Marwan Aouida
i thinks if i send the entire entity and not just an id, is that possible?
A: 

Or use the AntiforgeryToken with a juicy salt at the View..

Erik
AntiforgeryToken is really interesting , but it doesnt solve my problem, but is nice to know that it exists, thanks
A: 

[Authorize] without parameters allows you to indicate that a user must be logged in. You also can specify users/roles, authorized to access your action

eu-ge-ne