<?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>.NET Security Blog : ClickOnce</title><link>http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx</link><description>Tags: ClickOnce</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>CLR v4 Security Policy Roundup</title><link>http://blogs.msdn.com/shawnfa/archive/2009/06/12/clr-v4-security-policy-roundup.aspx</link><pubDate>Fri, 12 Jun 2009 21:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9737125</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/9737125.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=9737125</wfw:commentRss><description>&lt;P&gt;Over the last few weeks we’ve been taking a look at the updates to the CLR security policy system in the v4 release of the .NET Framework.&amp;nbsp; Here’s a quick index of those topics:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Overview&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/05/21/security-policy-in-the-v4-clr.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/05/21/security-policy-in-the-v4-clr.aspx"&gt;Security Policy in the v4 CLR&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/05/22/sandboxing-in-net-4-0.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/05/22/sandboxing-in-net-4-0.aspx"&gt;Sandboxing in .NET 4.0&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Updating code to work with the new model&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx"&gt;Implicit uses of CAS policy part 1 (Assembly.Load with Evidence, AppDomain creation with Evidence)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx"&gt;Implicit uses of CAS policy part 2 (loading assemblies from remote sources)&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/06/09/coding-with-security-policy-in-net-4-part-2-explicit-uses-of-cas-policy.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/06/09/coding-with-security-policy-in-net-4-part-2-explicit-uses-of-cas-policy.aspx"&gt;Explicit uses of CAS policy (APIs such as SecurityManager which directly use CAS policy)&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Temporarily re-enabling CAS policy during migration&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2009/06/12/temporarily-re-enabling-cas-policy-during-migration.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2009/06/12/temporarily-re-enabling-cas-policy-during-migration.aspx"&gt;The NetFx40_LegacySecurityPolicy config file switch&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9737125" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>FullTrust on the LocalIntranet</title><link>http://blogs.msdn.com/shawnfa/archive/2008/05/12/fulltrust-on-the-localintranet.aspx</link><pubDate>Mon, 12 May 2008 20:49:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8495622</guid><dc:creator>shawnfa</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/8495622.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=8495622</wfw:commentRss><description>&lt;p&gt;We released the &lt;a href="http://blogs.msdn.com/somasegar/archive/2008/05/12/visual-studio-2008-and-net-fx-3-5-sp1-beta-available-now.aspx"&gt;first beta of .NET 3.5 SP 1&lt;/a&gt; this morning, and it includes a change to the default grant set for applications launched from the LocalIntranet zone.&amp;nbsp; The quick summary is that as of .NET 3.5 SP1, applications run from a network share will receive a grant set of FullTrust by default, making them act the same as if they were launched off of your computer directly.&amp;nbsp; Since this is an issue that &lt;a href="http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx"&gt;I know a lot of people run into&lt;/a&gt;, I hope that this change makes it easier to use and deploy managed applications.&amp;nbsp; For people who want to keep their machines working the same as they did for previous .NET Framework releases, you can set the DWORD registry value LegacyMyComputerZone to 1 in the HKLM\Software\Microsoft\.NETFramework registry key.&lt;/p&gt; &lt;p&gt;With the high-level summary out of the way, let's take a look under the hood to see what changed to make this possible :-)&lt;/p&gt; &lt;p&gt;The core of this change is a modification in how we assign evidence to network launched applications.&amp;nbsp; When we see an .exe launched directly off a network share, rather than giving that .exe Zone evidence of LocalInranet, we instead give the .exe Zone evidence of MyComputer.&amp;nbsp; This causes the .exe to match the default MyComputer code group rather than the LocalIntranet group, and in default CAS policy that code group grants FullTrust.&amp;nbsp;&amp;nbsp; (This also explains why the opt-out registry value is named LegacyMyComputerZone)&lt;/p&gt; &lt;p&gt;In addition to the entry point .exe of the application, we'll also extend this MyComputer evidence to any assembly loaded from the same directory as the .exe.&amp;nbsp; So, if you place any managed .dll's immediately next to your .exe, those will also all be given FullTrust by default in .NET 3.5 SP1.&lt;/p&gt; &lt;p&gt;Since we're only including assemblies loaded from the same directory as the entry point application, things will just work for most applications, however more complicated programs that need to load assemblies from different subdirectories or other network shares may not see all of their assemblies get fully trusted by default.&amp;nbsp; For these more types of applications, ClickOnce deployment is the recommended way to elevate to FullTrust.&lt;/p&gt; &lt;p&gt;We've specifically disabled this change for any hosted applications.&amp;nbsp; So this means that if your program uses the CorBindToRuntime API to host the CLR, we won't start trusting assemblies it loads from a share.&amp;nbsp; Similarly, hosts like Internet Explorer will not start trusting controls that it loads into the browser.&lt;/p&gt; &lt;p&gt;To summarize the under the hood changes, assemblies which will now receive Zone evidence of MyComputer and therefore be fully trusted by default are:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Any managed .exe which is launched directly from a network share&lt;/li&gt; &lt;li&gt;Any assembly in that .exe's process which is loaded from the same directory as the .exe itself was.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Assemblies which will not see this change include:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Assemblies loaded from a subdirectory of the share where the .exe was launched from&lt;/li&gt; &lt;li&gt;Assemblies loaded from shares other than the one where the main .exe was launched&lt;/li&gt; &lt;li&gt;Any assembly loaded on a machine with the LegacyMyComputer registry value set to 1&lt;/li&gt; &lt;li&gt;Any assembly loaded into a CLR host, including assemblies loaded into Internet Explorer as controls.&lt;/li&gt; &lt;li&gt;Any assembly loaded from shares by an application that was launched from the "real" MyComputer zone.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8495622" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>Avoiding Assembly Level Declarative Security</title><link>http://blogs.msdn.com/shawnfa/archive/2007/10/02/avoiding-assembly-level-declarative-security.aspx</link><pubDate>Tue, 02 Oct 2007 19:24:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5244758</guid><dc:creator>shawnfa</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/5244758.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=5244758</wfw:commentRss><description>&lt;p&gt;I've written in the past about &lt;a href="http://blogs.msdn.com/shawnfa/archive/2004/08/30/222918.aspx"&gt;the three assembly level declarative security actions&lt;/a&gt;: RequestMinimum, RequestOptional, and RequestRefuse.&amp;nbsp; Although the CLR has supported these since v1.0, I tend to stay away from using them as much as I possibly can, and also recommend that others avoid them as well.&amp;nbsp; Let me go through each one individually:&lt;/p&gt; &lt;h2&gt;RequestMinimum&lt;/h2&gt; &lt;p&gt;RequestMinimum is the most common of the three, and in fact is &lt;a href="http://msdn2.microsoft.com/en-us/library/ms182325(VS.80).aspx"&gt;mentioned by a FxCop rule&lt;/a&gt; and automatically inserted by the C# compiler in some cases.&amp;nbsp; There are several reasons I don't like to use this security action.&lt;/p&gt; &lt;p&gt;The first problem I have with RequestMinimum is a usability problem stemming from the fact that if&amp;nbsp;your assembly is not granted its RequestMinimum permission set, the CLR will refuse to load it by throwing an exception.&amp;nbsp; If the assembly in question happens to be the entry point of my application, that means the user of my app ends up&amp;nbsp;staring down an unhandled exception dialog (since my&amp;nbsp;code never got loaded, and therefore never had a chance to handle this error more&amp;nbsp;gracefully).&amp;nbsp; If my mother runs an app I give her and it throws a FileLoadException due to insufficient permissions, she's not going to have any idea what to do with that.&lt;/p&gt; &lt;p&gt;Even if the assembly is not the entry point assembly, gracefully handling failure to load due to RequestMinimum means that an application needs a try ... catch around every code path which could potentially lead to loading the assembly in question; that's not something that a lot of applications are setup to do.&lt;/p&gt; &lt;p&gt;The other problem I find with RequestMinimum is that in the case of writing a shared library it's very difficult to figure out what the correct grant set to request is.&amp;nbsp; Unless all of the APIs being exposed require the same set of permissions, having only a single RequestMinimum set doesn't help much.&amp;nbsp; For instance, an assembly like System.dll exposes hundreds of classes each with indivdual permission requirements varying from SecurityPermission/Execution to FullTrust.&amp;nbsp; If we decided to use the minimum grant set of any API in the assembly as the ReuqestMinimum, we've somewhat defeated the purpose of the security action; now I cannot be assured that the assembly loading means that it has the required permissions to work in all cases.&amp;nbsp; On the other hand, if I use the maximum grant set required, the assembly won't load even if an application was only intending to use APIs that would work in the grant set that the assembly is loaded into.&lt;/p&gt; &lt;p&gt;Finally, since security demands go against the entire call stack, even if the assembly in question has all the permissions that it needs to run doesn't mean that all assemblies and AppDomains on the call stack will have those permissions.&amp;nbsp; So even if an assembly does have its minimum grant set met, it doesn't have any guarantee that its APIs will all work without throwing a SecurityException.&lt;/p&gt; &lt;h2&gt;RequestOptional&lt;/h2&gt; &lt;p&gt;RequestOptional is probably the least commonly used assembly level security action, and with good reason.&amp;nbsp; This security action is somewhat poorly named, and people who use it for the first time often don't realize that &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/09/14/466661.aspx"&gt;it will actually remove permissions from your grant set&lt;/a&gt;.&amp;nbsp; In fact, I run across RequestOptional most commonly when helping someone debug a SecurityException that they can't figure out.&amp;nbsp; ("Why does this exception&amp;nbsp;occur? All assemblies should be fully trusted!")&lt;/p&gt; &lt;p&gt;Even once you do understand the full effect of RequestOptional, the fact that it is confusingly named and that most people do not understand it is argument enough for me&amp;nbsp;to stay away.&amp;nbsp; Code readability is extremely important, and if I can expect that the next person to read through my code will be confused by that RequestOptional I stuck on my assembly, that's not a good thing -- especially when it comes to security.&lt;/p&gt; &lt;h2&gt;RequestRefuse&lt;/h2&gt; &lt;p&gt;I expect this is the most controversial security action to take a stance against.&amp;nbsp; A good number of people probably use RequestRefuse as a least-privilege mechanism.&amp;nbsp; My problem with that is that you're stating "I don't want permissions A and B", however when someone comes along and introduces permission C you haven't refused it, and therefore you still get it.&amp;nbsp; Personally, I believe the CLR has other, much better, least-privilege mechanisms available -- and I prefer to use those whenever possible.&amp;nbsp; (Sounds like the topic of a future blog post :-) ).&lt;/p&gt; &lt;p&gt;Finally, and this should come as no surprise to any regular visitors, &lt;a href="http://blogs.msdn.com/shawnfa/archive/2006/04/19/579066.aspx"&gt;I'm a huge fan of the model where every sandboxed AppDomain has exactly two permission sets -- FullTrust and one sandbox grant set&lt;/a&gt;.&amp;nbsp; RequestRefuse (and RequestOptional) both detract from this model by creating multiple permission sets within an otherwise homogenous AppDomain.&amp;nbsp; By keeping AppDomains entirely homogenous, it's much easier to reason about security within the domain.&amp;nbsp; And, in my opinion, keeping&amp;nbsp;the security model as simple as possible&amp;nbsp;can only be goodness -- complexity can lead to&amp;nbsp;mistakes in reasoning, which&amp;nbsp;leads to security holes.&amp;nbsp;&lt;/p&gt; &lt;h2&gt;So What Instead?&lt;/h2&gt; &lt;p&gt;Some of the abilities promised by the assembly level declarative security actions seem to be very useful at first glance.&amp;nbsp; Notably the ability to specify a grant set that the code was tested to run in (which is what RequestMinimum seems to promise) and the ability to run with least privilege (via RequestRefuse).&lt;/p&gt; &lt;p&gt;For RequestMinimum, I think that ClickOnce is a far superior alternative for a variety of reasons.&amp;nbsp; Most importantly, ClickOnce gives the user of the application a nicer experience when the application does not by default meet the minimum grant set.&amp;nbsp; Rather than throwing an exception in the face of a non-developer, a friendly user interface is displayed which may even offer the ability to grant the application the ability to run.&lt;/p&gt; &lt;p&gt;Also, the grant set specified for a ClickOnce application applies to all of the assemblies in the application as well as the AppDomain&amp;nbsp; (hey -- it's my favorite homogenous model again!).&amp;nbsp; This means that you don't have to worry about the scenario where your assembly meets its minimum grant set, but some APIs still fail with SecurityExceptions because another assembly further up the call stack did not meet the minimum grant set.&lt;/p&gt; &lt;p&gt;That covers RequestMinimum -- but what about the least privilege promise of RequestRefuse?&amp;nbsp; As AB might say -- that's another show.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5244758" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>Specifying Permissions for IE Controls in Orcas</title><link>http://blogs.msdn.com/shawnfa/archive/2007/03/07/specifying-permissions-for-ie-controls-in-orcas.aspx</link><pubDate>Wed, 07 Mar 2007 22:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1830177</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/1830177.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=1830177</wfw:commentRss><description>&lt;P&gt;One of my most read blog posts (and one of the reasons I created this blog in the first place -- to answer what was one of the most asked questions on the old .NET Security newsgroup), is my post about &lt;A href="http://blogs.msdn.com/shawnfa/archive/2003/06/26/57026.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2003/06/26/57026.aspx"&gt;granting managed controls hosted in IE extra permissions&lt;/A&gt;.&amp;nbsp; If you need to have a managed control run above its default grant set, the process getting this working in .NET versions through&amp;nbsp;.NET 2.0&amp;nbsp;was relatively painful.&lt;/P&gt;
&lt;P&gt;You needed to create an extra code group that granted your control the permissions required, and then get that policy deployed to all client machines.&amp;nbsp; One of the more common ways of doing this is to use the .NET MMC snap-in to create a policy MSI file.&amp;nbsp; However, those policy files are snapshots of policy and overwrite any other custom policy settings on each client machine.&amp;nbsp; This means if a user has two controls they use that require an MSI prerequisite, they end up fighting for control over policy -- only the last one installed wins.&amp;nbsp; There's also no guarantee that client machines have run my MSI file, so unless the control does runtime permission checking it will sometimes fail on misconfigured machines.&lt;/P&gt;
&lt;P&gt;Versioning provides another challenge here.&amp;nbsp; Since &lt;A href="http://blogs.msdn.com/shawnfa/archive/2006/07/11/661769.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2006/07/11/661769.aspx"&gt;every CLR has independent security policy&lt;/A&gt;&amp;nbsp;and IE will always load the latest runtime version when hosting a control, as soon as a new version of the CLR ships all changes in policy will no longer apply to hosted controls, and new MSIs will need to be created.&lt;/P&gt;
&lt;P&gt;On top of all of these challenges, is the problem mentioned in the original blog post -- namely that the AppDomain hosting the control will only have Url and Zone evidence.&amp;nbsp; If your code group uses a stronger membership condition (and it probably should) such as StrongName or Publisher, any demands will fail when they hit the AppDomain boundary because the domain will not match your code group and will have lower trust than your assembly.&amp;nbsp; This required adding an assert at each of the control's entry points, which is not really a great coding practice.&lt;/P&gt;
&lt;P&gt;With all of these problems, it's pretty obvious that we need a better solution for controls which need to run with higher permission than default.&amp;nbsp; A lot of these problems apply to applications as well as controls, and we solved them in .NET 2.0 by having those applications use ClickOnce.&amp;nbsp; Since ClickOnce applications can specify their required permissions in a manifest and allow the user to decide if this is a safe set of permissions to grant, there was no policy modification.&lt;/P&gt;
&lt;P&gt;Orcas introduces a very similar system for IE hosted controls.&amp;nbsp; They can now include a set of manifests, which are very similar to the ClickOnce manifests, that state the required set of permissions for the control to run.&amp;nbsp; Again, this decouples the control from policy which solves the MSI-fight problem as well as the CLR versioning problem.&amp;nbsp; Just like ClickOnce applications, these controls are hosted in &lt;A href="http://blogs.msdn.com/shawnfa/archive/2006/04/19/579066.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2006/04/19/579066.aspx"&gt;simple sandbox domains&lt;/A&gt; -- this means that the domain and the control both have the same permission set, removing the need to assert at the entry points.&lt;/P&gt;
&lt;P&gt;One of the first&amp;nbsp;questions that comes to mind when thinking about this feature is if a control is allowed to declaratively state what permissions it wants to run with, what's to prevent malicious controls from elevating to FullTrust and doing whatever it wants to my machine?&amp;nbsp; We've decided not to do any prompting of the user for this feature, instead we use a simple algorithm to determine if the control should be allowed to run with its requested permissions.&amp;nbsp; Specifically, if any of these requirements are met, then we allow the control to run:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The control is requesting a subset of the permissions it would have gotten anyway.&amp;nbsp; So if a control is coming from the Internet zone and it is requesting the Internet permission set, we'll allow it to run.&lt;/LI&gt;
&lt;LI&gt;The control is signed by a trusted publisher.&amp;nbsp; The control's deployment manifest must be signed (more on the requirements for manifests later) by a X.509 certificate.&amp;nbsp; If the signer is in the client's trusted publisher list and the certificate is valid and chains to a trusted root, then we allow the control to run with whatever permissions it requests.&amp;nbsp; This is likely the easiest way for IT organizations to make use of the feature, as trusted publishers can be controlled via group policy.&lt;/LI&gt;
&lt;LI&gt;If the zone the manifest is running from explicitly allows controls loaded from it to elevate their permissions&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;If all three of those checks fail, then the control is not allowed to run.&amp;nbsp; (Note that we don't run the control with the permissions it would be granted from policy if these checks fail -- we assume that the control was authored to run with the specified set of permissions, and should not be run with less than the requested set).&lt;/P&gt;
&lt;P&gt;The third check may need a little more explanation.&amp;nbsp; When you install Orcas, you'll see that a new option has been added to the Internet Explorer Security Settings dialog box called "Permissions for components with manifests":&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/photos/shawnfa/images/1830158/original.aspx" mce_href="http://blogs.msdn.com/photos/shawnfa/images/1830158/original.aspx"&gt;&lt;IMG src="http://blogs.msdn.com/photos/shawnfa/images/1830158/original.aspx" mce_src="http://blogs.msdn.com/photos/shawnfa/images/1830158/original.aspx"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;As you can see, there are three possible values for this setting:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;Disable&lt;/EM&gt; - controls with manifests will not be allowed to run at all.&amp;nbsp; Even if the control is requesting only Execution permission and is signed by a trusted publisher, if the zone it's loaded from is set to disabled the CLR will not allow the control to run.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;High Safety&lt;/EM&gt; - controls are not allowed to elevate their permissions via this setting alone.&amp;nbsp; If the control is not requesting elevation or is signed by a trusted publisher than it will be allowed to run, however this setting will cause check #3 above to fail.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Low Safety (Unrestricted)&lt;/EM&gt; - controls are allowed to elevate.&amp;nbsp; Even if the first two elevation checks fail, if the zone is set to low safety, then the control will be allowed to run with whatever permissions it asks for.&amp;nbsp; The reason that "Unrestricted" appears in the setting is that by setting this value, you're effectively giving all controls loaded from this zone the ability to run fully trusted.&amp;nbsp; Obviously that's not something that should be done lightly if at all. &lt;EM&gt;[Updated 1/24/2008 - Low Safety was removed after the Orcas betas.]&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Essentially, if the setting for the deployment manifest's zone is High Safety then elevation check #3 fails, if it is Low Safety then elevation check #3 succeeds.&amp;nbsp; The default values for this setting are:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width=400 border=1 unselectable="on"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;MyComputer&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;Disable&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;Local Intranet&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;High Safety&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;Trusted Sites&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;High Safety&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;Internet&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;High Safety&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;Restricted Sites&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;Disable&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;So no zone will elevate by default, and manifested controls are disabled entirely on the local machine and restricted sites.&lt;/P&gt;
&lt;P&gt;Next time: More information about the manifests&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1830177" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Orcas/default.aspx">Orcas</category></item><item><title>ClickOnce Same Site Permissions</title><link>http://blogs.msdn.com/shawnfa/archive/2006/07/15/665763.aspx</link><pubDate>Sat, 15 Jul 2006 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:665763</guid><dc:creator>shawnfa</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/665763.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=665763</wfw:commentRss><description>&lt;P&gt;ClickOnce applications can request that they be granted permission to contact their site of origin.&amp;nbsp; In Visual Studio this is done by clicking on the Advanced button in the Security tab of the project properties and checking "Grant the application access to its site of origin."&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/photos/shawnfa/picture665771.aspx" target=_blank&gt;&lt;IMG src="http://blogs.msdn.com/photos/shawnfa/images/665771/640x379.aspx" border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This has the effect of adding a SameSite attribute onto the requested permission set XML:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;
&lt;P&gt;&amp;lt;PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" &lt;FONT color=maroon&gt;SameSite="site"&lt;/FONT&gt;&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Access="Open" /&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Allowed="ApplicationIsolationByUser" UserQuota="512000" /&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Assertion, UnmanagedCode, Execution, ControlThread, ControlEvidence, ControlPolicy, SerializationFormatter, ControlDomainPolicy, ControlPrincipal, ControlAppDomain, RemotingConfiguration, Infrastructure" /&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Window="SafeTopLevelWindows" Clipboard="OwnClipboard" /&amp;gt; &lt;BR&gt;&amp;nbsp; &amp;lt;IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" version="1" Level="SafePrinting" /&amp;gt; &lt;BR&gt;&amp;lt;/PermissionSet&amp;gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The SameSite attribute is ignored by the CLR unless we're reading the PermissionSet XML from a ClickOnce manifest.&amp;nbsp; In that case, if we see the value of SameSite="site", we'll add in any appropriate permissions for the ClickOnce application to communicate with its site of origin.&lt;/P&gt;
&lt;P&gt;So what permissions does SameSite="site" grant exactly?&amp;nbsp; The answer is basically what you would expect, a WebPermission with Connect access back to the site the application was deployed from.&amp;nbsp; So if your application lived on http://www.fantasticsoftware.com/KillerApplicaton/KillerApplication.application you would be given a web permission with connect access to anything matching the regular expression:&lt;/P&gt;
&lt;P&gt;(http|https)://www.fantasticsoftware.com/.*&lt;/P&gt;
&lt;P&gt;Applications deployed over https will only receive permission to connect back via https, and applications deployed over a non-default port will have connect access back to that port instead of the default one.&lt;/P&gt;
&lt;P&gt;If the application is run directly from the file system, for example off of a network share, instead of a WebPermission it will get a FileIOPermission for read and path discovery back to the path it was deployed from.&amp;nbsp; \\InternalSoftware\Software\AccountingApplication\AccountingApplication.application will get access to \\InternalSoftware\Software\AccountingApplication for instance.&lt;/P&gt;
&lt;P&gt;In the event that the application already had a WebPermission or FileIOPermission in its requested permission set, then the same site permission will be unioned with the existing permission to form the final request set.&amp;nbsp; You can see the final permission set by examining the &lt;A href="http://msdn2.microsoft.com/en-us/library/system.security.policy.applicationsecurityinfo.defaultrequestset.aspx"&gt;DefaultRequestSet property&lt;/A&gt; of an ApplicationSecurityInfo object &lt;A href="http://msdn2.microsoft.com/en-us/library/system.security.policy.applicationsecurityinfo.applicationsecurityinfo.aspx"&gt;constructed with the ActivationContext&lt;/A&gt; of your ClickOnce application.&lt;/P&gt;
&lt;P&gt;Why go through all this trouble instead of just hard coding the WebPermission or FileIOPermission into the manifest itself?&amp;nbsp; By adding this level of abstraction, the application author does not need to know where the application will finally be deployed from.&amp;nbsp; If your group builds a ClickOnce application, specifying SameSite="site" allows the IT group which is hosting the application to decide which location makes the most sense.&amp;nbsp; It also gives them the freedom to move the application's location if need be without having to contact you to get the application updated.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=665763" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category></item><item><title>Sandboxed Applications Can’t Elevate Their Own Permissions</title><link>http://blogs.msdn.com/shawnfa/archive/2006/07/13/664789.aspx</link><pubDate>Thu, 13 Jul 2006 21:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:664789</guid><dc:creator>shawnfa</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/664789.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=664789</wfw:commentRss><description>&lt;p&gt;Every once in a while someone will ask how they can do something similar to these &lt;a href="http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx"&gt;caspol commands&lt;/a&gt; from within their application.  Generally, they want their application to be deployed from the Internet or a file share and don’t want users to have to deal with setting up CAS policy properly to get the application to run.
&lt;/p&gt;&lt;p&gt;The answer of course is that you can’t do this … if an application were allowed to add code groups to policy without user interaction in order to elevate their privileges then every malicious application out there would go ahead and grant themselves full access to everybody’s machine; effectively rendering CAS useless as a protection mechanism.
&lt;/p&gt;&lt;p&gt;Instead, you’ll need to have the end user make a trust decision for you.  In v1.x this was difficult, you generally had to deploy a policy MSI for the user to run or give them a set of caspol commands.  With v2.0 of the CLR, we’ve made things a lot easier via ClickOnce applications.   You can use ClickOnce to request any permissions that your application needs to run effectively – if these permissions would elevate the application above what it would normally get, then the user is prompted to make a trust decision.
&lt;/p&gt;&lt;p&gt;This way your app can elevate to whatever permission level it needs, and you don’t have to worry about pushing out confusing CAS policy changes to everyone who wants to run it.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=664789" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>5 Reasons to Choose Simple Sandboxing</title><link>http://blogs.msdn.com/shawnfa/archive/2006/04/19/579066.aspx</link><pubDate>Wed, 19 Apr 2006 18:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:579066</guid><dc:creator>shawnfa</dc:creator><slash:comments>17</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/579066.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=579066</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;When it comes time to host some partially trusted code in your application, perhaps as a part of an Add-In model, you’ve got a few options to choose from.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;How do you decide which is the best way to go?&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Thankfully the answer to this one is relatively straightforward – choose the new simple sandboxing model whenever possible.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Here’s 5 good reasons to prefer it over other options:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=4&gt;1. It provides an effective sandbox&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;A HREF="/shawnfa/archive/2006/02/02/523390.aspx"&gt;We’ve&amp;nbsp;already talked about why using PermitOnly or Deny to sandbox code is not an effective option&lt;/A&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The primary issue is that both of these are simply stack walk modifiers, and have no effect on the grant set of any assembly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Because of that, they can be overridden with an Assert in the sandboxed assembly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The sandboxed code (and I’m using that term very loosly in this context), won’t even have to Assert to satisfy a LinkDemand or an InheritenceDemand since those are done at JIT time and do not involve a stack walk.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;In addition to being ineffective against various CAS demands, these stack walk modifiers make life much harder when it comes to protecting sensitive information.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since static variables are shared on an AppDomain level, any static state that your application may maintain needs to be protected against these “sandboxed” assemblies.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If you were to create a new AppDomain to sandbox in, the shared state problem goes away because each AppDomain gets a new copy of the static data.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Since these stack modifiers obviously cannot create an effective sandbox, we’re left with two options, the legacy sandboxed domain using a &lt;A HREF="/shawnfa/archive/2004/10/25/247379.aspx"&gt;v1.x AppDomain policy level&lt;/A&gt;, and the new &lt;A HREF="/shawnfa/archive/2005/08/08/449050.aspx"&gt;v2.0 simple sandboxing API&lt;/A&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The next four points show why it’s generally preferable to pick the v2.0 model if you don’t have to run your code on the v1.x runtimes.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=4&gt;2. Simpler to Create&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Even for the most basic of sandboxes, a simple sandbox takes about 50% less code to create than the v1.x sandbox – and reducing the number of lines of security code in your application is goodness.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Not only are lines of code reduced, but the code itself is much easier to read and understand.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The input to the simple sandboxing API is a single permission set to grant all partially trusted assemblies (and the domain itself), along with a list of assemblies to grant FullTrust (presumably assemblies provided by your hosting application).&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;On the other hand, the input to the legacy sandboxing API was a policy tree and some evidence.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In order to figure out what permissions each assembly is going to get within the domain, you need to draw out the tree and evaluate its evidence against the policy.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The same goes for the AppDomain itself.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Of course, to do this, you need to understand the various evidences that an Assembly might have.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Does your hosting application provide custom evidence?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Does it remove or add evidence that the CLR provided?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Exactly which evidence will the CLR be providing for each assembly anyway?&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;And, once you’ve determined all that, you’ve only figured out the maximum permission set that an assembly will have.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since the AppDomain policy level is intersected with the other three policy levels, you might end up with fewer permissions than you though.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Getting the policy tree right in the first place can also be deceptively tricky.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What membership condition do you want?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Which merge logic for child code groups?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What parent code groups should be added?&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;When doing a code review, the upper hand is clearly to the simple sandboxing API on this front, since it’s very clear what the permission sets to be granted to each assembly are.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In the legacy model, you can’t determine that just by looking at the code alone, since you’ll need to know the evidence granted to every one of the assemblies to be loaded into the domain.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Due to the potential complexities involved, getting the policy tree correct can be difficult, whereas setting up a simple sandbox is relatively straightforward.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=4&gt;3. Simpler to Understand and Reason About&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;I touched on this a bit in the previous point.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The “simple” in the simple sandboxing API isn’t just about the code needed to create the domain.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It’s also about making it easier to reason about the domain and code that runs in it.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Since a legacy sandboxed domain can have arbitrary policy, with arbitrary grant sets to every individual assembly loaded into it, you run into several complexities.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The first one is just making sure that you’ve actually correctly calculated the grant set for each assembly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You also need to make sure that whatever evidence that you supplied the AppDomain will provide a secure enough backdrop for any demands that happen to hit that boundary.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Assuming that you’ve got the various grant sets of the assemblies figured out, you now have to keep each of these sets in mind when coding and reviewing any code that runs in the sandbox.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Does it work correctly when called by each of the other permission sets floating around?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Any code that’s being called by code with a lower permission set needs to be designed and written so that it cannot be tricked into elevating the lower permission set to its own permission set – something that can be surprisingly tricky.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(Although &lt;A HREF="/shawnfa/archive/2005/08/31/458641.aspx"&gt;transparent code&lt;/A&gt; helps you out a ton here).&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;When you use the simple sandboxing API, you’ve got exactly two permission sets floating around your domain, the sandboxed permission set and FullTrust.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(Of course, nothing is preventing you from making the sandboxed set FullTrust so that you have only one set, although that’s not really sandboxing as much as separating code for reliability’s sake).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Having just these two permission sets means that you know the core set of code which needs to worry about elevation attacks.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It also means that you know the backstop of the AppDomain boundary is a secure one for your domain.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=4&gt;4. Resilient to Policy Changes&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Since in the legacy sandboxing model, the final permission set was determined by intersecting all four policy levels, some applications would make policy decisions in a level other than the AppDomain level.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Depending on your application, this might have been the only choice for you – VSTO is the canonical example here.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The problem comes into play when you realize that the other three policy levels are shared resources for the machine, and there could be contention over them.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For instance, on popular way to create and deploy modifications to policy is to have one of the developers &lt;A HREF="/shawnfa/archive/2004/09/07/226530.aspx"&gt;use the MMC snap in that ships with the framework SDK to create a policy MSI file&lt;/A&gt;.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;These MSI files are snapshots of the current state of policy however, and contain no merge logic at all. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;This means that if two applications deploy policy in this way, the last one to install wins; the first application will have its changes removed from the system.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If that application was not written with this situation in mind, it probably will fail with unhandled SecurityExceptions, causing a less than ideal user experience.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In fact, given that the first application might not be run for some time after the second is installed, it could be very difficult to trace back the cause of failure!&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;IT departments also run into this problem; they need to deploy policy changes across the company for various internal applications.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;One way to solve the situation is to create one MSI file that contains all the policy changes for every application.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;However, that’s not ideal since users will end up with policy entries for applications they might never need to run.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Another solution is to generate a script with the appropriate caspol logic; something that can be difficult to do properly.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=4&gt;5. Resilient to CLR Versioning&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;This is really a special case of being resilient to policy changes.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Jessie Kaplan discusses an issue we ran into with &lt;A href="http://msdn.microsoft.com/msdnmag/issues/06/03/CLRInsideOut/default.aspx?side=true#a"&gt;VSTO with the v2.0 upgrade&lt;/A&gt; in his &lt;A href="http://msdn.microsoft.com/msdnmag/issues/06/03/CLRInsideOut/default.aspx"&gt;recent MSDN column&lt;/A&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since VSTO made its policy decisions in the v1.1 security policy, and security policy is tied to a specific version of the runtime, when v2.0 was installed on a machine all of the VSTO policy modifications were essentially lost to it.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Your application can protect itself against this issue by providing a config file that directs it to bind against one specific CLR instead of floating forward to a newer compatible version.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This does provide a requirement that the users of your application keep the older CLR around, and may cause more pressure on you to provide a newer application built against the newer runtime.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Both of the above issues are solved for standalone applications with the advent of ClickOnce in v2.0.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Now trust decisions are tied to the application, instead of the CLR version or the specific policy.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If one application installs, it’s not going to affect the trust decisions for any other application on the machine.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Administrators can still exert some control over these trust decisions by using a set of registry keys to control the trust manager.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It’s no coincidence that under the covers, ClickOnce is using the simple sandboxing model to ensure that its applications get run with exactly the permissions they require.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=579066" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Policy/default.aspx">Policy</category></item><item><title>Debugging a Partial Trust ClickOnce Application</title><link>http://blogs.msdn.com/shawnfa/archive/2006/03/28/563188.aspx</link><pubDate>Tue, 28 Mar 2006 20:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:563188</guid><dc:creator>shawnfa</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/563188.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=563188</wfw:commentRss><description>&lt;P&gt;Although the theory is that by the time we deploy a finished application it's already fully debugged we all know that in&amp;nbsp;practice things rarely go that smoothly.&amp;nbsp; So what happens if you deploy a partial trust ClickOnce application that starts to crash when it's run?&amp;nbsp; Well, if you're lucky enough to have the problematic application&amp;nbsp;stay alive&amp;nbsp;for as long as it takes&amp;nbsp;you to attach a debugger you're golden.&lt;/P&gt;
&lt;P&gt;However if the crash occurs somewhere along the startup path, or if the debugger shows that something went wrong and got you into a bad state before you could attach it you might want to have the debugger run before the process even starts.&lt;/P&gt;
&lt;P&gt;That's where things start to get tricky -- since ClickOnce is responsible for starting up your application, you can't just tell it to run the debugger for you.&amp;nbsp; Instead, you can use the gflags tool from the &lt;A href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx"&gt;Debugging Tools for Windows&lt;/A&gt; to intercept the start of your process.&amp;nbsp; &lt;A HREF="/shawnfa/archive/2005/11/30/498610.aspx"&gt;For a partial trust application, AppLaunch will be the real entry point&lt;/A&gt;, so you'll want to launch your debugger when AppLaunch starts.&lt;/P&gt;
&lt;P&gt;In the gflags Image File section, set AppLaunch.exe as the image, check the debugger box, and put the full path to your debugger in the debugger field.&amp;nbsp; I tend to use either &lt;A HREF="/jmstall/archive/2005/11/08/mdbg_linkfest.aspx"&gt;Mdbg&lt;/A&gt; or WinDbg for this, depending on what kind of error I'm debugging.&lt;/P&gt;
&lt;P&gt;&lt;IMG alt="Setting up a debugger for AppLaunch" src="/photos/shawnfa/images/563181/original.aspx" border=0&gt;&lt;/P&gt;
&lt;P&gt;Once you've got that setup you can launch your ClickOnce application normally and the debugger will start ready to run the application.&amp;nbsp; If your app no longer starts up, make sure that the full path to the debugger is correct, since if Windows fails to find it, it will fail the CreateProcess for AppLaunch as well.&lt;/P&gt;
&lt;P&gt;Finally, when you've solved the problem, you'll probably want to go back to gflags and uncheck the debugger box so that your partial trust applications no longer run under the debugger.&lt;/P&gt;
&lt;P&gt;A couple of quick notes on this -- since all partial trust code runs through the same AppLaunch entry point, setting this up will cause all partial trust ClickOnce apps to run under the debugger, not just the one you're debugging.&amp;nbsp; The same technique can be used for a FullTrust ClickOnce application as well; in that case you'd use the name of your application's .exe file instead of AppLaunch.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=563188" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Debugging/default.aspx">Debugging</category></item><item><title>Detecting that You're Running in a ClickOnce Application</title><link>http://blogs.msdn.com/shawnfa/archive/2006/01/20/514411.aspx</link><pubDate>Fri, 20 Jan 2006 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:514411</guid><dc:creator>shawnfa</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/514411.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=514411</wfw:commentRss><description>&lt;P&gt;In my &lt;a href="http://blogs.msdn.com/shawnfa/archive/2006/01/18/514407.aspx"&gt;last post&lt;/A&gt;,&amp;nbsp;&amp;nbsp;I mentioned that application scoped isolated storage only works if you're running in a ClickOnce application.&amp;nbsp; That begs the question -- how do I tell if I'm currently running in the context of a ClickOnce application?&lt;/P&gt;
&lt;P&gt;You can see if a ClickOnce application is running in the current AppDomain by checking the &lt;A href="http://msdn2.microsoft.com/en-us/library/system.appdomain.activationcontext.aspx"&gt;AppDomain.CurrentDomain.ActivationContext&lt;/A&gt; property.&amp;nbsp; If that value is non-null, then the domain is running a ClickOnce application.&amp;nbsp; The ActivationContext will also get you &lt;a href="http://blogs.msdn.com/shawnfa/archive/2004/06/30/170241.aspx"&gt;the name of that application&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;What you choose to do with that information is up to you.&amp;nbsp; In general, modifying your behavior depending on the context of the application leads to difficult to test and debug programs.&amp;nbsp; However, there may be situations (such as choosing an isolated storage scope), where having this information is necessary and useful.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=514411" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item><item><title>Isolated Storage and ClickOnce</title><link>http://blogs.msdn.com/shawnfa/archive/2006/01/18/514407.aspx</link><pubDate>Wed, 18 Jan 2006 21:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:514407</guid><dc:creator>shawnfa</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/514407.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=514407</wfw:commentRss><description>&lt;P&gt;Isolated storage introduced a new scope in v2.0 of the CLR to work with ClickOnce applications.&amp;nbsp; Application scoped Isolated storage is backed by the application's data directory.&amp;nbsp; This enables scenarios where your isolated storage data will flow forward with your application as ClickOnce updates it to new versions.&lt;/P&gt;
&lt;P&gt;However, in order to take advantage of this, you need to be sure you're using the application scope.&amp;nbsp; The default IsolatedStorageFileStream constructor will actually use domain scope, even if you are running in a ClickOnce application.&amp;nbsp; (One design decision we could have made might have been to detect if this is a ClickOnce application and default to application scope, however this would lead to the situation where the program would have subtly different behavior if it was run as a standalone application.)&lt;/P&gt;
&lt;P&gt;Since the default constructor is using domain scope, you might observe that as your application upgrades it appears that the files you stored in your isolated storage disappear.&amp;nbsp; Because of this behavior, you'll want to specify that you'd like to use application scoped storage&amp;nbsp;instead of domain scoped storage:&lt;/P&gt;
&lt;P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 2em; FONT-SIZE: x-small; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace; BACKGROUND-COLOR: lightgrey; WORD-WRAP: break-word"&gt;IsolatedStorageFile&amp;nbsp;scope&amp;nbsp;=&amp;nbsp;IsolatedStorageFile.GetUserStoreForApplication();&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt;(IsolatedStorageFileStream&amp;nbsp;stream&amp;nbsp;=&amp;nbsp;&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&amp;nbsp;IsolatedStorageFileStream("data.dat",&amp;nbsp;FileMode.OpenOrCreate,&amp;nbsp;scope))&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="COLOR: green"&gt;// ...&lt;/SPAN&gt;&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Note that application scoped isolated storage is only available if your program is running as a ClickOnce application.&amp;nbsp; If it is not, you'll get an IsolatedStorageException when you call GetUserStoreForApplication which says "Unable to determine the application identity of the caller."&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=514407" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item><item><title>Why Can't I See My Partially Trusted ClickOnce Applications in Task Manager?</title><link>http://blogs.msdn.com/shawnfa/archive/2005/11/30/498610.aspx</link><pubDate>Thu, 01 Dec 2005 00:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:498610</guid><dc:creator>shawnfa</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/498610.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=498610</wfw:commentRss><description>&lt;P&gt;If you're developing a partial trust&amp;nbsp;&lt;A href="http://msdn.microsoft.com/smartclient/understanding/windowsforms/2.0/features/clickonce.aspx"&gt;ClickOnce&lt;/A&gt; application and are looking for its process in Task Manager or Process Explorer, you might be surprised that you can't find it listed anywhere.&amp;nbsp; What you will see however is a process named AppLaunch.exe.&amp;nbsp; AppLaunch is a small shim tool who's entire purpose in life is to turn around and invoke a ClickOnce application.&amp;nbsp; The trick here is that it doesn't invoke the application by executing its .exe.&amp;nbsp; Rather, it acts as a simple CLR host, and uses the hosting APIs to transfer control to the application's Main method.&amp;nbsp; (This is one of the reasons that ClickOnce requires the application entry point be a managed assembly).&lt;/P&gt;
&lt;P&gt;So why all the fancy redirection?&amp;nbsp; It turns out that when you tell Windows to start a process, lots of things happen under the covers before the process actually gets started up.&amp;nbsp; For instance, the application might be registered to use an AppCompat shim.&amp;nbsp; Or it might have a registered debugger.&amp;nbsp; Or there could be a .local file, which affects loading behavior.&amp;nbsp; Any of these things (or plenty of others) could be controlled by the name of the application's entry point.&amp;nbsp; So, to work around these issues we don't allow partially trusted applications to control the name of their entry point.&amp;nbsp; Instead, they all have a main module named AppLaunch.&lt;/P&gt;
&lt;P&gt;Since AppLaunch really just helps to protect against partial trust applications abusing something in the load path, it isn't used to launch a FullTrust ClickOnce application.&amp;nbsp; Those will show up in a process list as you would expect.&lt;/P&gt;
&lt;P&gt;As a side effect of this, if your partial trust application happens to throw an unhandled exception, it will propagate up as an unhandled AppLaunch exception since to Windows, it looks as though AppLaunch is the entry point.&amp;nbsp; When you see one of these errors, it's worth attaching a debugger to the AppLaunch process and obtaining a stack trace of the exception to determine if it is a real bug in AppLaunch or if it's simply a bug in the program being run.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=498610" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item><item><title>Using Add-Ins with a ClickOnce Deployed Application</title><link>http://blogs.msdn.com/shawnfa/archive/2005/09/16/469163.aspx</link><pubDate>Fri, 16 Sep 2005 22:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:469163</guid><dc:creator>shawnfa</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/469163.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=469163</wfw:commentRss><description>&lt;P&gt;One of the attendees at the PDC had an interesting question combining ClickOnce and Add-Ins.&amp;nbsp; Basically, his application was being deployed with ClickOnce, and was running without elevating it's privileges beyond the Internet zone [fan-tastic :-)].&amp;nbsp; The problem is that the application was extensible with AddIns, and the identity of these AddIns were not known at deployment time.&lt;/P&gt;
&lt;P&gt;The obvious solution is to simply deploy the AddIns with the application, and late bind to them.&amp;nbsp; However since ClickOnce requires that all of the files being deployed be listed in the application manifest, obviously not knowing the identity of the AddIns until runtime prevents this solution from working.&lt;/P&gt;
&lt;P&gt;This leaves two viable options, using &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflectionassemblyclassloadfromtopic1.asp"&gt;Assembly.LoadFrom(string url)&lt;/A&gt; to load the assemblies off of the deployment server at runtime, or creating a cache of assemblies in Isolated Storage and loading them using &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemReflectionAssemblyClassLoadTopic2.asp"&gt;Assembly.Load(byte[])&lt;/A&gt;.&amp;nbsp; There are trade offs to using these two techniques, so lets look at each individually.&lt;/P&gt;
&lt;P&gt;First, a limitation that applies to both of them.&amp;nbsp; Running&amp;nbsp;with the&amp;nbsp;Internet permission set is going to require that the location of the AddIn assemblies be the deployment server (since you'll only have WebPermission back to the site of origin).&amp;nbsp; If that's not a possibility, you'll need to add WebPermission to the server holding the AddIn assemblies to your manifest, which will end up causing your users to get a ClickOnce trust prompt.&lt;/P&gt;
&lt;P&gt;Using LoadFrom(url) is going to be the easiest option, as Fusion will simply connect to the server and obtain your assembly for you, caching it locally.&amp;nbsp; It will also automatically pick up updates to the AddIn when they are detected.&amp;nbsp; However, you run into the potential problems with &lt;a href="http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx"&gt;using the LoadFrom context&lt;/A&gt;. On the plus side, you won't have any limitation on the total size of the Add-In assemblies.&lt;/P&gt;
&lt;P&gt;As an alternative you could connect to the AddIn distribution server yourself, which allows you to implement your own downloading, caching, and updating policies.&amp;nbsp; However, this method also requires that you implement your own download, caching, and updating policies :-).&amp;nbsp; If you want this level of control, downloading the assemblies into Isolated Storage, and then loading them with Load(byte[]) is your best bet.&amp;nbsp; Using application scoped&amp;nbsp;Isolated Storage for the cache means that ClickOnce will migrate your AddIns forward as you provide upgrades to your application.&amp;nbsp; And since you're using Assembly.Load instead of Assembly.LoadFrom, you end up using the standard Load context.&lt;/P&gt;
&lt;P&gt;The major limitation here will be your Isolated Storage quota, which for the Internet zone is limited to approximately 500 kilobytes.&amp;nbsp; That 500k needs to be shared among all the cached AddIns and any additional streams that your application creates in IsoStore.&amp;nbsp; If that won't be enough space, then you've got a few options.&amp;nbsp; First you could simply not cache the assemblies, and just read them from the server every time (perhaps relying on a proxy to cache for you), and passing the read bytes directly to Assembly.Load().&amp;nbsp; Obviously this method is going to result in potentially unacceptable load times for AddIns, especially if they're contained in large assemblies or your connection to the server housing them is slow.&lt;/P&gt;
&lt;P&gt;A second alternative is to simply use an aggressive caching cleaning policy -- simply clear out older AddIns when a new one becomes available that won't fit in the remaining IsoStore space.&amp;nbsp; This method will work relatively well, though depending on your cleanup policy, you may end up causing performance problems for your users again.&lt;/P&gt;
&lt;P&gt;Finally, you could simply let the user manage the Add-In cache.&amp;nbsp; Depending on&amp;nbsp;how fancy you want to get, you could give them UI to mark certain AddIns as "never cache" or "always cache".&amp;nbsp; Providing a view of what is already in the IsoStore cache, and&amp;nbsp;the ability to remove specific AddIns would be useful as well.&amp;nbsp; With that infrastructure in place, when you download an assembly that won't fit into your IsoStore cache, you could prompt the user and give them the option to not cache this assembly or to remove some other assemblies from the cache to make room.&lt;/P&gt;
&lt;P&gt;Basically, the answer is that this scenario will absolutely work, although you may have to do some work in order to get it up and running.&amp;nbsp; Here's a quick rundown of the pros and cons of each method:&lt;/P&gt;
&lt;P&gt;
&lt;TABLE border=1&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TD&gt;&lt;B&gt;LoadFrom(url)&lt;/B&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;B&gt;Load(byte[])&lt;/B&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;B&gt;Pros&lt;/B&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;UL&gt;
&lt;LI&gt;Fusion cache management 
&lt;LI&gt;Fusion picks up updates automatically 
&lt;LI&gt;Quickest method to get running 
&lt;LI&gt;No built in size limitations on the AddIns.&lt;/LI&gt;&lt;/UL&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;UL&gt;
&lt;LI&gt;Custom download, cache, and update&amp;nbsp;management 
&lt;LI&gt;ClickOnce migrates cache up to new versions of the application as they become available&lt;/LI&gt;&lt;/UL&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;B&gt;Cons&lt;/B&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;UL&gt;
&lt;LI&gt;AddIns must be on deployment server 
&lt;LI&gt;Assemblies end up in the LoadFrom context 
&lt;LI&gt;You don't own the cache policy, so assemblies may be removed when you don't want them to be&lt;/LI&gt;&lt;/UL&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;UL&gt;
&lt;LI&gt;AddIns must be on deployment server 
&lt;LI&gt;More work -- custom cache, download, and updating logic must be written.&amp;nbsp; Cache clean options may also need to be written to present to the user 
&lt;LI&gt;Limited cache space -- ~500 kilobytes for your AddIn cache and other Isolated Storage to share&lt;/LI&gt;&lt;/UL&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;&lt;EM&gt;[Updated 11/4/2005: Removed wrong load context]&lt;/EM&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=469163" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item><item><title>PDC '05: Lunch with Apple</title><link>http://blogs.msdn.com/shawnfa/archive/2005/09/13/465048.aspx</link><pubDate>Tue, 13 Sep 2005 23:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:465048</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/465048.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=465048</wfw:commentRss><description>&lt;P&gt;Just got back from lunch with a group from Apple.&amp;nbsp; After checking the rule book, it turns out that no physical laws would be violated by having Apple and Microsoft so close together, and than fully there was no matter-antimatter reaction :-).&lt;/P&gt;
&lt;P&gt;They were interested in Avalon, erm ... Windows Presentation Framework, which was not really surprising.&amp;nbsp; More interesting was their interest in Indigo, erm ... Windows Communication Framework.&lt;/P&gt;
&lt;P&gt;Outside of that, so&amp;nbsp; far there hasn't been a ton of questions about CAS, however we've answered several questions about ClickOnce.&amp;nbsp; The Smart Client story really seems to be interesting to people ... and I'm pretty excited about that since I think the combination of WinForms + ClickOnce for now, and later on ClickOnce + Windows Presentation Framework can make for pretty compelling applications without the annoyances of web based applications.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=465048" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item><item><title>A Closer Look at the Simple Sandboxed AppDomain</title><link>http://blogs.msdn.com/shawnfa/archive/2005/08/09/449563.aspx</link><pubDate>Tue, 09 Aug 2005 22:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449563</guid><dc:creator>shawnfa</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/449563.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=449563</wfw:commentRss><description>&lt;P&gt;Yesterday we took a look at &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/08/08/449050.aspx"&gt;Whidbey's new Simple Sandboxing API&lt;/A&gt;.&amp;nbsp; At first glance this API does seem relatively simple, however when you start to look closer at the AppDomain that is created for your sandboxed code, there are a few surprising properties.&lt;/P&gt;
&lt;P&gt;You might expect that under the covers this API is doing the grunt work of creating an AppDomain policy level which grants AllCode the specified permission set, and then has a code group&amp;nbsp;for each strong name specified on the FullTrust list in order to provide those assemblies FullTrust.&amp;nbsp; However, this is not how the API works -- &lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;it actually uses an entirely different security model than the traditional policy level based one&lt;/SPAN&gt;.&amp;nbsp; In fact, there is no AppDomain policy level in the sandboxed domain at all!&amp;nbsp; Instead the sandboxed domain simply keeps track of a set of FullTrust assemblies and a permission set to be granted to all other assemblies and the AppDomain itself.&amp;nbsp; No policy resolution will be done for assemblies loaded into this type of domain.&lt;/P&gt;
&lt;P&gt;Why does Whidbey add this second AppDomain security model?&amp;nbsp; Aside from making it trivial for applications to sandbox untrusted code, it's also required for the ClickOnce security model.&amp;nbsp; ClickOnce allows an application to specify the exact set of permissions it should run under.&amp;nbsp; ClickOnce application authors test their applications with these permissions and expect to have exactly their requested permissions at runtime.&amp;nbsp; This AppDomain security model allows for that to occur.&lt;/P&gt;
&lt;P&gt;Similarly, Visual Studio's debug-in-zone feature also requires an environment where the permissions it requests are exactly the permissions it gets -- if it were to debug your application with fewer privileges, debug-in-zone could lead to a lot of confusion when operations that are expected to pass start throwing SecurityExceptions.&lt;/P&gt;
&lt;P&gt;Finally lets take a look at that evidence parameter to the CreateDomain API.&amp;nbsp; Since a sandboxed AppDomain does not resolve policy and always has a domain permission set equal to the grant set of the assemblies loaded into it, why does it need Evidence?&amp;nbsp; Technically the domain itself doesn't need that parameter, and it won't ever look at it directly.&amp;nbsp; However, the evidence is still stored on the AppDomain's Evidence property.&amp;nbsp; This means that other features which make decisions based upon AppDomain evidence (such as isolated storage), can still work with code executing in a simple sandboxed domain without modification.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=449563" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CAS/default.aspx">CAS</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Under+the+Hood/default.aspx">Under the Hood</category></item><item><title>Configuring the TrustManager</title><link>http://blogs.msdn.com/shawnfa/archive/2005/06/24/432490.aspx</link><pubDate>Sat, 25 Jun 2005 04:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:432490</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/432490.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=432490</wfw:commentRss><description>&lt;P&gt;I've been working on the CLR side of ClickOnce pretty much from the beginning.&amp;nbsp; In fact, since I started working with it, I can count at least&amp;nbsp;3 major design revisions and countless minor tweaks.&amp;nbsp; I believe that of all the people on the CLR team, I've been the one involved with ClickOnce the longest by about a year.&amp;nbsp; So needless to say, I'm pretty excited to get this technology out into the world when we ship Whidbey.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.leastprivilege.com/PermaLink.aspx?guid=f5c4e107-585b-4294-9545-663ef8afb0ff"&gt;Dominick Baier has a post&lt;/A&gt; about using GPO to tweak the behavior of the default TrustManager that ships with Whidbey.&amp;nbsp; The TrustManager (System.Security.Policy.TrustManager in System.Windows.Forms.dll), is basically the UI that walks you through the process of making a trust decision.&amp;nbsp; You can read more about it in &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/clickoncetrustpub.asp"&gt;Brian Noyes' MSDN article about configuring trusted publishers&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;After a series of posts I have planned for the next few weeks, I should spend some time discussing the aspects of ClickOnce that belong to the CLR itself.&lt;/P&gt;
&lt;P&gt;More information about ClickOnce can be found in the blogs of &lt;a href="http://blogs.msdn.com/misampso/default.aspx"&gt;Mike Sampson&lt;/A&gt; from the VB team, and &lt;a href="http://blogs.msdn.com/saurabh/default.aspx"&gt;Saurabh Pant&lt;/A&gt; from the Fusion team.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=432490" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/ClickOnce/default.aspx">ClickOnce</category></item></channel></rss>