<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://keepitlocked.net/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>KeepItLocked.net : ASP.NET, Software Security</title><link>http://keepitlocked.net/archive/tags/ASP.NET/Software+Security/default.aspx</link><description>Tags: ASP.NET, Software Security</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>SoCalCodeCamp Presentation - "Top Ten Tips for Tenacious Defense for ASP.NET Application"</title><link>http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx</link><pubDate>Tue, 27 Jan 2009 20:37:00 GMT</pubDate><guid isPermaLink="false">a3f75fb5-0505-4d35-9795-aaa2ed659a71:1707</guid><dc:creator>Alex</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://keepitlocked.net/rsscomments.aspx?PostID=1707</wfw:commentRss><comments>http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx#comments</comments><description>&lt;p&gt;I think it was a good talk - too bad I only got through three tips :)&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:dddbe350-6920-44a4-9054-b4f2ed537260" style="margin: 0px; padding: 0px; display: inline;"&gt;&lt;div&gt;&lt;div style="width: 425px; text-align: left;" id="__ss_958662"&gt;&lt;object style="margin: 0px;" height="355" width="425"&gt;&lt;param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=top-ten-tips-for-tenacious-defense-in-aspnet-1233088335576626-1&amp;amp;stripped_title=top-ten-tips-for-tenacious-defense-in-aspnet-presentation"&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;param name="allowScriptAccess" value="always"&gt;&lt;embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=top-ten-tips-for-tenacious-defense-in-aspnet-1233088335576626-1&amp;amp;stripped_title=top-ten-tips-for-tenacious-defense-in-aspnet-presentation" mce_src="http://static.slideshare.net/swf/ssplayer2.swf?doc=top-ten-tips-for-tenacious-defense-in-aspnet-1233088335576626-1&amp;amp;stripped_title=top-ten-tips-for-tenacious-defense-in-aspnet-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="355" width="425"&gt;&lt;/object&gt;&lt;a href="http://static.slideshare.net/swf/ssplayer2.swf?doc=top-ten-tips-for-tenacious-defense-in-aspnet-1233088335576626-1&amp;amp;stripped_title=top-ten-tips-for-tenacious-defense-in-aspnet-presentation" style="left: 425px ! important; top: -355px ! important;" title="Click here to block this object with Adblock Plus" class="piitcxlmyadchqylinzw visible ontop"&gt;&lt;/a&gt;&lt;a href="http://keepitlocked.net/controlpanel/blogs/" style="left: 425px ! important; top: -355px ! important;" title="Click here to block this object with Adblock Plus" class="piitcxlmyadchqylinzw visible ontop"&gt;&lt;/a&gt;&lt;div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;"&gt;View more &lt;a href="http://www.slideshare.net/" style="text-decoration: underline;" mce_href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; or &lt;a href="http://www.slideshare.net/upload?type=powerpoint" style="text-decoration: underline;" mce_href="http://www.slideshare.net/upload?type=powerpoint"&gt;upload&lt;/a&gt; your own.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;You can download the slides &lt;a href="http://www.slideshare.net/alsmola/top-ten-tips-for-tenacious-defense-in-aspnet-presentation/download" mce_href="http://www.slideshare.net/alsmola/top-ten-tips-for-tenacious-defense-in-aspnet-presentation/download"&gt;here&lt;/a&gt; if you have a Slideshare account, or just send me an email.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;;subject=SoCalCodeCamp+Presentation+-+%26quot%3bTop+Ten+Tips+for+Tenacious+Defense+for+ASP.NET+Application%26quot%3b" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;;title=SoCalCodeCamp+Presentation+-+%26quot%3bTop+Ten+Tips+for+Tenacious+Defense+for+ASP.NET+Application%26quot%3b" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;title=SoCalCodeCamp+Presentation+-+%26quot%3bTop+Ten+Tips+for+Tenacious+Defense+for+ASP.NET+Application%26quot%3b" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;;title=SoCalCodeCamp+Presentation+-+%26quot%3bTop+Ten+Tips+for+Tenacious+Defense+for+ASP.NET+Application%26quot%3b" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx&amp;amp;;title=SoCalCodeCamp+Presentation+-+%26quot%3bTop+Ten+Tips+for+Tenacious+Defense+for+ASP.NET+Application%26quot%3b&amp;amp;;top=1" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/27/socalcodecamp-presentation-quot-top-ten-tips-for-tenacious-defense-for-asp-net-application-quot.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://keepitlocked.net/aggbug.aspx?PostID=1707" width="1" height="1"&gt;</description><category domain="http://keepitlocked.net/archive/tags/Software+Security/default.aspx">Software Security</category><category domain="http://keepitlocked.net/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://keepitlocked.net/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>@SoCalCodeCamp, Speaking</title><link>http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx</link><pubDate>Fri, 23 Jan 2009 19:35:00 GMT</pubDate><guid isPermaLink="false">a3f75fb5-0505-4d35-9795-aaa2ed659a71:1134</guid><dc:creator>Alex</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://keepitlocked.net/rsscomments.aspx?PostID=1134</wfw:commentRss><comments>http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.socalcodecamp.com/" mce_href="http://www.socalcodecamp.com/"&gt;&lt;img src="http://keepitlocked.net/images/keepitlockednet/WindowsLiveWriter/SoCalCodeCampSpeaking_A2DE/socalcodecamp_3.jpg" style="border: 0px none ;" alt="socalcodecamp" mce_src="http://keepitlocked.net/images/keepitlockednet/WindowsLiveWriter/SoCalCodeCampSpeaking_A2DE/socalcodecamp_3.jpg" border="0" height="83" width="604"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I'll be at &lt;a href="http://www.socalcodecamp.com/" mce_href="http://www.socalcodecamp.com/"&gt;SoCalCodeCamp&lt;/a&gt; this weekend (January 24-25, 2009), attending sessions and hanging out. I'll also be speaking on Sunday, January 25, at 9:00AM in &lt;a href="http://www.socalcodecamp.com/schedule.aspx?rt=UH%20250" mce_href="http://www.socalcodecamp.com/schedule.aspx?rt=UH%20250"&gt;UH 250&lt;/a&gt;, giving a presentation entitled "&lt;a href="http://www.socalcodecamp.com/session.aspx?sid=c5ca8fd9-522d-4515-aa9f-6dada5bdcecd" mce_href="http://www.socalcodecamp.com/session.aspx?sid=c5ca8fd9-522d-4515-aa9f-6dada5bdcecd"&gt;Top Ten Tips for Tenacious Defense in ASP.NET&lt;/a&gt;". &lt;/p&gt;  &lt;p&gt;I like SoCalCodeCamp. It's in my backyard (growing up a Fullertonite) and it's free for all participants. Also, somehow Rock n' Roll is involved. Looking forward to it.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;;subject=%40SoCalCodeCamp%2c+Speaking" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;;title=%40SoCalCodeCamp%2c+Speaking" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;title=%40SoCalCodeCamp%2c+Speaking" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;;title=%40SoCalCodeCamp%2c+Speaking" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx&amp;amp;;title=%40SoCalCodeCamp%2c+Speaking&amp;amp;;top=1" target="_blank" title = "Post http://keepitlocked.net/archive/2009/01/23/socalcodecamp-speaking.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://keepitlocked.net/aggbug.aspx?PostID=1134" width="1" height="1"&gt;</description><category domain="http://keepitlocked.net/archive/tags/Software+Security/default.aspx">Software Security</category><category domain="http://keepitlocked.net/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://keepitlocked.net/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>More ASP.NET CSRF Protection Options</title><link>http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx</link><pubDate>Tue, 16 Dec 2008 21:39:00 GMT</pubDate><guid isPermaLink="false">a3f75fb5-0505-4d35-9795-aaa2ed659a71:63</guid><dc:creator>Alex</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://keepitlocked.net/rsscomments.aspx?PostID=63</wfw:commentRss><comments>http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://idunno.org/" mce_href="http://idunno.org/"&gt;Barry Dorrans&lt;/a&gt; created a filter for &lt;a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery" mce_href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"&gt;CSRF&lt;/a&gt; protection in ASP.NET. It's inspired by the &lt;a href="http://blog.codeville.net/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/" mce_href="http://blog.codeville.net/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/"&gt;ASP.NET MVC CSRF token&lt;/a&gt; approach. It's a simple and effective protection mechanism when you can't use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.page.viewstateuserkey.aspx"&gt;ViewStateUserKey&lt;/a&gt; because you've disabled ViewState. It doesn't rely on sessions either. Now if I could only get him to support GET requests on an opt-in basis! Check out &lt;a href="http://idunno.org/archive/2008/12/14/announcing-anticsrf-for-asp.net.aspx" mce_href="http://idunno.org/archive/2008/12/14/announcing-anticsrf-for-asp.net.aspx"&gt;his blog post&lt;/a&gt; and the code on &lt;a href="http://www.codeplex.com/AntiCSRF/Release/ProjectReleases.aspx" mce_href="http://www.codeplex.com/AntiCSRF/Release/ProjectReleases.aspx"&gt;Codeplex&lt;/a&gt;.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;;subject=More+ASP.NET+CSRF+Protection+Options" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;;title=More+ASP.NET+CSRF+Protection+Options" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;title=More+ASP.NET+CSRF+Protection+Options" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;;title=More+ASP.NET+CSRF+Protection+Options" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx&amp;amp;;title=More+ASP.NET+CSRF+Protection+Options&amp;amp;;top=1" target="_blank" title = "Post http://keepitlocked.net/archive/2008/12/16/more-asp-net-csrf-protection-options.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://keepitlocked.net/aggbug.aspx?PostID=63" width="1" height="1"&gt;</description><category domain="http://keepitlocked.net/archive/tags/Software+Security/default.aspx">Software Security</category><category domain="http://keepitlocked.net/archive/tags/CSRF/default.aspx">CSRF</category><category domain="http://keepitlocked.net/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>ViewStateUserKey Doesn’t Prevent Cross-Site Request Forgery</title><link>http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx</link><pubDate>Thu, 29 May 2008 21:30:00 GMT</pubDate><guid isPermaLink="false">a3f75fb5-0505-4d35-9795-aaa2ed659a71:26</guid><dc:creator>Alex</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://keepitlocked.net/rsscomments.aspx?PostID=26</wfw:commentRss><comments>http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx#comments</comments><description>&lt;p&gt;ViewStateUserKey is not a completely effective mitigation against Cross-Site Request Forgery. It doesn't work for non post-backs (I.e. GET requests), and it doesn't work if the ViewState MAC is turned off.
&lt;/p&gt;&lt;p&gt;In &lt;a href="http://msdn.microsoft.com/en-us/library/ms972969.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms972969.aspx"&gt;several&lt;/a&gt;
		&lt;a href="http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation" mce_href="http://www.guidanceshare.com/wiki/ASP.NET_2.0_Security_Guidelines_-_Parameter_Manipulation"&gt;different&lt;/a&gt;
		&lt;a href="http://channel9.msdn.com/wiki/default.aspx/Channel9.ASPNETSecurityGuidelines" mce_href="http://channel9.msdn.com/wiki/default.aspx/Channel9.ASPNETSecurityGuidelines"&gt;places&lt;/a&gt;, we see a piece of advice repeated - use the ViewStateUserKey property to prevent One-Click Attacks. Often, this piece of advice is accompanied by the following code:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;
			&lt;span style="color: blue;"&gt;void&lt;/span&gt; Page_Init(&lt;span style="color: blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color: teal;"&gt;EventArgs&lt;/span&gt; e)
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;    {
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;        ViewStateUserKey = Session.SessionID;
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;    }
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;What exactly does this code do? To understand it, we first need to look at the ViewState mechanism itself. The ViewState is an ASP.NET mechanism used to persist the value of web controls between post-backs. This allows a lot of the drag and drop, UI-driven ASP.NET architecture to function "auto-magically" by serializing and de-serializing data automatically on the fly.
&lt;/p&gt;&lt;p&gt;The ViewState is encoded and stored as a hidden field. This introduces security issues, because the value is under the control of the client. There may be a value stored in a field that you do not want someone to see and modify, like an admin-only control with the visible property set to false.
&lt;/p&gt;&lt;p&gt;ASP.NET helps us out by introducing two mechanisms to help protect the ViewState. ViewState MAC prevents tampering with the ViewState by introducing a separate Message Authentication Code that is verified when the ViewState is submitted. ViewState Encryption protects the ViewState confidentially by encrypting the ViewState value. By default, the ViewState MAC is enabled, and ViewState Encryption is not.
&lt;/p&gt;&lt;p&gt;The ViewStateUserKey property is an optional addition to the data used in ViewState MAC calculation. If that value changes between post-backs, the ViewState MAC calculation will fail and the page will cause an error.
&lt;/p&gt;&lt;p&gt;When we set the value of ViewStateUserKey to something associated with a particular user (like a Session ID or a Username), we are making sure that the ViewState is valid &lt;i&gt;only for that user.&lt;/i&gt;
	&lt;/p&gt;&lt;p&gt;Back to One-Click Attacks. One-Click Attack is sometimes incorrectly referred to as Microsoft's name for Cross-Site Request Forgery. However, this is not entirely correct.
