Javascript injection asp mvc

I created a 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 following javascript who checked in can delete the airline even if it doesn't have delete permissions.

    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 problem.

+1


a source to share


3 answers


You can filter 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();
    }

      

+2


a source


Or use AntiforgeryToken with juicy salt in the view.



0


a source


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

0


a source







All Articles