ASP.NET security overview
ASP .NET Support Voice Column: ASP.NET security overviewTo customize this column to your needs, we want to invite you to submit your ideas about topics that interest you and issues that you want to see addressed in future Knowledge Base articles and Support Voice columns. You can submit your ideas and feedback using the Ask For It (http://support.microsoft.com/common/survey.aspx?scid=sw;en;1176&p0=&p1=&p2=&p3=&p4=) form. There's also a link to the form at the bottom of this column.On This PageIntroductionSecurity is an integral part of any Web-based application. Understanding ASP.NET security will help in building secure Web applications. This document provides a brief overview of security in ASP.NET. You can use the various resources and pointers provided in this document to study the topics in-depth.Back to the top Understanding the IIS security modelBefore the requests reach ASP.NET, they must be authenticated by Microsoft Internet Information Services (IIS). Learning how IIS security works would be very helpful. See the following resources for helpful information.INFO: How IIS Authenticates Browser Clients (http://support.microsoft.com/kb/264921/) Untangling Web Security: Getting the Most from IIS Security (http://msdn2.microsoft.com/en-us/library/ms995343.aspx) How Does It Work? (http://msdn2.microsoft.com/en-us/library/aa302376.aspx) Security Model for ASP.NET Applications (http://msdn2.microsoft.com/en-us/library/aa302382.aspx) Microsoft Internet Information Server Security Overview (http://msdn2.microsoft.com/en-us/library/ms951692.aspx) Back to the top Worker process identity informationOn Microsoft Windows 2000 or on Microsoft Windows XP, ASP.NET runs under a special user called ASPNET. If you install the .NET Framework version 1.1 on a domain controller, the installation does not create the local ASPNET account. Instead, ASP.NET applications run under other identities.On Windows 2000 domain controller servers, ASP.NET applications run under the IWAM_machinename identity. On Windows 2003 domain controller servers, ASP.NET applications run under the NETWORK SERVICE identity (regardless of the IIS isolation mode). Under some circumstances, running ASP.NET on a domain controller requires that you take extra steps to make the installation work properly. For more information about potential problems running ASP.NET 1.1 on a domain controller, click the following article number to view the article in the Microsoft Knowledge Base: 824308 (http://support.microsoft.com/kb/824308/)
IWAM account is not granted the impersonate privilege for ASP.NET 1.1 on Windows 2000 Domain Controller with SP4
For more
information about running the .NET Framework version 1.0 on a domain
controller, click the following article numbers to view the articles in the
Microsoft Knowledge Base: 315158 (http://support.microsoft.com/kb/315158/)
FIX: ASP.NET does not work with the default ASPNET account on domain controller
317012 (http://support.microsoft.com/kb/317012/) Process and request identity in ASP.NET
Back to the
topAuthentication in ASP.NET authorizationAuthentication is the process of obtaining identification credentials such as name and password from a user and then validating those credentials against some authority. If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity. After an identity has been authenticated, the authorization process determines whether that identity has access to a given resource.ASP.NET implements authentication through authentication providers, the code modules that contain the code necessary to authenticate the requestor's credentials. ASP.NET supports Forms Authentication, Passport Authentication, and Windows authentication providers. To enable an authentication provider for an ASP.NET application, you only have to create an entry for the application configuration file as follows: The mode is set to one of the authentication modes: Windows, Forms, Passport, or None. The default is Windows. If the mode is None, ASP.NET does not apply any additional authentication to the
request. This can be useful when you want to implement a custom authentication
scheme, or if you are solely using anonymous authentication and want the
highest possible level of performance. The authentication mode cannot be set at a level below the application root directory. As is the case with other ASP.NET modules, subdirectories in the URL space inherit authentication modules unless explicitly overridden. Back to the top Forms-based authenticationForms authentication is a system by which unauthenticated requests are redirected to an HTML form using HTTP client-side redirection. The user provides credentials and submits the form. If the application authenticates the request, the system issues a cookie that contains the credentials or a key for reacquiring the identity. Subsequent requests are issued with the cookie in the request headers. They are authenticated and authorized by an ASP.NET event handler using whatever validation method the application developer specifies.Protecting static file types using forms authenticationBy default, forms authentication protects only ASPX pages and any other .NET extensions. You can configure forms authentication to protect other static extensions such as .jpg, .gif, .html, .pdf, etc. To do this, map these extensions to aspnet_isapi.dll using IIS Manager as follows:
Protecting classic ASP pages using forms authenticationProtecting classic ASP pages with forms authentication is not supported by design because ASP and ASP.NET use different handlers. However, you can make it work using the help of COM-Interop and Web services.The following sample should work. This would have been pretty easy using simple COM Interop to call into the FormsAutentication utility functions. However, the functions require an HttpContext, which is only available in an ASP.NET application. As a workaround, create an ASP.NET Web service that does the forms authentication ticket validation.
Forms
Authentication Provider: (http://msdn2.microsoft.com/en-us/library/9wff0kyh(vs.71).aspx) 306238 (http://support.microsoft.com/kb/306238/) How to implement role-based security with forms-based authentication in your ASP.NET application by using Visual Basic.NET
311495 (http://support.microsoft.com/kb/311495/) How to implement role-based security with forms-based authentication in your ASP.NET application by using Visual C#.NET
Back to the
topPassport-based authenticationPass-port based authentication is a centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites. For more information, see the following Microsoft Web site:Passport
Authentication Provider. (http://msdn2.microsoft.com/en-us/library/f8e50t0f(vs.71).aspx) Back to the
topWindows-based authenticationASP.NET uses Windows authentication in conjunction with Microsoft Internet Information Services (IIS) authentication. Authentication is performed by IIS in one of three ways: basic, digest, or integrated Windows authentication. When IIS authentication is complete, ASP.NET uses the authenticated identity to authorize access. For more information, see the following resources:Windows
Authentication Provider (http://msdn2.microsoft.com/en-us/library/907hb5w9(vs.71).aspx) 323176 (http://support.microsoft.com/kb/323176/) How to implement Windows authentication and authorization in ASP.NET
Back to the
topAuthorizationThe purpose of authorization is to determine whether an identity should be granted the type of access that is requested by a resource. There are two fundamental ways to authorize access to a given resource:
ASP.NET
Authorization (http://msdn2.microsoft.com/en-us/library/eeyk640h(vs.71).aspx) Back to the
top<authorization> Element (http://msdn2.microsoft.com/en-us/library/8d82143t(vs.71).aspx) ImpersonationImpersonation occurs when ASP.NET runs code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead runs all code using the same user account as the ASP.NET process, which is typically the ASPNET account. This is contrary to the default behavior of ASP, which is to use impersonation. In IIS 6.0, the default identity is the NetworkService account.Note Impersonation can significantly affect performance and scaling. It is generally more expensive to impersonate a client on a call than to make the call directly. Using impersonation, ASP.NET applications can optionally execute the processing thread using the identity of the client on whose behalf they are operating. You usually use impersonation for resource access control. Delegation is a more powerful form of impersonation and makes it possible for the server process to access remote resources while acting as the client. For more information about impersonation in ASP.NET, see the following resources: Impersonation
in ASP.NET (Designing Distributed Applications with Visual Studio
.NET) (http://msdn2.microsoft.com/en-us/library/aa292118(VS.71).aspx) Impersonation in ASP.NET (.NET Framework Developer's Guide) (http://msdn2.microsoft.com/en-us/library/xh507fc5(vs.71).aspx) Using IIS Authentication With ASP.NET Impersonation (http://msdn2.microsoft.com/en-us/library/134ec8tc(vs.71).aspx) ASP.NET Data Flow (http://msdn2.microsoft.com/en-us/library/xa68twcb(vs.71).aspx) ASP.NET Delegation (http://msdn2.microsoft.com/en-us/library/aa291350(VS.71).aspx) 306158 (http://support.microsoft.com/kb/306158/) How to implement impersonation in an ASP.NET application
Microsoft Windows 2000 Service Pack 4 (SP4) adds a
couple of new local security policies that the impersonating account will need.
For more information, click the following article numbers
to view the articles in the Microsoft Knowledge Base: 824308 (http://support.microsoft.com/kb/824308/)
BUG: IWAM account is not granted the impersonate privilege for ASP.NET 1.1 on a Windows 2000 domain controller with SP4
821546 (http://support.microsoft.com/kb/821546/) Overview of the "impersonate a client after authentication" and the "create global objects" security settings
Back to the
topCode access security in .NETCode access security is a resource constraint model designed to restrict the types of system resources that code can access and the types of privileged operations that the code can perform. These restrictions are independent of the user who calls the code or the user account under which the code runs.Code access security delivers three main benefits. By using code access security, you can:
Code
Access Security in Practice (http://msdn2.microsoft.com/en-us/library/aa302424.aspx) Back to the
topUsing Code Access Security with ASP .NET (http://msdn2.microsoft.com/en-us/library/aa302425.aspx) How To: Use Code Access Security Policy to Constrain an Assembly (http://msdn2.microsoft.com/en-us/library/aa302361.aspx) Code Access Security for Developers (http://msdn2.microsoft.com/en-us/library/aa302415.aspx) Code Access Security (http://msdn2.microsoft.com/en-us/library/930b76w0(vs.71).aspx) Data Access SecurityThis following link contains recommendations and guidance that will help you develop a secure data access strategy. Topics covered include using Windows authentication from ASP.NET to the database, securing connection strings, storing credentials securely in a database, protecting against SQL injection attacks, and using database roles. This article also addresses issues with double-hop authentication.Data
Access Security (http://msdn2.microsoft.com/en-us/library/aa302392.aspx) Back to the
topStoring Passwords and Connection Strings SecurelyBy default, storing the connection string or impersonated user identity in Web.Config, or storing the process identity in Machine.config, requires you to enter the user name and password in clear text. The following articles show you how to store them securely.329290 (http://support.microsoft.com/kb/329290/) How to use the ASP.NET utility to encrypt credentials and session state connection strings
329250 (http://support.microsoft.com/kb/329250/) FIX: Stronger credentials for processModel, identity, and sessionState
821616 (http://support.microsoft.com/kb/821616/) Usage of strong credentials to store connection strings in the sessionState element
Back to the
topSamples and walkthroughsBack to the topMust-read articlesThe following guides are developed to cover all the aspects of implementing ASP.NET security in the real world scenario and are an excellent way of understanding security in ASP.NET.Building
Secure ASP.NET Applications (http://msdn2.microsoft.com/en-us/library/aa302415.aspx) Back to the
topImproving Web Application Security: Threats and Countermeasures (http://msdn2.microsoft.com/en-us/library/ms995343.aspx) Authentication in ASP.NET: .NET Security Guidance (http://msdn2.microsoft.com/en-us/library/ms978378.aspx) Other useful links and KB articlesASP.NET
Security Home on MSDN (http://msdn2.microsoft.com/en-us/library/aa302415.aspx) 306590 (http://support.microsoft.com/kb/306590/) ASP.NET security overview
ASP.NET
Web Application Security (http://msdn2.microsoft.com/en-us/library/330a99hc(vs.71).aspx) 324964 (http://support.microsoft.com/kb/324964/) Support WebCast: Microsoft ASP.NET security
Security
Considerations for ASP.NET Web Applications (http://msdn2.microsoft.com/en-us/library/aa984187(vs.71).aspx) 310588 (http://support.microsoft.com/kb/310588/) Security toolkit breaks ASP.NET debugging in Visual Studio.NET
An
Introductory Guide to Building and Deploying More Secure Sites with ASP.NET and
IIS (http://msdn.microsoft.com/msdnmag/issues/02/04/ASPSec/default.aspx) How-to articles810572 (http://support.microsoft.com/kb/810572/) How to configure an ASP.NET application for a delegation scenario
315736 (http://support.microsoft.com/kb/315736/) How to secure an ASP.NET application by using Windows security
323176 (http://support.microsoft.com/kb/323176/) How to implement Windows authentication and authorization in ASP.NET
306238 (http://support.microsoft.com/kb/306238/) How to implement role-based security with forms-based authentication in your ASP.NET application by using Visual Basic.NET
311495 (http://support.microsoft.com/kb/311495/) How to implement role-based security with forms-based authentication in your ASP.NET application by using Visual C#.NET
306158 (http://support.microsoft.com/kb/306158/) How to implement impersonation in an ASP.NET application
815145 (http://support.microsoft.com/kb/815145/) How to lock down an ASP.NET Web application or Web service
815153 (http://support.microsoft.com/kb/815153/) How to configure NTFS file permissions for security of ASP.NET applications
How
to Store an Encrypted Connection String in the Registry
(http://msdn2.microsoft.com/en-us/library/aa302406.aspx) Applications may choose to store encrypted data, such as
connection strings and account credentials, in the Windows registry. Learn how
to store and retrieve encrypted strings in the registry. How-to articles already mentioned elsewhere in this document329290 (http://support.microsoft.com/kb/329290/) How to use the ASP.NET utility to encrypt credentials and session state connection strings
329250 (http://support.microsoft.com/kb/329250/) FIX: Stronger credentials for processModel, identity, and sessionState
821616 (http://support.microsoft.com/kb/821616/) Usage of strong credentials to store connection strings in the sessionState element
Back to the
topTop bug fixes and other security issuesWindows 2000 SP4 adds a couple of new local security policies that the impersonating account will need. For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:824308 (http://support.microsoft.com/kb/824308/)
BUG: IWAM account is not granted the impersonate privilege for ASP.NET 1.1 on a Windows 2000 domain controller with SP4
821546 (http://support.microsoft.com/kb/821546/) Overview of the "impersonate a client after authentication" and the "create global objects" security settings
315158 (http://support.microsoft.com/kb/315158/) FIX: ASP.NET does not work with the default ASPNET account on a domain controller
811320 (http://support.microsoft.com/kb/811320/) "Aspnet_wp.exe could not be started" error message when you view an ASP.NET page
810204 (http://support.microsoft.com/kb/810204/) Per request impersonation does not work on Windows 2000 with ASP.NET
827559 (http://support.microsoft.com/kb/827559/) "Catastrophic failure" error message when you try to debut an ASP.NET application on Windows 2000 domain controller
Back to the
topGetting free supportNewsgroups are a great way to get free support for your questions. You can post your questions or search through the archives for answers. The following newsgroups are very active and you can leverage the collective knowledge of the MSDN and ASP.NET developer community.ASP.NET Security Newsgroup (look under .NET Development) http://msdn.microsoft.com/newsgroups/default.aspx (http://msdn.microsoft.com/newsgroups/default.aspx) Security Forum at Home of ASP.NET http://forums.asp.net/25.aspx (http://forums.asp.net/25.aspx) Plenty of other security related information, including new KB
articles, is available at the following Microsoft Web site: http://support.microsoft.com (http://support.microsoft.com/) Back to the
topAs always, feel free to submit ideas on topics you want
addressed in future columns or in the Knowledge Base using the
Ask For It (http://support.microsoft.com/common/survey.aspx?scid=sw;en;1176&p0=&p1=&p2=&p3=&p4=) form.
| Article Translations
|

Back to the top
