<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security for Canadian Developers : ASP.NET 2.0</title><link>http://blogs.msdn.com/s4cd/archive/tags/ASP.NET+2.0/default.aspx</link><description>Tags: ASP.NET 2.0</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>8 Simple Rules For Developing More Secure Code</title><link>http://blogs.msdn.com/s4cd/archive/2007/05/28/8-simple-rules-for-developing-more-secure-code.aspx</link><pubDate>Mon, 28 May 2007 18:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2947471</guid><dc:creator>jldavid</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/2947471.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=2947471</wfw:commentRss><description>While surfing the Web, I came across the following article written by Michael Howard. The article really resonated for me because it covered the following &lt;SPAN class=clsSearchBox&gt;points:&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;
&lt;DIV class=clsDiscuss&gt;
&lt;UL&gt;
&lt;LI class=clsInfoBox&gt;Using analysis tools and experts to review your code (which can be accomplished with tools such as FxCop, AppVerifier&amp;nbsp;and PREfast) 
&lt;LI class=clsInfoBox&gt;Reducing risk using fuzzing and threat modeling&amp;nbsp; (the ACE team has written a great threat modeling tool that I demoed at the Toronto ISC2 conference recently) 
&lt;LI class=clsInfoBox&gt;Keeping bad input out of your applications 
&lt;LI class=clsInfoBox&gt;Learning all you can about security concepts&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;
&lt;P&gt;It's a good read. Check out the article here:&lt;BR&gt;&lt;A href="http://msdn.microsoft.com/msdnmag/issues/06/11/SecureHabits/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/06/11/SecureHabits/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/06/11/SecureHabits/default.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Are you interested in writing a post on this blog? &lt;A class="" href="http://blogs.msdn.com/cdndevs/contact.aspx" target=_blank mce_href="http://blogs.msdn.com/cdndevs/contact.aspx"&gt;Contact me here&lt;/A&gt; and I'd be glad to review and put up your security oriented article. Cheers!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2947471" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/ASP.NET+2.0/default.aspx">ASP.NET 2.0</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Security+Testing/default.aspx">Security Testing</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Security+On+The+Brain/default.aspx">Security On The Brain</category></item><item><title>ASP.NET AJAX Security Webcast</title><link>http://blogs.msdn.com/s4cd/archive/2007/04/09/asp-net-ajax-security-webcast.aspx</link><pubDate>Mon, 09 Apr 2007 20:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2062792</guid><dc:creator>jldavid</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/2062792.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=2062792</wfw:commentRss><description>&lt;P&gt;Be sure to check out our latest security webcast this Wednesday. Here is the abstract: ASP.NET AJAX is a powerful framework for creating interactive and highly-personalized Web experiences that work across all the most popular browsers. Like any other frameworks, there are security considerations you need to take into account. In this session, you will learn the core security concepts and principles surrounding the ASP.NET AJAX framework and learn how to implement them in your existing applications.&lt;/P&gt;
&lt;P&gt;Here is the link to register for the webcast:&lt;BR&gt;&lt;A href="http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032329023&amp;amp;EventCategory=4&amp;amp;culture=en-CA&amp;amp;CountryCode=CA"&gt;http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032329023&amp;amp;EventCategory=4&amp;amp;culture=en-CA&amp;amp;CountryCode=CA&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Hope to see you there!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2062792" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/ASP.NET+2.0/default.aspx">ASP.NET 2.0</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Announcements/default.aspx">Announcements</category></item><item><title>IIS 6.0 and ASP.NET 2.0 Credentials--Part Two</title><link>http://blogs.msdn.com/s4cd/archive/2006/08/24/720801.aspx</link><pubDate>Fri, 25 Aug 2006 07:30:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:720801</guid><dc:creator>dansellers</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/720801.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=720801</wfw:commentRss><description>&lt;p&gt;The ASP.NET User Principal (HTTPContext.User) clearly depends upon the&amp;nbsp;Authentication Mechanism that you selected in IIS 6.0 "Authenication Tab" and if you use Integrated Windows Authentication then it is dependant on the IIS impersonation token that get handed off in the extension control block via the ASP.NET 2.0 ISAPI API.&amp;nbsp;&amp;nbsp;&lt;/p&gt; &lt;p&gt;With ASP.NET 2.0 it is always&amp;nbsp;possible to get the credential of the logged on user--hence the IIS impersonate token stored in the extension control block--even with Forms Authentication by using the Request.LogonUserIdentity.&amp;nbsp; This was extremely difficult to do under ASP.NET 1.1.&lt;/p&gt; &lt;p&gt;So how does the IPrincipal object then get set in ASP.NET 2.0?&amp;nbsp; If you are using Windows Authentication then one of two things&amp;nbsp;occur inside of ASP.NET 2.0. It either takes the&amp;nbsp;impersonation token and wraps it&amp;nbsp;in the WindowsPrincipal object.&amp;nbsp; Now a .NET Developer can do the standard User.IsInRole checks from inside your code-behind pages.&amp;nbsp; However, if you allow Anonymous access inside IIS, ASP.NET detects this and ignores the impersonation token and ASP.NET puts in the Windows Anonymous identity instead.&amp;nbsp; There is a boolean property on WindowsIdentity that tells you whether this token is anonymous or not.&lt;/p&gt; &lt;p&gt;Now what get interesting is when you use Windows Authentication and your Web Application will be acessing the File System.&amp;nbsp; In this case IIS always uses the FileAuthorizationModule and as a result the FileAuthorizationModule always uses the IIS imperonation token and ignores the WindowsPrincipal on the context.&lt;/p&gt; &lt;p&gt;For example if you are using "Client Impersonation" the OS thread calls into ASP.NET 2.0 runtime and the "Set Client Token" API is fired and the IIS impersonation token is passed to the Windows Authentication Module and you can do checks against NT Security Groups.&amp;nbsp; However, if you have anonymous enbled in IIS then the IIS Machine Account or Anonymous User will be swapped instead.&amp;nbsp; Now as the request continues it will hit the FileAuthorizationModule, however, regardless of all the work that has been done up to this point the FileAuthorizationModule will do an access check using the IIS impersonation token, thus completely ignores what is set on the OS thread or the User Property as it always goes back out to IIS and finds out what the impersonation token is.&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;To test this you can create a sample webpage. This simple webpage will identity four parts:  &lt;p&gt;The User identity's name on the HTTPContext,&lt;br&gt;The OS thread identity--by default NT Authority\Network Service,&lt;br&gt;Whether WindowsIdentity is Anonymous or not,&lt;br&gt;The User identity from the impersonation token.  &lt;p&gt;The code would look similar to this in the page_load event:&lt;br&gt;{  &lt;p&gt;lblHttpContext.Text += "'" + User.Identity.Name + "'"&lt;br&gt;lblOSThread.Text += WindowsIdentity.GetCurrent().Name;&lt;br&gt;lblIsAnonymous+=((WIndowsIdentity)User.Identity).IsAnonymous;&lt;br&gt;lblFromToken += Request.LogonUserIdentity.Name;--this allows to get back to Impersonation token  &lt;p&gt;}  &lt;p&gt;So as you will see we can have three different identities in ASP.NET.  &lt;p&gt;To test out the behaviour of the FileAuthorizationModule you can modify the permission on the folder that contains your webpage and place an explicit deny permission on the "Internet Guest Account".&amp;nbsp; On the "Authorization Tab" in&amp;nbsp;IIS 6.0&amp;nbsp;clear the check box for&amp;nbsp;"Windows Integrated Security" which will force the applicaiton to run as Anonymous User.&amp;nbsp; Now when you&amp;nbsp;try to run the Webpage, you will receive an Access Denied error, however, this error comes from ASP.NET 2.0 runtime and not from IIS which is the result of FileAuthorizationModule failing authorzation and the authorization check was done against the IUSER Account.&amp;nbsp; Therefore, if you are using Anonymous user then the IUSER Account will have to be given permission at least read permission on your webpages. &lt;p&gt;For the second test go back to the "Authentication Tab" and enable the "Windows Integrated Security" and when you refresh the page you will now see the results of the webpage and you will notice the impersonate token and the HttpContext are now in sync.&amp;nbsp; The OS thread will still be the Network Service Account and Anonymous WindowsIdentity will be false.&amp;nbsp;  &lt;p&gt;Therefore, you will not need to enable impersonalization for File Authentication to work as clearly behind the scene we have proven that the FileAuthenticationModule is using the impersonate token value contained in the extension control block.&amp;nbsp;  &lt;p&gt;So why would you turn impersonate on then?&amp;nbsp; Because you need to flow identity off the box and you have delegation setup, or if you use an Authentication such as Basic which will give you one hop. Finally you might have an application that uses the File Object in your ASP.NET 2.0 code to perform some kind of File IO.&amp;nbsp; Now if you set &amp;lt;identity impersonate="true"/&amp;gt; in your web.config and refresh the webpage you will now see that OS thread, HttpContext, and the IIS impersonate token are now all in sync. &lt;p&gt;On a final note this should reveal that the identity of OS thread alone is not going to provide you with some kind of silver bullet security to your WebApplication.&amp;nbsp; I do not like the idea of changing the Network Service account which is already a very low privilege account for a domain account and think my Web Application will be more secure.&amp;nbsp; First the Nework Service is already one of the lowest privilege accounts on WIndows 2003 where as the&amp;nbsp;domain account will be a interactive account with a password, thus actually&amp;nbsp;is&amp;nbsp;has higher privilege.&amp;nbsp; In fact it increases the attack surface and is now subject to&amp;nbsp;account and password management.&amp;nbsp;  &lt;p&gt;Therefore, security is dependent upon the OS thread, the HTTPContext the trust level of your ASP.NET 2.0 Web Application as well as the way in which your application is configured.&amp;nbsp; Finally,&amp;nbsp;most importantly the input validation you put in your server side code.&amp;nbsp; There is no silver bullet but rather defence in depth using a wide variety of mechanism.&amp;nbsp;  &lt;p&gt;If someone tells you something is 100% secure don't believe it as there is no such thing as perfect in this world.&amp;nbsp; Do not look for the silver bullet for security as it does not exist.&amp;nbsp; Would you do banking at a bank that uses the simpliest security mechanism to save your identity and money, probably not.&amp;nbsp; So why go with the simpliest solution and think it will give you the highest level of security.&amp;nbsp;  &lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=720801" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/ASP.NET+2.0/default.aspx">ASP.NET 2.0</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/IIS+6.0/default.aspx">IIS 6.0</category></item><item><title>IIS 6.0 and ASP.NET 2.0 Credentials</title><link>http://blogs.msdn.com/s4cd/archive/2006/08/24/718656.aspx</link><pubDate>Thu, 24 Aug 2006 21:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:718656</guid><dc:creator>dansellers</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/718656.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=718656</wfw:commentRss><description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The one area that many developers do not have good grasp at is how Authentication tokens from IIS 6.0 is passed to ASP.NET 2.0 and how these tokens can subsequently be used for Authorization in an ASP.NET 2.0 Web Application. 
&lt;P&gt;The one question that arises quite often is when I click on “Integrated Windows Authentication” in IIS 6.0 “Authentication tab” how does this information get passed to ASP.NET 2.0 and when it is passed to my Web Application how do I flow the client identity between different Services such as a Web Service or a database like SQL Server for example? 
&lt;P&gt;On a side note if you need this client identity to flow across multiple hops between all your application servers, then you will need to use Kerberos with delegation credentials. A good article on how to configure delegation credentials is located &lt;A href="http://technet2.microsoft.com/WindowsServer/en/library/c312ba01-318f-46ca-990e-a597f3c294eb1033.mspx?mfr=true" target=_blank&gt;here&lt;/A&gt;. If you are using Windows Server 2003 then two new features were added known as constraint delegation and protocol transition. With protocol transition, you could use form authentication on an ASP.NET 2.0 Web Application--as not to flow the Windows Authentication tokens across the Internet. In your ASP.NET code you can have Windows 2003 literally newop a new Windows Identity by calling impersonate based upon a user identity and string passed into the construct of WindowsImpersonate class and then enable impersonation on this new Windows Identity. This is new extension to Kerberos and allows you to flow this token off the Web Server to other Application Servers on your Network. Now of course for this to work your Windows 2003 Web Server needs to be part of a Windows 2003 Domain. The next thing you should also do is to enable constraint delegation. This way when use protocol transition to newop a new Windows Identity you can constrain this new delegated token so it can only talk to this particular SQL Server and a particular App Server for example. Thus, not allowing it to delegated to all service in your network which significantly increases the attack service. 
&lt;P&gt;So what pieces of identity information does IIS knows about based upon the configuration setup in IIS 6.0? 
&lt;P&gt;While the first IIS 6.0 knows of is the OS thread identity. This is the worker process that has an identity associated with it and has been configured in the IIS 6.0 Application pool on the “Identity tab” --which by default is the Network Service Account. 
&lt;P&gt;The second piece of identity information that IIS knows about is based upon the settings you configure in the “Authentication Tab” under IIS 6.0 such as “Integrated Windows Authentication”. In this example, IIS 6.0 will make the identity of calling user available after receiving the information when the browser negotiates with IIS 6.0. 
&lt;P&gt;Ok, so how does this relate to ASP.NET 2.0 and how are these two identities get passed to your ASP.Net 2.0 Application? 
&lt;P&gt;IIS 6.0 makes these tokens available via ISAPI extension and part of the APS.Net 2.0 runtime is an ISAPI API. Therefore, by default when your application starts up the worker process is spun up. Now of the course IIS 6.0 and ASP.NET will know about the worker process which is commonly referred to as the OS thread identity (by default Network Service Account). When the worker process calls your ASP.NET 2.0 the ISAPI API contains an extension control block. This extension control block will store a security token a.k.a the Impersonation token from the “Authentication Tab” that you configured in IIS, so for example if you enabled Integrated Windows Authentication then the Windows Authentication token of the logged in user as negotiated between IE and IIS is now passed to your ASP.Net 2.0 application. 
&lt;P&gt;So to recap what do we see from inside the ASP.NET side of the house? 
&lt;P&gt;One thing is we know the OS thread transitions over to ASP.Net with an identity on it from the worker process. This token value is available to make integrated resource type of calls. For example, if in my connection string I used integration security with SQL Server then it is the OS thread identity that is making the call regardless of who is logged into the ASP.NET application or the Windows Identity that may have been passed via the extension control block. 
&lt;P&gt;When we talk about impersonation inside ASP.NET we are talking about taking the OS thread and switching the identity to some new set of security credentials. The most common one is "Client Impersonation" in which the &amp;lt;identity impersonate=”true”/&amp;gt; tag in the Web.config is set and behind the scene when the worker process starts up&amp;nbsp;ASP.NET 2.0 runtimes calls the “Set Thread Token” API which takes the impersonation token stored in the extension control block and now swaps it on top of the OS thread. Now the OS thread will now be running under the identity of calling user. 
&lt;P&gt;The other option is “Application impersonation” in which the “Logon User API” is called and takes the username and password as specified in the &amp;lt;identity impersonate=”true” user=”someuser” password=”somepassword”/&amp;gt; tag of our web.config. Now the OS thread will run under these credentials within the APS.Net 2.0 Application. With Application Impersonation this allows you run multiple applications in an single Application pool under the same executable but you want each application to use different identities when making resource calls. 
&lt;P&gt;In both of these instances the OS thread identity has been changed. 
&lt;P&gt;So far our ASP.NET 2.0 application knows about OS thread and the impersonation token from IIS, however, we cannot forget about the ASP.NET user principal which is derived from the HttpContext.User or Thread.Current Principal. In most cases the ASP.NET user principal and OS threat are not the same identity, thus we can have three different identities inside your ASP.NET 2.0 Applications. 
&lt;P&gt;In a big nut shell this is how the identity as specified under the Application pool “Identity tab” can be used to make integrated security calls under a single context or how this identity be swapped out with “Client” or “Application” impersonation depending upon our applications requirements. 
&lt;P&gt;In part two of this blog I will talk more about the ASP.NET user principal inside ASP.NET 2.0 and what we can do with this information.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=718656" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/ASP.NET+2.0/default.aspx">ASP.NET 2.0</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/IIS+6.0/default.aspx">IIS 6.0</category></item></channel></rss>