views:

48

answers:

2

I am using ASP.NET MVC2 and have a problem. After Log off I manually type into the adress bar http://localhost/controller/action and I'm redirected to the page regardless of what I am LogOff . How do I solve this security risk?

Code of some controller action who I am manual type on adress bar:

[Authorize(Roles = "Admin")]
public ActionResult Upload()
{       
    return View();
}

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

Upload

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Upload</h2>
    <% using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype="multipart/form-data" }))
    { %>
          Select a file: <input type="file" name="fileUpload" id="fileUpload" />  
          <input type="submit" value="Upload";/>
      <% 
    } %>
</asp:Content>

Update: Now I have discovered that I can manualy type in adress bar controller and action name and open pages on my web site before login, why

LogOn and LogOff actions:

    [AcceptVerbs(HttpVerbs.Post)]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
        Justification = "Needs to take same parameter type as Controller.Redirect()")]
    public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
    {

        if (!ValidateLogOn(userName, password))
        {
            return View();
        }

        FormsAuth.SignIn(userName, rememberMe);
        if (!String.IsNullOrEmpty(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return RedirectToAction("About", "Home");
        }
    }

    public ActionResult LogOff()
    {

        FormsAuth.SignOut();

        return RedirectToAction("Index", "Home");
    }

I'm found solutions: I put wrong role name ([Authorize(Roles = "Admin")]) and it was a problem with my code

A: 

My guess:page comes from the browser cache, when you press a button submit a page you will be redirected to login page

mehmet6parmak
+1  A: 

Are you sure the controller and or action you are typing into the address bar has the [Authorize] attribute associated to it?

DevDave
I posted some action code, see above
Ognjen
And in that code, you do not have the authorize attribute defined. Therefore, you are saying that this particular controller/action can be accessed by anyone.
Tommy
I set authorize attribute but problem is still there, see code above
Ognjen
Only things I can think of is. The guy below is correct and the page is coming from the cache and as soon as you try to perform an action on the page it will redirect you to the login page. The other thing could be the logout code. Can you post the code you used to logout?
DevDave
I post LogOn and LogOff actions, see my code. How I delete that cache to prevent of typing absolute path to my pages
Ognjen