&lt;/p&gt;&lt;p&gt;One-Click Attacks refer to CSRF attacks that use a malicious ViewState to perform the request. Because web forms developed with ASP.NET use ViewState for post-backs, the attacker can perform the post-back they want the user to perform unknowingly, and record the ViewState. Due to the way that ASP.NET ignores HTTP verbs when using &lt;span style="font-family: Courier New;"&gt;Request.Params&lt;/span&gt; versus &lt;span style="font-family: Courier New;"&gt;Request.Form&lt;/span&gt;, and in web controls, this request can often be made via GET.
&lt;/p&gt;&lt;p&gt;Example:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;http://site/Default.aspx?__VIEWSTATE=%2FwEPDwULLTExOTcyMDExODNkZAShpi32DKvqCd4uvHuQ%2FmmnBcdY&amp;amp;TextBox1=&lt;span style="color: red;"&gt;&lt;b&gt;&amp;lt;MALICIOUS_CONTROL_DATA_GOES_HERE&amp;gt;&lt;/b&gt;&lt;/span&gt;&amp;amp;Button1=Button&amp;amp;__EVENTVALIDATION=%2FwEWAwKEyYGZBwLs0bLrBgKM54rG3sCHijug9ibUUfHX808cCvcppg1i
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;This link can be used in a CSRF attack. It is then known as a one-click attack, because it uses the ViewState. This, however, is not:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;http://site/DeleteUser.aspx?user_id=123456789
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;If the page is not a post-back (as in the case of a direct link), the ViewState MAC is never checked. Several ASP.NET applications allow you to modify data without submitting a form. Consider &lt;a href="http://www.asp.net/mvc/" mce_href="http://www.asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt; - it doesn't even use post-backs.
&lt;/p&gt;&lt;p&gt;Furthermore, the ViewState MAC can be disabled at the page level:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="background-color: yellow;"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue;"&gt;@&lt;/span&gt;
			&lt;span style="color: maroon;"&gt;Page&lt;/span&gt;
			&lt;span style="color: red;"&gt;Language&lt;/span&gt;&lt;span style="color: blue;"&gt;="C#"&lt;/span&gt;
			&lt;span style="color: red;"&gt;EnableViewStateMac&lt;/span&gt;&lt;span style="color: blue;"&gt;="false"&lt;/span&gt;&lt;span style="background-color: yellow;"&gt;%&amp;gt;&lt;/span&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;or in &lt;span style="font-family: Courier New;"&gt;web.config&lt;/span&gt;.:
