Re: Role-based authentication and Forms and System.UnauthorizedAccessException

From: Dominick Baier [DevelopMentor] (dbaier_at_pleasepleasenospamdevelop.com)
Date: 08/19/05


Date: Thu, 18 Aug 2005 23:43:45 -0700

Hello wrecker,

i doubt your code is working fine. In AuthenticateRequest you don't have
access to the Session as the SessionModule runs after this event....

The common approach is to store the roles in the cookie. I have a sample
on my blog for doing this:
http://www.leastprivilege.com/DevWeek2005PostConference.aspx

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

> Hi all,
>
> I'm trying to implement role-based authentication for the following
> directory structure in my ASP.NET app.
>
> login.aspx
> Admin/
> Members/
> The web.config in my Admin directory is as follows
>
> <configuration>
> <system.web>
> <authorization>
> <allow roles="Admin"/>
> <deny users="*"/>
> </authorization>
> </system.web>
> </configuration>
> When the user logs in using authentication mode set to Forms, they are
> authenticated against a SQL table and then assigned a role
>
> Dim roles() As String
> If CurrentUser.IsAdministrator Then
> roles = New String() {"Admin", "Member"}
> Else
> roles = New String() {"Member"}
> End If
> Where the roles string array is stored in the Session (although I've
> also tried storing it in the cache object as well to try and solve my
> problem)
>
> In Global.asax Application_AuthenticateRequest I have
>
> If (Not (HttpContext.Current.User Is Nothing)) Then
> If HttpContext.Current.User.Identity.AuthenticationType =
> "Forms" Then
> Dim id As System.Web.Security.FormsIdentity
> id = HttpContext.Current.User.Identity
> HttpContext.Current.User = New _
>
> System.Security.Principal.GenericPrincipal(id, roles)
> ' roles extracted from session
> End If
> End If
> My problem is that after a user having Administrator privelages logs
> in and they try to access a page in the Admin directory they get a
> System.UnauthorizedAccessException exception. I've debugged this and
> the roles array does indeed have "Admin" and "Members" in it, but the
> HttpContext.Current.User doesn't seem to contain this information,
> even after assigning it the new principal (I can't find it in any
> fields that are visible to the debugger) I've checked the permissions
> on the directory and the ASP machine account has access to this
> directory. I've been reading quite a few articles on role based
> security (expecially the ones from the Rolla guys) and they all seem
> to use this approach. Why is this not working???
>
> My test system is IIS5.1 on XP Pro using version 1.1 of the framework.
>
> Thanks
>



Relevant Pages

  • Re: HELP Connection error on Release mode
    ... "Off" Always display detailed ASP.NET error information. ... This section sets the authentication policies of the application. ... Set trace enabled="true" to enable application trace logging. ... <!-- SESSION STATE SETTINGS ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Session Fixation Vulnerability in Web-based Applications
    ... session, without modifying the way servers generate session ID's is as ... Think of the http server generated sessions as "UI Sessions" and as ... no impact on authentication. ... "authentication key" for this domain (usually in the form of a new ...
    (NT-Bugtraq)
  • Re: [PHP] Re: a question on session ID and security
    ... constructed to produce the actual authentication token. ... looking at the cookies on the client gets no indication that you're ... testing for remote session hijacking weaknesses. ... blinded by a bright shiny new algorithm. ...
    (php.general)
  • Re: Forms authentication vs session variable
    ... There is a known security vulnerability called "Session Hijacking", ... and there are standard ways of protection. ... With forms authentication being the standard approach, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Forms authentication vs session variable
    ... There is a known security vulnerability called "Session Hijacking", ... and there are standard ways of protection. ... With forms authentication being the standard approach, ...
    (microsoft.public.dotnet.framework.aspnet)