John Lam 1997 — 2026

ASP.NET authentication

Security looks easy until you analyze the threats to your application. I’ve been working on a small sample that demonstrates some best practices for secure authentication in ASP.NET V1.1. One of the key things in this sample is code access security (CAS) support. CAS is now enabled for ASP.NET applications, and this gives you many new opportunities to lock down your application’s attack surface.

My goal is to lock down the ASP.NET authentication process. I want to enable role-based security by writing user roles into the ASP.NET authentication ticket. I want to have a secure link between my application and SQL server as well. This turns into a fairly complex scenario that involves several different pieces of technology (ASP.NET, CLR security, COM+, Win32 security and SQL Server). Here’s an overview of the process:

  1. SQL server is used to authenticate salted, hashed passwords.
  2. There is a trusted connection to SQL server. There is a special account that is setup for authentication purposes only. It calls a secured stored procedure that takes the user name and hashed password, and returns a list of roles that the user belongs to (if authentication is successful, of course).
  3. The code that calls the stored procedure lives in a COM+ serviced component. The COM+ application is configured to runas the account described in part 2).
  4. The serviced component is called from a trusted assembly in the ASP.NET web application. It makes two link demands of the trusted assembly: a) that the account that the trusted assembly is running as is a known ASP.NET service account (e.g. MACHINE\ASPNET) and b) that the strong name of the trusted assembly is known.
  5. The trusted assembly in the ASP.NET web application is installed into the GAC. It has a strong name, and asserts that it has SecurityPermission.ControlPrincipal.
  6. The trusted assembly takes the set of roles returned from the call to the Serviced Component and creates a new Principal that contains the role. It attaches that Principal object to Thread.CurrentPrincipal.
  7. Assemblies or .aspx pages that call the trusted assembly must not have SecurityPermission.ControlPermission. I created a separate security zone (based on Medium) that removes this permission. This makes it impossible for code outside my trusted assembly to change the CurrentPrincipal (and thereby subject the rest of my application code to luring attacks).
  8. I configure the directory that contains .aspx pages to be writeable only from local administrator accounts.

A few coments about this scenario. First, I’m a bit disappointed that I can’t strong-name my .aspx pages, nor can I strong-name my codebehind assemblies. This makes it hard to create a tamper-proof chain of transfer of a user’s password to the database. Second, I’m not entirely sure whether denying non-administrator accounts write access to the .aspx directory will prevent luring attacks against my authentication chain.

Any comments from folks reading this weblog would be greatly appreciated. If you have friends who would like to comment on this, please forward this along to them as well. Thanks.

1 archived reader comment

Adam Stevenson (2003-12-14)

This is a good, short, article and has identified serveral areas in security that i had not concidered before now. Thanks for the good work!