&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon;"&gt;pages&lt;/span&gt;&lt;span style="color: blue;"&gt;
			&lt;/span&gt;&lt;span style="color: red;"&gt;enableViewStateMac&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;false&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;      
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Courier New; font-size: 10pt;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon;"&gt;pages&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;ViewState MAC is often disabled for (perceived) performance reason, or (more likely) if there is some functionality in the application that causes the ViewState MAC to cause error.
&lt;/p&gt;&lt;p&gt;This reminds of &lt;a href="http://keepitlocked.net/archive/2007/10/30/asp-net-validaterequest-and-the-html-attribute-based-cross-site-scripting.aspx" mce_href="http://keepitlocked.net/archive/2007/10/30/asp-net-validaterequest-and-the-html-attribute-based-cross-site-scripting.aspx"&gt;problems with Request Validation is ASP.NET&lt;/a&gt; - the mechanism works, sometimes. This can be dangerous, because people rely on it and can get burned. The solution is to write something similar to&lt;a href="http://www.owasp.org/index.php/Category:OWASP_CSRFGuard_Project" mce_href="http://www.owasp.org/index.php/Category:OWASP_CSRFGuard_Project"&gt; CSRFGuard&lt;/a&gt; from &lt;a href="http://www.owasp.org/index.php/Main_Page" mce_href="http://www.owasp.org/index.php/Main_Page"&gt;OWASP&lt;/a&gt; in .NET. I have a feeling that the newly resurgent &lt;a href="http://www.owasp.org/index.php/Category:OWASP_.NET_Project" mce_href="http://www.owasp.org/index.php/Category:OWASP_.NET_Project"&gt;OWASP .NET project&lt;/a&gt; will add this to their to-do list.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;;subject=ViewStateUserKey+Doesn%e2%80%99t+Prevent+Cross-Site+Request+Forgery" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;;title=ViewStateUserKey+Doesn%e2%80%99t+Prevent+Cross-Site+Request+Forgery" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;title=ViewStateUserKey+Doesn%e2%80%99t+Prevent+Cross-Site+Request+Forgery" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;;title=ViewStateUserKey+Doesn%e2%80%99t+Prevent+Cross-Site+Request+Forgery" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx&amp;amp;;title=ViewStateUserKey+Doesn%e2%80%99t+Prevent+Cross-Site+Request+Forgery&amp;amp;;top=1" target="_blank" title = "Post http://keepitlocked.net/archive/2008/05/29/viewstateuserkey-doesn-t-prevent-cross-site-request-forgery.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://keepitlocked.net/aggbug.aspx?PostID=26" width="1" height="1"&gt;</description><category domain="http://keepitlocked.net/archive/tags/Software+Security/default.aspx">Software Security</category><category domain="http://keepitlocked.net/archive/tags/CSRF/default.aspx">CSRF</category><category domain="http://keepitlocked.net/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>Developing ASP.NET in Partial Trust</title><link>http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx</link><pubDate>Fri, 11 Apr 2008 22:20:00 GMT</pubDate><guid isPermaLink="false">a3f75fb5-0505-4d35-9795-aaa2ed659a71:25</guid><dc:creator>Alex</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://keepitlocked.net/rsscomments.aspx?PostID=25</wfw:commentRss><comments>http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx#comments</comments><description>&lt;p&gt;Recently I developed a lab for our Writing Secure Code – ASP.NET training course where students modify Hacme Bank to run in Partial Trust rather than Full Trust.
&lt;/p&gt;

