<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>I may have joined the wrong side : CAS</title><link>http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx</link><description>Tags: CAS</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Hopping databases from the SAFE SQLCLR permission level</title><link>http://msmvps.com/blogs/calinoiu/archive/2006/02/18/102952.aspx</link><pubDate>Sat, 18 Feb 2006 18:20:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102952</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102952</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102952</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2006/02/18/102952.aspx#comments</comments><description>&lt;P&gt;I've seen quite a few articles over the past few months that make the assumption that one can only connect to the hosting database from SQLCLR code running at the &lt;B&gt;SAFE&lt;/B&gt; permission level. I can't seem to find any official MSDN documentation that would directly reinforce this misconception, so I'm guessing that it stems from the limitation of the &lt;B&gt;SqlClientPermission&lt;/B&gt; at the SAFE level to only allow use of the following connection strings (with optional specification of the &lt;B&gt;Type System Version&lt;/B&gt; parameter): &lt;/P&gt;&lt;PRE&gt;context connection=true&lt;/PRE&gt;or&lt;PRE&gt;context connection=yes&lt;/PRE&gt;
&lt;P&gt;Unfortunately, the documentation for the &lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlclientpermission.add.aspx"&gt;&lt;B&gt;SqlClientPermission.Add&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt; method is a wee bit ambiguous with respect to the effect of preventing arbitrary target database specifications in the connection string, and one might easily be led into believing that preventing use of the database parameter will prevent connections to unintended databases. However, while it will prevent mucking about with the connection string, that's not enough to prevent connecting to other databases. &lt;/P&gt;
&lt;P&gt;For starters, the &lt;B&gt;SqlConnection&lt;/B&gt; object has a &lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.changedatabase.aspx"&gt;&lt;B&gt;ChangeDatabase&lt;/FONT&gt;&lt;/B&gt;&lt;/A&gt; method that allows one to target another database after an initial connection has already been established.&lt;I&gt;e.g.&lt;/I&gt;:&lt;SUP&gt;1&lt;/SUP&gt;&lt;/P&gt;&lt;PRE&gt;using (SqlConnection connection = new SqlConnection(@"Data Source=(local);Initial Catalog=AllowedDB;Integrated Security=True"))
{
 connection.Open();
 connection.ChangeDatabase("ForbiddenDB");

 using (SqlCommand command = connection.CreateCommand())
 {
  command.CommandType = CommandType.Text;
  command.CommandText = "SELECT DB_NAME()";
  Console.WriteLine((string)command.ExecuteScalar());
 }
}
&lt;/PRE&gt;
&lt;P&gt;Now, one might argue that this is actually a bug, and that &lt;B&gt;ChangeDatabase&lt;/B&gt; method ought to demand &lt;B&gt;SqlClientPermission&lt;/B&gt; for the target database before making the switch. However, it's quite possible to bypass the &lt;B&gt;SqlClient&lt;/B&gt; layer entirely and make the switch inside database code, so any additional protection at the &lt;B&gt;SqlClient&lt;/B&gt; level would only provide a false sense of security and probably isn't worth implementing. &lt;/P&gt;
&lt;P&gt;The next approach invokes making a direct database context switch from T-SQL using the &lt;A href="http://msdn2.microsoft.com/en-us/library/ms188366(SQL.90).aspx"&gt;&lt;B&gt;USE&lt;/B&gt; statement&lt;/a&gt;. &lt;I&gt;e.g.&lt;/I&gt;: &lt;/P&gt;&lt;PRE&gt;using (SqlConnection connection = new SqlConnection(@"Data Source=(local);Initial Catalog=AllowedDB;Integrated Security=True"))
{
 connection.Open();

 using (SqlCommand command = connection.CreateCommand())
 {
  command.CommandType = CommandType.Text;

  command.CommandText = "USE ForbiddenDB";
  command.ExecuteNonQuery();

  command.CommandText = "SELECT DB_NAME()";
  Console.WriteLine((string)command.ExecuteScalar());
 }
}
&lt;/PRE&gt;
&lt;P&gt;Effectively, this means that SqlClientPermission provides no protection against using any particular database within a given SQL Server instance. You might guess that the SQLCLR might add some additional protection against database switching from within hosted code, but you'd be wrong. The above techniques work just as well against the SQLCLR context connection as they do against a plain, old vanilla connection as shown above. &lt;B&gt;SAFE&lt;/B&gt; or not, SQLCLR assemblies can connect to any database in their host SQL Server instance assuming, of course, that user permissions also allow the connection.&lt;/P&gt;&lt;BR&gt;&lt;BR&gt;
&lt;HR&gt;
&lt;SUP&gt;1&lt;/SUP&gt; The &lt;A href="http://msdn2.microsoft.com/en-us/library/ms189753(SQL.90).aspx"&gt;DB_NAME&lt;/a&gt; function, when called with no parameters, returns the name of the current database. If you haven't switched the context database, the function would be expected to return the name of the database against which the connection was originally established.&lt;/A&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102952" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Why is my application coughing up a SecurityException after my code stops running?</title><link>http://msmvps.com/blogs/calinoiu/archive/2006/01/07/why-is-my-application-coughing-up-a-securityexception-after-my-code-stops-running.aspx</link><pubDate>Sat, 07 Jan 2006 16:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102951</guid><dc:creator>calinoiu</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102951</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102951</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2006/01/07/why-is-my-application-coughing-up-a-securityexception-after-my-code-stops-running.aspx#comments</comments><description>&lt;h3&gt;Odd exceptions at odd times&lt;/h3&gt;
&lt;p&gt;If you apply a PrincipalPermission attribute to a class in order to restrict the users and/or roles that are permitted to use the class, you may start seeing security exceptions like the following being thrown at unexpected times (like, say, when your application is quitting): &lt;/p&gt;&lt;pre&gt;System.Security.SecurityException was unhandled
Message=&amp;quot;Request for principal permission failed.&amp;quot;
Source=&amp;quot;mscorlib&amp;quot;
StackTrace:
        at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
        at System.Security.Permissions.PrincipalPermission.Demand()
        at System.Security.PermissionSet.DemandNonCAS()
        at YourNamespace.YourClass.Finalize()