&lt;p&gt;A lot has been written about Partial Trust. It's not going to solve every security problem, but it's a smart thing to do. I wanted to show students that it was easy to take an existing application and get it to run with only the privileges it needed.
&lt;/p&gt;

&lt;p&gt;Turns out, there is more than one way to skin a cat. And, depending on your architecture, you may be spinning your wheels needlessly, as I learned the hard way.
&lt;/p&gt;

&lt;p&gt;Hacme Bank is based on the older &lt;span style="font-family: Courier New;"&gt;.asmx&lt;/span&gt; web service architecture, with the web front-end calling a service layer, which calls the database.
&lt;/p&gt;

&lt;p&gt;If we configure the site to run in the default Medium Trust level, it does not have access to the Hacme Bank web service (a &lt;span style="font-family: Courier New;"&gt;WebPermission&lt;/span&gt; error is thrown).
&lt;/p&gt;

&lt;p&gt;After a few hours of tinkering, reading, debugging, and throwing my innocent wireless mouse across the room (my preferred method of stress management), I discovered a couple of different methods that I could use to get this working. Thanks to &lt;a href="http://www.leastprivilege.com/" mce_href="http://www.leastprivilege.com/"&gt;Dominick Baier&lt;/a&gt; and &lt;a href="http://www.codesecurely.org" mce_href="http://www.codesecurely.org"&gt;Rudolph Araujo&lt;/a&gt; for seeding the clouds of this brainstorm.
&lt;/p&gt;

&lt;p&gt;The four options are:
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the &lt;span style="font-family: Courier New;"&gt;originUrl&lt;/span&gt; attribute in the &lt;span style="font-family: Courier New;"&gt;trust&lt;/span&gt; element of the &lt;span style="font-family: Courier New;"&gt;web.config&lt;/span&gt; file
&lt;/li&gt;

&lt;li&gt;Create a new custom trust level
&lt;/li&gt;

&lt;li&gt;Partition the privileged code into an assembly and install in the Global Assembly Cache
&lt;/li&gt;

&lt;li&gt;Partition the privileged code into an assembly and create a new custom trust level
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And, for those of you who aren't into reading longish blog posts, here's a summary of what I found:
&lt;/p&gt;
&lt;div&gt;
&lt;table style="border-collapse: collapse;" border="0" height="390" width="701"&gt;&lt;colgroup&gt;&lt;col style="width: 234px;"&gt;&lt;col style="width: 234px;"&gt;&lt;col style="width: 234px;"&gt;&lt;/colgroup&gt;&lt;tbody valign="top"&gt;
&lt;tr style="background: rgb(102, 102, 102) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;td style="border: 0.5pt solid rgb(217, 217, 217); padding-left: 5px; padding-right: 5px;"&gt;
&lt;p style="text-align: center;"&gt;&lt;b&gt;Approach&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: solid solid solid none; border-color: rgb(217, 217, 217) rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: 0.5pt 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p style="text-align: center;"&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: solid solid solid none; border-color: rgb(217, 217, 217) rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: 0.5pt 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p style="text-align: center;"&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217); border-width: medium 0.5pt 0.5pt; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Set the &lt;span style="font-family: Courier New;"&gt;originUrl&lt;/span&gt; attribute in the &lt;span style="font-family: Courier New;"&gt;trust&lt;/span&gt; element of the &lt;span style="font-family: Courier New;"&gt;web.config&lt;/span&gt; file
&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;&amp;nbsp;Really easy
&lt;/p&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;
Only works for web permissions (like calling a web service)
&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;