&lt;/pre&gt;&lt;br /&gt;
&lt;h3&gt;What&amp;#39;s up with that?&lt;/h3&gt;
&lt;p&gt;The basic gist of the above exception that the demand for your specified PrincipalPermission is failing when the finalizer for your class is invoked. If your class also happens to be disposable, and disposition suppresses its finalization, you might be tempted to believe that this problem occurs because the thread principal couldn&amp;#39;t satisfy the original PrincipalPermission demand at construction. However, things are a wee bit more complicated than that... &lt;/p&gt;
&lt;p&gt;Finalization is triggered by the garbage collector and runs on a separate thread controlled by the garbage collector. This means that the principal that you set on your application&amp;#39;s thread won&amp;#39;t be applied to the thread on which an instance of your finalizable type gets finalized. Your PrincipalPermission demand will &lt;i&gt;always&lt;/i&gt; fail at finalization, regardless of the thread principal set within your application. &lt;/p&gt;
&lt;p&gt;Another surprise might be that there&amp;#39;s an object available for finalization at all if the PrincipalPermission demand fails when the constructor is invoked. What you actually end up with in such a case is a partially constructed instance of your type. This instance won&amp;#39;t be available to the invoking code, so it won&amp;#39;t be subject to disposition, but the garbage collector will still attempt to finalize it despite the fact that it isn&amp;#39;t fully constructed. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;So what can I do about all this?&lt;/h3&gt;
&lt;p&gt;The simple answer is you need to make it possible for the finalizer (and any other methods it calls) to run despite the fact that the finalizer thread cannot satisfy the class-level PrincipalPermission demand. You can do this by applying a PrincipalPermission attribute that allows unauthenticated callers to the finalizer (and any methods it calls). The C# form of this attribute would be: &lt;/p&gt;&lt;pre&gt;[PrincipalPermission(SecurityAction.Demand, Authenticated = false)]
&lt;/pre&gt;
&lt;p&gt;The VB form would be: &lt;/p&gt;&lt;pre&gt;&amp;lt;PrincipalPermission(SecurityAction.Demand, Authenticated:=False)&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Obviously, if you&amp;#39;re going to be removing the requirement for the class-level PrincipalPermission from the finalizer or any other methods, you should also ensure that these methods don&amp;#39;t perform any actions that should require whatever user identity or role membership specified by the original PrincipalPermission. &lt;/p&gt;
&lt;p&gt;You may want to also consider applying the same PrincipalPermission reversal on any methods used for disposition, even if these are not invoked from your finalizer. (This would be a bit of an odd design choice in most cases, but if that&amp;#39;s what you&amp;#39;re using, you should be addressing the consequences.) The main reason for this is that disposition might not be invoked under the same principal as was in place at construction. As with finalization, you should ensure that your disposition methods don&amp;#39;t perform any &amp;quot;high-privilege&amp;quot; actions if you do choose to reverse the PrincipalPermission requirement. &lt;/p&gt;&lt;br /&gt;
&lt;h3&gt;If that was the simple answer...&lt;/h3&gt;
&lt;p&gt;The good news is that the above approach is pretty much the only approach. It&amp;#39;s reasonably clear-cut, and there&amp;#39;s not much that you can do in terms of variation on the theme. The bad news is that, if you&amp;#39;re running into this particular problem, chances are pretty good that you should perhaps be concerned about some of the finer details of finalization and disposition. If you&amp;#39;re interested in learning more about these, I&amp;#39;d recommend reading &lt;a href="http://blogs.msdn.com/cbrumme/archive/2004/02/20/77460.aspx"&gt;Chris Brumme&amp;#39;s blog entry on finalization&lt;/a&gt;. If you&amp;#39;re implementing disposition as well as a finalizer, you should probably take a look at &lt;a href="http://msdn2.microsoft.com/fs2xkftw.aspx"&gt;the recommended disposition pattern&lt;/a&gt;, and maybe even &lt;a href="http://www.gotdotnet.com/team/libraries/whitepapers/resourcemanagement/resourcemanagement.aspx"&gt;the whitepaper on .NET Framework Resource Management&lt;/a&gt;. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102951" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>Secure by de...what?</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/12/04/102950.aspx</link><pubDate>Sun, 04 Dec 2005 17:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102950</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102950</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102950</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/12/04/102950.aspx#comments</comments><description>&lt;H3&gt;Surprise!&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/library/en-us/dnsse/html/sseoverview.asp?frame=true#sseover_topic11"&gt;User instances&lt;/a&gt; are a new capability of SQL Server 2005 (Express edition only) that are supposedly intended to allow non-admins to attach database files without requiring additional permissions. This actually works just fine and, at first glance, it probably strikes most folks as a lovely least-privilege accomodation. The unfortunate bit that might not be immediately obvious to the casual user is that this is accomplished by granting the connecting user &lt;B&gt;sysadmin&lt;/B&gt; privilege over his user instance. This means that every connection to a user instance is a connection running as &lt;B&gt;sysadmin&lt;/B&gt;. &lt;/P&gt;
&lt;H3&gt;So... What's so bad about connecting as sysadmin?&lt;/H3&gt;
&lt;P&gt;If you're at all familiar with secure practices around database connectivity, you've probably heard that you should never connect under a &lt;B&gt;sysadmin&lt;/B&gt; login unless you're connecting for the express purpose of performing administrative tasks. The main reason for this is that a &lt;B&gt;sysadmin&lt;/B&gt; login has unlimited control over the SQL Server instance, as well as being able to "climb" out of the SQL Server instance via extended stored procedures (or hosted SQLCLR code, in the case of SQL Server 2005) to affect other machine resources. In other words, code running under a &lt;B&gt;sysadmin&lt;/B&gt; login can fully control the SQL Server instance and can do anything on the machine or network that either the login account or the SQL Server service account can do. It's also possible to impersonate other Windows accounts when calling outside SQL Server, so the damage potential isn't necessarily limited by the privileges of the login and service account. &lt;/P&gt;
&lt;H3&gt;Yikes! But, ummm... Yikes!&lt;/H3&gt;
&lt;P&gt;Hmmm... Sounds like running user instances might be just a wee bit on the risky side, doesn't it? After a bit of a stumped initial reaction, the little voices in my head started evaluating the implementation against SD&lt;SUP&gt;3&lt;/SUP&gt;+C ("secure by design, secure by default, secure in deployment, and communications") criteria, which is supposed to be an integral part of &lt;A href="http://msdn.microsoft.com/security/default.aspx?pull=/library/en-us/dnsecure/html/sdl.asp#sdl2_topic1_2"&gt;the Microsoft security development lifecycle&lt;/a&gt;. I can't help but feel that some less risky choices might have been made along the way, but perhaps that's just my paranoid nutbag side talking. You decide... &lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;I&gt;Secure by design?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;The main goal of user instance mode seems to be &lt;A href="http://msdn.microsoft.com/library/en-us/dnsse/html/sqlexpuserinst.asp"&gt;allowing applications to attach database files even when running under a limited privilege user account&lt;/a&gt;. That's pretty necessary if you're going to, say, &lt;A href="http://msdn.microsoft.com/library/en-us/dnsse/html/sseoverview.asp?frame=true#sseover_topic21"&gt;push user instance mode SQL Server Express as a replacement for Jet&lt;/a&gt;. That said, might some safer design choices have been made when choosing how to implement this requirement? This would allow even &lt;B&gt;dbcreator&lt;/B&gt; membership to be revoked when it isn't actually needed, which could be the case if one were to configure the user instance template data files to pre-connect to a designated set of databases. &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;B&gt;Does the connecting user really need to be a sysadmin?&lt;/B&gt;&lt;BR&gt;Probably not. Membership in the &lt;B&gt;dbcreator&lt;/B&gt; role would probably have been quite sufficient for the purposes of attaching database files without invoking additional risks around control of the instance configuration and allowing code to call out of the database. However, a potentially more interesting design might allow a true &lt;B&gt;sysadmin&lt;/B&gt; of the master SQL Express instance to designate the role membership of a user instance creator. &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;B&gt;Is the connecting user account really the best choice for the service account?&lt;/B&gt;&lt;BR&gt;On the surface, choosing to run the user instance under the connecting user's account might actually seem to be a good choice. After all, it ensures that code run within the user instance can't do anything that the user himself can't do (unless, of course, impersonation is used). However, if you turn things around a bit and assume that an attached database might come from a less than ideal source (say, passed around from one user to another, all of whom act as &lt;B&gt;dbo&lt;/B&gt; and &lt;B&gt;sysadmin&lt;/B&gt; while the database is in their hands), running with the full privileges of the connecting user all of a sudden doesn't sound so good... &lt;BR&gt;&lt;BR&gt;Could another choice have been made here? Granted, there are some challenges around designating the permissions granted to any alternate account. However, one obvious possibility would be to allow a master instance administrator to designate per-user service accounts for user instance mode. As with master instance service accounts, such a mechanism could automatically assign the minimal user permission set required for service operation, thereby reducing the administrative burden. A configurable design could also allow for enabling/disabling user instance mode by user (with disabled as the default state for a properly "secure by default" design). &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;B&gt;Do user instances really need the full functionality of stand-alone instances?&lt;/B&gt;&lt;BR&gt;If the true purpose of user instances is to permit applications to attach local database files, why include any functionality beyond what's needed to act as a pure database server? Do such applications really need to be able to run extended stored procedures like &lt;B&gt;xp_cmdshell&lt;/B&gt;? If not, why include it at all? &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;B&gt;What CAS permissions ought to be assigned to assemblies hosted in an attached database?&lt;/B&gt;&lt;BR&gt;Unfortunately, all assemblies hosted by the SQLCLR are &lt;A href="http://bordecal.mvps.org/Nicole/SqlClrCas/SqlClrCasSpeculations.htm"&gt;assigned local zone evidence&lt;/a&gt;, which means that a database loaded from a remote location (either with an application loaded from that location or as an attached remote database) will be granted unrestricted CAS permissions under default CAS policy. In order to prevent remotely sourced applications from escalating their own CAS privilege via this mechanism, the SQLCLR probably ought to assign zone evidence based on database source locations in a manner similar to what the stand-alone CLR does for assemblies. &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;I&gt;Secure by default?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Well, it looks like someone did at least give this one the old college try. For example, regardless of the master instance setting, a user instance will have &lt;B&gt;xp_cmdshell&lt;/B&gt; use disabled by default. Unfortunately, it's trivial to enable the option from within any application connected to a user instance since the user is running as a &lt;B&gt;sysadmin&lt;/B&gt;, so this is essentially just a bit of cosmetic cover-up. &lt;/P&gt;
&lt;P&gt;Given the current design, the only real "secure by default" setting that I can see would be to deploy SQL Server Express with user instance mode disabled by default. Since most machines on which the Express edition will be installed will likely never need to run user instances, it's really rather disappointing that it's enabled by default in the first place. Then again, this is an obvious ease of use vs. security trade-off, and it's not exactly difficult to imagine the meeting at which the decision was made... &lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;I&gt;Secure in deployment?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;There's little an administrator or user can do to make user instances more secure if they're enabled. There appears to be no information at all out there about the risks of their use, forget about guidance on &lt;A href="http://msdn.microsoft.com/security/default.aspx?pull=/library/en-us/dnsecure/html/sdl.asp#sdl2_topic1_2"&gt;"how to use it securely"&lt;/a&gt;. We'll have to wait to see if updates will be easy to deploy, but updating all user instances on any given machine will certainly pose some potentially interesting challenges. &lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;I&gt;Communications?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Well, I guess we'll see... ;) &lt;/P&gt;
&lt;H3&gt;Ouch! Band-aids, anyone?&lt;/H3&gt;
&lt;P&gt;If you need to install the SQL Server Express edition and want to protect yourself against these risks, there are a few things you can do. For starters, unless you absolutely need user instances, disabling them would probably be a really good idea. This can be done by executing &lt;B&gt;sp_configure&lt;/B&gt; against the master SQL Express instance on a machine as follows: &lt;/P&gt;&lt;PRE class=shaded&gt;sp_configure 'user instances enabled', '0'
GO

RECONFIGURE
GO&lt;/PRE&gt;&lt;BR&gt;
&lt;P&gt;Developers who distribute SQL Server Express edition with their applications might also want to keep this in mind. If you don't use user instances in your application, you should probably disable them as part of the installation. Also, given the risks involved with running user instances, you might want to consider avoiding their use if at all possible. (BTW, if you've installed Visual Studio 2005 on your machine, there's a good chance that SQL Express edition was also installed, and you might want to take a little break from reading this in order to run off and disable user instances.) &lt;/P&gt;
&lt;P&gt;So, that's all fine and dandy if you don't need user instances at all. What happens if you really need to run an application that uses user instances? For starters, you might want to limit which users can create user instances. Unfortunately, as far as I know, the only way to do this at present would be to remove user permissions on the directory created for a user instance. In other words, for any user to whom you wish to deny user instances, you would need to create a &lt;B&gt;%USERPROFILE%\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS&lt;/B&gt; folder, then remove the user's NTFS permissions on the folder. Since this is a major pain in the caboose, as well as easy to miss doing for any given account, it's the sort of thing you might want to consider automating via a default login script or similar mechanism. BTW, if you do make this permission alteration, other processes such as backups may be affected, so you might want to do some pretty thorough testing before, say, pushing this sort of thing out to your entire domain... &lt;/P&gt;
&lt;H3&gt;What about CAS permissions?&lt;/H3&gt;
&lt;P&gt;Sorry, but CAS isn't going to help much here if you allow connections to a user instance. Code with &lt;I&gt;any&lt;/I&gt; &lt;B&gt;SqlClientPermission&lt;/B&gt; can do anything the connecting user is allowed to do via the SQL Server instance. When connecting to a remote instance (or even a local non-user instance), the user's capabilities are usually (or so one would hope!) constrained by their NTFS permissions, SQL Server permissions, and limitations imposed by the configuration of the SQL Server instance. However, running as &lt;B&gt;sysadmin&lt;/B&gt; on a user instance, these contraints are mostly absent. If you grant any &lt;B&gt;SqlClientPermission&lt;/B&gt; to managed code that permits connection to a user instance, you are effectively granting permission for that code to do anything the user can do. The end result for a malicious application is the same as if you had granted unrestricted CAS permissions (aka "full trust"). In other words, you shouldn't be granting &lt;B&gt;SqlClientPermission&lt;/B&gt; that includes the possibility to connect to a user instance to any assembly unless you would happily grant unrestricted permissions as well. &lt;/P&gt;
&lt;P&gt;This means that granting unrestricted &lt;B&gt;SqlClientPermission&lt;/B&gt; to any code (other than as part of a full trust grant) is a pretty horrible idea. Unfortunately, if you want to grant "almost unrestricted" &lt;B&gt;SqlClientPermission&lt;/B&gt; that excludes the right to connect to user instances, the CAS permission configuration UIs won't be of much help. Instead, you'll need to define the permission "manually". The XML definition for such a permission might look like this (watch out for fakey angle brackets if you copy and paste): &lt;/P&gt;&lt;PRE class=shaded&gt;‹IPermission 
 class="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1"
 AllowBlankPassword="True"›

 ‹add KeyRestrictions="User Instance=;" KeyRestrictionBehavior="PreventUsage" /›
‹/IPermission›&lt;/PRE&gt;
&lt;P&gt;If you want to grant additional permissions to a network-sourced assembly so that it can connect to a SQL Server instance running any server on your network, I'd recommend you use something like the above permission rather than an unrestricted &lt;B&gt;SqlClientPermission&lt;/B&gt; grant. Otherwise, you might unwittingly be granting that assembly essentially unrestricted permissions over the machine on which it's executing via code run within a user instance. &lt;/P&gt;
&lt;H3&gt;Wrapping things up...&lt;/H3&gt;
&lt;P&gt;In my opinion, SQL Express user instances just plain don't meet the SD&lt;SUP&gt;3&lt;/SUP&gt;+C bar, and disabling them is probably the best way for most of us to protect ourselves against the risks they introduce. Then again, I am a something of a paranoid nutbag, so your mileage may vary greatly... ;)&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102950" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Speculations on the suprisingly under-documented world of SQL CLR CAS permission grants</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/11/05/102948.aspx</link><pubDate>Sun, 06 Nov 2005 01:57:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102948</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102948</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102948</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/11/05/102948.aspx#comments</comments><description>&lt;P&gt;I'd been hoping that the details of the SQL CLR CAS permission sets might make it into the SQL Server Books Online or other relevant documentation by the RTM timeframe. Unfortunately, I can't seem to find anything that even begins to resemble a listing of the permissions, never mind coverage of some of the pickier details of their assessment and consequences. I'd already started trying to investigate some of this on my own during the beta and, after spending a bit more time with the RTM build (&lt;I&gt;i.e.&lt;/I&gt;: pretty much wasting a perfectly good Saturday), &lt;A href="http://bordecal.mvps.org/Nicole/SqlClrCas/SqlClrCasSpeculations.htm"&gt;here's what I think I've discovered so far...&lt;/A&gt; (Click &lt;A href="http://bordecal.mvps.org/Nicole/SqlClrCas/SqlClrCasSpeculations.htm"&gt;here&lt;/A&gt; to read the whole kit and kaboodle.)&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102948" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Heads, you lose.  Tails, you lose.</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/21/102946.aspx</link><pubDate>Mon, 21 Feb 2005 14:38:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102946</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102946</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102946</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/21/102946.aspx#comments</comments><description>&lt;P&gt;&lt;I&gt;Finally wrapping up &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!108.entry"&gt;my rebuttal&lt;/a&gt; of &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/15/373604.aspx"&gt;Shawn's listing of reasons&lt;/a&gt; for forcing full trust of assemblies in the GAC...&lt;/I&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;6.a)&lt;/B&gt; &lt;I&gt;"Based upon the assumption that GACed assemblies are receiving FullTrust, tools such as NGEN can have simpler code paths around security."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Not too many users of the platform are likely to lose sleep worrying about how complex Microsoft's private implementation of such tools might be. If any given feature is too difficult to implement without eroding the security protections offered by the platform, dropping the feature might be a better solution than dropping the protection. Of course, this only holds true if one values security over the feature in question.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;6.b)&lt;/B&gt; &lt;I&gt;"And reducing complexity in code paths that involve security helps to reduce the risk of bugs, which is a very good thing."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Is it really necessary to sacrifice our ability to protect ourselves against similar bugs in the GACed assemblies distributed by both Microsoft and others simply in order to reduce the risk of bugs appearing in a much smaller set of supporting tools? Is Microsoft not concerned that the many GACed assemblies it distributes (and not just as part of the Framework itself) might be potentially just as buggy as these tools?&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;On the more general side of things...&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;It seems to me that this point is the actual reason Microsoft wants to force full trust in the GAC. The other points strike me as being little more than justifications that Microsoft is attempting to use to convince their clients (and maybe themselves?) that we shouldn't object to the change. Since I don't find the other five arguments to be even slightly compelling, I'd like to examine this "tools gains" issue in a bit more depth...&lt;/P&gt;
&lt;P&gt;Last week, &lt;A href="http://msdn.microsoft.com/msdnmag/issues/05/04/NGen/default.aspx"&gt;an article&lt;/a&gt; by &lt;A href="http://blogs.msdn.com/reidlw/"&gt;Reid Wilkes&lt;/a&gt; covering new NGen features became available on the &lt;A href="http://msdn.microsoft.com/msdnmag/"&gt;MSDN Magazine site&lt;/a&gt;. I had already suspected that the change in CAS behaviour might be the result of a security vs performance trade-off, and this article rang quite a few bells for me despite the fact that it made no mention of security (or at least not any that I could find).&lt;/P&gt;
&lt;P&gt;Assuming my guess is right, and the forced full trust of GACed assemblies is meant to support improved performance via reduction/elimination of runtime permission verifications in extended NGen scenarios, a couple of reasonable questions might be:&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;1.&lt;/B&gt; &lt;I&gt;Why move in this direction at all?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;The performance vs security trade-off is nothing new. Presumably quite a few decisions were made during the design of the v. 1 .NET Framework regarding where and how to strike the balance between these two quality factors. What could have changed to make things swing the other way? Has Microsoft has been receiving vociferous and frequent complaints about .NET performance? Has it been too difficult to sell folks on the idea that improved security comes at a cost? Is this due to nothing more than altered composition of the relevant product teams, with different people making different choices?&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;2.&lt;/B&gt; &lt;I&gt;Is there no alternative that might satisfy both those who want enhanced performance and those who want to maintain full CAS functionality?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;I can think of at least a couple of potential options:&lt;/P&gt;
&lt;P&gt;&lt;B&gt;a)&lt;/B&gt; CAS can already be disabled entirely, thereby allowing runtime stack walks for permission verification to be avoided. This is a client-controllable option that can be used to improve runtime performance. Why not tie assumed GAC full trust to this option, or some similar switch to be introduced for this purpose only? (Or might this sort of thing be the "complexity in code paths that involve security" that Microsoft is attempting to avoid?)&lt;/P&gt;
&lt;P&gt;&lt;B&gt;b)&lt;/B&gt; Accept that at least some performance and security goals may be incompatible. Instead of trying to accomodate all potential users with one platform that is too slow for some and too insecure for others, focus on the more generally important goal (security, of course ;)) in the generally distributed Framework and release an alternate framework for the other crowd.&lt;/P&gt;
&lt;P&gt;Of course, (a) may be more complex, and (b) might be more expensive, but implementing security is rarely both easy and cheap.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102946" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>If only everyone would just play nice...</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/21/102945.aspx</link><pubDate>Mon, 21 Feb 2005 14:37:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102945</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102945</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102945</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/21/102945.aspx#comments</comments><description>&lt;P&gt;&lt;I&gt;Continuing with &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!108.entry"&gt;my rebuttal&lt;/a&gt; of &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/15/373604.aspx"&gt;Shawn's listing of reasons&lt;/a&gt; for forcing full trust of assemblies in the GAC...&lt;/I&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;4.&lt;/B&gt; &lt;I&gt;"If an application is hosting the CLR, it has the ability to protect itself from assemblies it doesn't trust to load. For instance, SQL Server 2005 does not allow the Windows Forms library to load. Applications can provide an AppDomainManager and HostSecurityManager in order to disallow some assemblies from loading, or to tweak their grant sets."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;That's nice. Unfortunately, it does nothing to protect users against the majority of .NET applications, which are run outside of such custom hosts. I suppose this does mean that one could force stand-alone .NET apps to run in a host of one's choosing, but I have a really hard time seeing this is a general workaround for reduced CAS policy flexibility. Amongst other things, who could be trusted by most users to build, test, and distribute such a host (keeping in mind that &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!105.entry"&gt;a buggy host might introduce security problems of its own&lt;/a&gt;)?&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;5.&lt;/B&gt; &lt;I&gt;"Assembly-level declarative security still works to reduce the grant set, so if you really need it, there is a knob you can turn to reduce the granted permissions of an assembly stored in the GAC."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;This works for the assemblies we create, but not the ones we consume (either via our own code or applications authored by others). It would be naive not to recognize that some developers will be GACing assemblies just to acquire a guaranteed full trust grant. These are not folks who would be likely to be willing to reduce their permission grants in any way. They may also do some pretty silly things like blindly asserting any permission their own callers might need, thereby creating some rather ugly security holes on our machines.&lt;/P&gt;
&lt;P&gt;If the platform allows developers to abuse the system with such ease, it should at least allow users to protect themselves with as little effort.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102945" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>I'm so special...</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/18/102944.aspx</link><pubDate>Fri, 18 Feb 2005 15:26:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102944</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102944</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102944</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/18/102944.aspx#comments</comments><description>&lt;P&gt;&lt;I&gt;Continuing with &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!108.entry"&gt;my rebuttal&lt;/a&gt; of &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/15/373604.aspx"&gt;Shawn's listing of reasons&lt;/a&gt; for forcing full trust of assemblies in the GAC...&lt;/I&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;3.a)&lt;/B&gt; &lt;I&gt;"Since you have to be an administrator in order to add an assembly to the GAC, it is already considered special from a security standpoint."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Ouch. Got a few things to say about this one...&lt;/P&gt;
&lt;P&gt;&lt;B&gt;i.&lt;/B&gt; Joe User can't write to the Program Files directory either. Does this make it special too? (Rhetorical question, I hope. ;))&lt;/P&gt;
&lt;P&gt;&lt;B&gt;ii.&lt;/B&gt; One absolutely does not need to be an administrator to add assemblies to the GAC. Even under default ACLs (at least on fully patched Windows XP and .NET Framework 1.1), power users can also do so. Although I haven't tried this, I'm guessing that manipulation of ACLs might also allow any user to do so.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;iii.&lt;/B&gt; Unfortunately, far too many enterprise users (particularly in smaller businesses) and almost all home users run as admins. In practice, there's nothing special about a location to which all these folks can write. These are also the users who can most benefit from the protections offered by limitation of CAS permissions.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;iv.&lt;/B&gt; Windows 98, Windows 98 Second Edition, Windows ME are all &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=B7ADC595-717C-4EF7-817B-BDEFD6947019"&gt;listed as supported versions&lt;/a&gt; for the beta version of the v. 2.0 Framework. Assuming this doesn't change, the supposed "difficulty" of placing assemblies in the GAC shouldn't be a factor in the decision to force full trust of GACed assemblies.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;3.b)&lt;/B&gt; "For instance, strong name verification is skipped for assemblies that are loaded from the GAC."&lt;/P&gt;
&lt;P&gt;Well, I've never liked that one--surprise! :) Amongst other things, consider those poor Win9x users and all those folks who run with sufficient privileges to alter the contents of the GAC. Also, given that the ACLs on the GAC can be altered, it seems ridiculous for the platform provider to be making decisions based on an assumption that the default ACLs will be in effect.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102944" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>Secure by default?</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/18/102943.aspx</link><pubDate>Fri, 18 Feb 2005 15:25:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102943</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102943</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102943</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/18/102943.aspx#comments</comments><description>&lt;P&gt;&lt;I&gt;Continuing with &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!108.entry"&gt;my rebuttal&lt;/a&gt; of &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/15/373604.aspx"&gt;Shawn's listing of reasons&lt;/a&gt; for forcing full trust of assemblies in the GAC...&lt;/I&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;2.a)&lt;/B&gt; &lt;I&gt;"By side-effect, assemblies in the GAC did already receive FullTrust."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Under default policy only. I'd be one of the first to argue that this default policy is probably too permissive, but it's a little late in the game for that. At least those of us who don't like the default policy can alter it so that not all locally installed code is fully trusted. Forcing full trust of all assemblies in the GAC would deny us that possibility.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;2.b)&lt;/B&gt; &lt;I&gt;"The only way that you could change this would be to either not grant MyComputer FullTrust, or create an exclusive code group that matched the strong name of the assembly and granted less trust."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Yup. I run almost all my machines (both desktops and servers) with only SecurityPermission\Execution granted to the My_Computer_Zone code group. It causes the occasional bit of pain, but I prefer it to the alternative.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102943" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>I'm in the platform?  Little old me?</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102942.aspx</link><pubDate>Thu, 17 Feb 2005 19:13:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102942</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102942</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102942</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102942.aspx#comments</comments><description>&lt;P&gt;After introducing &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/10/370743.aspx"&gt;a Microsoft plan&lt;/a&gt; to force full trust all assemblies in the GAC, &lt;A href="http://blogs.msdn.com/shawnfa/"&gt;Shawn Farkas&lt;/a&gt; posted &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/15/373604.aspx"&gt;follow-up&lt;/a&gt; inviting further feeback. Included in his post are six points explaining some of the reasoning behind the change. In my opinion, none of these reasons even begins to justify the change, and I'd like to present some counter-arguments to each. I'll address each of Shawn's points in a separate post here, with the individual points and subpoints labeled for ease of discussion.&lt;/P&gt;
&lt;P&gt;Starting with point 1...&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;1.a)&lt;/B&gt; &lt;I&gt;"Assemblies in the GAC build up the managed platform that all managed applications can run on."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Not all assemblies in the GAC are meant to form part of the general .NET platform, just as not all DLLs in the Windows\System32 folder form part of the Windows platform. Microsoft lost the right to assume this the moment every Tom, ***, and Harry were allowed to put their assemblies in the GAC.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;1.b)&lt;/B&gt; &lt;I&gt;"In order to build up a platform where any application, trusted or not, can run safely, it makes sense that you need to trust the assemblies making up that platform."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;But that trust need not be blind. See &lt;A href="http://spaces.msn.com/members/calinoiu/Blog/cns!1pYmj2Kpn4Oz9CW9IKwXQF8A!105.entry"&gt;my earlier post on trust decisions&lt;/a&gt; for why one might not want to grant full trust to even the most trustworthy assemblies.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;1.c)&lt;/B&gt; &lt;I&gt;"If you don't trust an assembly enough for any code to be able to call into it, then the best place for it is probably not the GAC"&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;i.&lt;/B&gt; On inappropriate GACing:&lt;/P&gt;
&lt;P&gt;By and large, the decision to place any given assembly in the GAC or not is made by the folks who author and distribute applications, not the folks who run their installation packages. I might decide not to install an app once I find out that it puts assemblies in the GAC in a manner that I find unnecessary (and I'll be far more likely to make this decision if the change goes through), but I won't be adjusting someone else's app or installer to avoid putting their assemblies in the GAC.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;ii.&lt;/B&gt; On trusting GACed assemblies:&lt;/P&gt;
&lt;P&gt;Under v. 1.x rules, one could set policy to grant only partial trust to assemblies in the GAC, so allowing other folks' apps to put assemblies in the GAC did not necessarily cause a trust problem. The problem is introduced by eliminating the possibility to the restrict GACed assemblies to the permission one feels they actually merit.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102942" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>Keep it simple, smarty</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102941.aspx</link><pubDate>Thu, 17 Feb 2005 18:01:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102941</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102941</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102941</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102941.aspx#comments</comments><description>&lt;P&gt;&lt;EM&gt;This post is in response to &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/10/370743.aspx"&gt;a Microsoft plan&lt;/a&gt; to force full trust all assemblies in the GAC regardless of CAS policy settings.&lt;/EM&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;CAS&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Imagine for a moment that you could find an "intro to CAS" document from Microsoft that gives a simple, clear statement of the purpose of CAS. What would that statement be?&lt;/P&gt;
&lt;P&gt;Unfortunately, my own search for such a document failed to turn up anything that didn't jump directly from the "why" into the "how" of CAS, leaving the reader to infer the purpose from the "why". In the absence of a clear statement of from Microsoft (unless someone else has seen one?), I'm going to propose the following:&lt;/P&gt;
&lt;P&gt;&lt;I&gt;The purpose of code access security is to permit restriction of the activities available to managed code beyond the limitations imposed by permissions (not) granted to the user executing the code.&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;If one agrees with the above statement, then it should be very difficult to accept a modification to CAS that makes it impossible to control permissions for any managed code. After all, if the purpose of CAS is to allow restriction of code permissions, how does eliminating the restrictability of permissions for some code fit in?&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;The GAC&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;What's the purpose of the GAC? I had a little better luck this time around and found the following statement in the &lt;A href="http://msdn.microsoft.com/library/en-us/cpguide/html/cpconglobalassemblycache.asp"&gt;Global Assembly Cache&lt;/a&gt; topic in the &lt;A href="http://msdn.microsoft.com/library/en-us/netstart/html/sdk_netstart.asp"&gt;.NET Framework Developer's Guide&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;"The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer."&lt;/P&gt;
&lt;P&gt;One could argue that the above isn't necessarily a definitive statement of purpose, so let's also consider the following instructions from the same document:&lt;/P&gt;
&lt;P&gt;"You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required."&lt;/P&gt;
&lt;P&gt;CAS isn't mentioned at all. There's nothing about placing assemblies in the GAC in order to obtain a full trust grant. Unfortunately, if the plan to force full trust for GACed assemblies goes through, folks will violate the above instructions simply to ensure their code is granted full trust. The worst abusers of the GAC will probably be those developers who are least familiar with (and/or least willing to abide by) the principles and practices of secure development. Do you really want their assemblies being guaranteed full trust on your machine?&lt;/P&gt;
&lt;P&gt;&lt;B&gt;UPDATE:&lt;/B&gt; Microsoft is already &lt;A href="http://www.gotdotnet.com/team/changeinfo/Backwards1.1to2.0/default.aspx#00000047"&gt;recommending that folks place assemblies in the GAC solely in order to obtain a full trust grant&lt;/a&gt;.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;B&gt;CAS and the GAC&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;I actually happen to think that the introduction of GacMembershipCondition (assuming it sticks around) and the associated easing of assignment of special permissions to GACed assemblies is quite reasonable. If .NET 2.0 were to ship with a code group granting full trust to assemblies in the GAC (redundant though that may be if all local code is already granted full trust), I wouldn't complain despite the apparent violation of the "secure by default" principle. After all, those of us who care about running code with least privilege would still be free to modify CAS policy in order to reduce the permission grants, and ignorant and/or lazy developers wouldn't be able to grab full trust simply by GACing their assemblies on our machines.&lt;/P&gt;
&lt;P&gt;However, enforcing full trust for GACed assemblies has some potential consequences beyond simply removing our immediate ability to limit the permissions of potentially "bad" code in the GAC. I would imagine that quite a few very smart people spent rather a lot of time mapping out the goals for CAS and the GAC. If one accepts that their visions for CAS and the GAC were reasonable, then corruption of those goals should not be irrevocably built into the framework. Of course, no software feature is ever strictly final, but Microsoft has repeatedly demonstrated an unwillingness to make breaking changes. Unfortunately, if this change goes through, the rather large segment of the developer population that will want to run their code as fully trusted will likely complain very loudly if the change is ever reversed.&lt;/P&gt;
&lt;P&gt;What do you think will happen a few years down the road if folks at Microsoft decide that the original vision was right after all?&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102941" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item><item><title>Do I trust you? Well, sort of...</title><link>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102939.aspx</link><pubDate>Thu, 17 Feb 2005 18:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:102939</guid><dc:creator>calinoiu</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/rsscomments.aspx?PostID=102939</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/calinoiu/commentapi.aspx?PostID=102939</wfw:comment><comments>http://msmvps.com/blogs/calinoiu/archive/2005/02/17/102939.aspx#comments</comments><description>&lt;P&gt;&lt;EM&gt;This post is in response to &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/02/10/370743.aspx"&gt;a Microsoft plan&lt;/a&gt; to force full trust all assemblies in the GAC regardless of CAS policy settings.&lt;/EM&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;For some time now, I've been rather disappointed with the view of code trustworthiness that seems to be generally espoused at Microsoft. IMO, there are at least two main issues to address when evaluating the trustworthiness of code (and/or its source):&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do I trust it to not be deliberately malicious? 
&lt;LI&gt;Do I trust it to not contain any exploitable flaws?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;As far as I can tell, Microsoft seems to be concentrating mostly on #1* (and not just with respect to CAS and the .NET Framework). However, I worry at least as much, if not more, about #2. Unfortunately, even the most well intentioned of developers are not necessarily all that competent, particularly when it comes to security.&lt;/P&gt;
&lt;P&gt;Even when developers are competent and careful, there's every reason to expect that their code will contain at least some exploitable flaws since bugs related to security will likely be at least as frequent as problems in any other area. Therefore, even if I trust the developers of a given assembly to be both non-malicious and competent, I would still want to run their code with least possible privilege. This is simple defense in depth.&lt;/P&gt;
&lt;P&gt;If all assemblies in the GAC are to become fully trusted regardless of policy settings, administrators will have no way of enforcing least privilege for these assemblies. Is the loss of this ability really worth any trade-off with respect to possible gains that might result in other areas?&lt;/P&gt;&lt;BR&gt;&lt;BR&gt;
&lt;P&gt;*Interestingly enough, the &lt;A href="http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcodeaccesssecurity.asp"&gt;Code Access Security&lt;/a&gt; topic in the &lt;A href="http://msdn.microsoft.com/library/en-us/netstart/html/sdk_netstart.asp"&gt;.NET Framework Developer's Guide&lt;/a&gt; does mention #2 as one of the reasons for the limitation of code permissions under CAS. Unfortunately, it would seem that someone has forgotten about this along the way.&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=102939" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/calinoiu/archive/tags/CAS/default.aspx">CAS</category></item></channel></rss>