&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217); border-width: medium 0.5pt 0.5pt; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Create a new custom trust level
&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Only necessary permissions are granted 
&lt;/p&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;All code runs with the extra permissions
&lt;br&gt;
&lt;/p&gt;
&lt;ul&gt;

&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217); border-width: medium 0.5pt 0.5pt; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Partition the privileged code into an assembly and install in the Global Assembly Cache&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Only a small amount of code gets elevated privileges&lt;/p&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;The code that gets elevated privileges runs in Full Trust
&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;

&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td style="border-style: none solid solid; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217); border-width: medium 0.5pt 0.5pt; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Partition the privileged code into an assembly and create a new custom trust level&lt;/p&gt;
&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Only necessary permissions are granted and only a small amount of code gets elevated privileges&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;

&lt;/ul&gt;

&lt;/td&gt;

&lt;td style="border-style: none solid solid none; border-color: -moz-use-text-color rgb(217, 217, 217) rgb(217, 217, 217) -moz-use-text-color; border-width: medium 0.5pt 0.5pt medium; padding-left: 5px; padding-right: 5px;"&gt;
&lt;p&gt;Difficult&lt;/p&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Now for some background:
&lt;/p&gt;

&lt;p&gt;1. Set the &lt;span style="font-family: Courier New;"&gt;originUrl&lt;/span&gt; attribute in the &lt;span style="font-family: Courier New;"&gt;trust&lt;/span&gt; element of the &lt;span style="font-family: Courier New;"&gt;web.config&lt;/span&gt; file.
&lt;/p&gt;

&lt;ol&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;originUrl &lt;/span&gt;is an optional attribute that punches a hole in medium trust, allowing web connections to hosts defined by a regular expression. This is used to facilitate exactly what we need – connecting to a web service at an arbitrary location.
&lt;/p&gt;

&lt;p&gt;This is implemented by an entry in the &lt;span style="font-family: Courier New;"&gt;web_mediumtrust.config&lt;/span&gt; file:
&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;IPermission class="WebPermission" version="1"&amp;gt;
&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;ConnectAccess&amp;gt;
&lt;/span&gt;&lt;/p&gt;

&lt;p style="margin-left: 36pt;"&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;URI uri="$OriginHost$"/&amp;gt;
&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;/ConnectAccess&amp;gt;
&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: Courier New;"&gt;&amp;lt;/IPermission&amp;gt;&lt;/span&gt;
	&lt;/p&gt;

&lt;p&gt;Besides making this lab a little too easy, the &lt;span style="font-family: Courier New;"&gt;originUrl&lt;/span&gt; attribute is limited to web permissions and is not useful for different permission elevation scenarios such as accessing the registry or using reflection.
&lt;/p&gt;

&lt;p&gt;2. Create a new custom trust level.
&lt;/p&gt;

&lt;ol&gt;
&lt;/ol&gt;

&lt;p&gt;A more flexible approach is to create a new trust level. Usually this is done by copying over one of the policy files and adding the necessary permission. A good description is available at the Patterns and Practices site &lt;a href="http://msdn2.microsoft.com/en-us/library/ms998341.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms998341.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;While this approach gives us the tools to add arbitrary permissions to the code base, it doesn't exactly follow the principal of least privilege, because all of the code in the web site is granted the permissions, rather than just the code that requires them.
&lt;/p&gt;

&lt;p&gt;3. Partition the privileged code into an assembly and install in the Global Assembly Cache.
&lt;/p&gt;

&lt;ol&gt;
&lt;/ol&gt;

&lt;p&gt;In order to segregate duties and reduce the overall privileges granted, we can rip out the code that needs permissions and throw it in to a new assembly. This is also known as sandboxing. All code that can run with low privileges is in a very low privilege environment, and is given limited access to higher privilege functionality. This approach has some similarity with the Silverlight security model and the security safe critical attribute – I'll blog about this later.
&lt;/p&gt;

&lt;p&gt;Once we have our privileged code in a separate assembly, we need to configure our environment so that the privileged code can be accessed safely. First, the privileged assembly should be decorated with the &lt;span style="font-family: Courier New;"&gt;AllowPartiallyTrustedCallersAttribtue&lt;/span&gt;, strong nam signed, and (in this case) installed in the GAC. To protect the code from being accessed by other classes, we can add a Code Access Security demand that will prevent access by all but the required classes. We have a few options here:
&lt;/p&gt;

&lt;ol style="margin-left: 54pt;"&gt;
&lt;li&gt;Use a &lt;span style="font-family: Courier New;"&gt;StrongNameIdentityPermission&lt;/span&gt;. If we strong name the ASP.NET application (running with partial trust), we can verify the strong name in the privileged assembly. This, unfortunately, isn't as easy as you might think. It's not supported in Visual Web Developer Express 2008, and so it wouldn't work for my lab. In the full version of Visual Studio, we can strong name the assembly by adding a compiler option &lt;i&gt;however &lt;/i&gt;this means that we need to create a new trust level. This is because modifying compiler options requires unmanaged code permissions. The suggestion is to use this modified trust level while debugging, then to deploy the assembly as a pre-compiled, strongly named assembly, with the unmodified trust level. I feel that this is probably a bad design choice – there should be a simple option for the Visual Studio built-in web server to perform strong naming on the ASP.NET code to support this type of scenario in medium trust. One note - Dominick points out that strong naming doesn't scale particularly well, since more than one strong name cannot be demand (this will result in an AND condition).
&lt;/li&gt;

&lt;li&gt;Use the &lt;span style="font-family: Courier New;"&gt;UrlIdentityPermission&lt;/span&gt;. I wasn't able to get this working, but theoretically you could restrict the caller's file location to the URL &lt;span style="font-family: Courier New;"&gt;file://c:\directorytowebapp\*&lt;/span&gt;. Not sure if anyone has tried this successfully, but if you could, you may get around some of the difficulties around strong naming.
&lt;/li&gt;

&lt;li&gt;Use a custom permission. This may be the most natural way to express the demand and justify the extra effort in creating a new permission, which isn't trivial.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that these permissions do not prevent Full Trust callers from accessing the assembly. See this &lt;a href="http://blogs.msdn.com/eugene_bobukh/archive/2005/05/06/415217.aspx" mce_href="http://blogs.msdn.com/eugene_bobukh/archive/2005/05/06/415217.aspx"&gt;blog post&lt;/a&gt; for a description of why "Full Trust Means Full Trust"
&lt;/p&gt;

&lt;p&gt;One major problem here is that the assembly will run in the GAC with Full Trust. This is a fairly significant privilege escalation, even for a very small piece of code. However, we can do better.
&lt;/p&gt;

&lt;p&gt;4. Partition the privileged code into an assembly and create a new custom trust level.
&lt;/p&gt;

&lt;ol&gt;
&lt;/ol&gt;

&lt;p&gt;In this approach, we will combine approaches 2 and 3 to get the best of both worlds. We partition the code into a privileged assembly and the low privileged web site, taking into account the precautions discussed in the previous step. Then, rather than installing the code in the GAC, we create a custom policy file (as described in approach 2) and add a new code group which refers to our privileged assembly, and assign that code group a permission set that has only the requisite permissions. This approach is described in the hyperbolically-titled but otherwise helpful article "&lt;a href="http://www.devx.com/codemag/Article/37396/1763/page/5" mce_href="http://www.devx.com/codemag/Article/37396/1763/page/5"&gt;Never Write an Insecure ASP.NET Application Ever Again&lt;/a&gt;" and in Dominick's &lt;a href="http://www.microsoft.com/mspress/books/9989.aspx" mce_href="http://www.microsoft.com/mspress/books/9989.aspx"&gt;book&lt;/a&gt; (pages 330-332). One thing to note here is that you don't use the .NET Framework Configuration tool to set the security policy for the privileged assembly – you want to use the ASP.NET policies in the &lt;span style="font-family: Courier New;"&gt;.config&lt;/span&gt; file. Boy, I wish I had known that a few days ago.
&lt;/p&gt;

&lt;p&gt;This approach gives us the best shot at least privilege, and is extremely flexible. However, it's probably not appropriate for the couple of hours that the students have to complete the lab. Hopefully in the future we'll get an easy way to a) secure a privileged assembly with a simple permission demand and b) create a new trust level based off medium trust and c) create a new code group in the custom trust level based on the strong name of the privileged assembly.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;;subject=Developing+ASP.NET+in+Partial+Trust" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;;title=Developing+ASP.NET+in+Partial+Trust" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;title=Developing+ASP.NET+in+Partial+Trust" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;;title=Developing+ASP.NET+in+Partial+Trust" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx&amp;amp;;title=Developing+ASP.NET+in+Partial+Trust&amp;amp;;top=1" target="_blank" title = "Post http://keepitlocked.net/archive/2008/04/11/developing-asp-net-in-partial-trust.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://keepitlocked.net/aggbug.aspx?PostID=25" width="1" height="1"&gt;</description><category domain="http://keepitlocked.net/archive/tags/Software+Security/default.aspx">Software Security</category><category domain="http://keepitlocked.net/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item></channel></rss>