<?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 : Silverlight</title><link>http://blogs.msdn.com/shawnfa/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Differences Between the Security Rule Sets</title><link>http://blogs.msdn.com/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx</link><pubDate>Thu, 12 Nov 2009 20:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921126</guid><dc:creator>shawnfa</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/9921126.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=9921126</wfw:commentRss><description>&lt;p&gt;In my last post I talked about the &lt;a href="http://blogs.msdn.com/shawnfa/archive/2009/11/11/transparency-models-a-tale-of-two-levels.aspx"&gt;two different security rule sets supported by the v4 CLR&lt;/a&gt;.&amp;#160; At a high level, level 1 is the v2.0 security transparency model, and level 2 encompasses the updated v4 security transparency model.&amp;#160; Digging down a little deeper, it’s interesting to look at some of the exact details that change between the various transparency models.&amp;#160; For fun, let’s also compare both rule sets to Silverlight.&lt;/p&gt;  &lt;p&gt;A couple of interesting things to notice – the level 2 rules look quite similar to the Silverlight rules.&amp;#160; This means that you can basically learn one set of core security enforcement rules and apply them to both desktop and Silverlight development.&amp;#160; As I mentioned previously, it’s also interesting to note that &lt;a href="http://blogs.msdn.com/shawnfa/archive/2009/11/09/transparency-as-enforcement-in-clr-v4.aspx"&gt;the penalty for transparency violations in level 2 transparency are generally hard failures, while the penalty in level 1 was generally triggering a full trust demand&lt;/a&gt;.&amp;#160; That means that many of the level 1 transparency violations are generally more expensive (since they incur a runtime check at each invocation, rather than a single JIT time check).&amp;#160; They also have a tendency to hide on you, since runtime checks can sometimes succeed during testing, and fail once you deploy your app to a new environment.&lt;/p&gt;  &lt;p&gt;In the interest of completeness, I’m going to list several things in this table that I have yet to blog about.&amp;#160; (Although, you’ll recognize many of &lt;a href="http://blogs.msdn.com/shawnfa/archive/2009/11/03/transparency-101-basic-transparency-rules.aspx"&gt;the core transparency rules&lt;/a&gt; covered here.) Over the next few weeks, I should cover the various interesting pieces of this table – but rather than waiting to blog about them before adding them here, I think it would be more useful to list the full table now.&lt;/p&gt;  &lt;p&gt;I’ll also note that while level 1 transparency is supported in the v4 runtime, it exists solely for compatibility with existing code.&amp;#160; No new code should be written using the level 1 rule set, and over time existing code should consider moving to the level 2 rule set as well.&amp;#160; (That is, don’t necessarily treat this chart as a way to select which security rule set you want to work with, but rather as a way to compare the evolution of transparency from .NET 2.0, to Silverlight 2, and finally into .NET 4).&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2"&gt;&lt;thead&gt;     &lt;tr&gt;       &lt;td&gt;&amp;#160;&lt;/td&gt;        &lt;td&gt;&lt;strong&gt;Level 1 (v2)&lt;/strong&gt;&lt;/td&gt;        &lt;td&gt;&lt;strong&gt;Level 2 (v4)&lt;/strong&gt;&lt;/td&gt;        &lt;td&gt;&lt;strong&gt;Silverlight 2&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/thead&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Introduced in&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;.NET 2.0&lt;/td&gt;        &lt;td&gt;.NET 4&lt;/td&gt;        &lt;td&gt;Silverlight 2&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Default for&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Assemblies built against runtimes prior to v4&lt;/td&gt;        &lt;td&gt;Assemblies built against the v4 runtime&lt;/td&gt;        &lt;td&gt;Silverlight assemblies&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Explicit attribute&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;[&lt;span style="color: blue"&gt;assembly&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;SecurityRules&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SecurityRuleSet&lt;/span&gt;.Level1)] &lt;/td&gt;        &lt;td&gt;[&lt;span style="color: blue"&gt;assembly&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;SecurityRules&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SecurityRuleSet&lt;/span&gt;.Level2)]&lt;/td&gt;        &lt;td&gt;N/A – all assemblies use the Silverlight transparency model&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Attribute to create a mixed transparency assembly (containing a combination of critical, safe critical, and transparent code in a single assembly)&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;[&lt;span style="color: blue"&gt;assembly&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;SecurityCritical&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SecurityCriticalScope&lt;/span&gt;.Explicit)]&lt;/td&gt;        &lt;td&gt;[&lt;span style="color: blue"&gt;assembly&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;AllowPartiallyTrustedCallers&lt;/span&gt;]&lt;/td&gt;        &lt;td&gt;N/A – platform assemblies are all mixed transparency, application assemblies are all fully transparent&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Effect of the APTCA attribute&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Allows partial trusted callers access to the assembly by removing an implicit link demand for full trust on all code in signed assemblies.&lt;/td&gt;        &lt;td&gt;Allows partial trusted callers access to the assembly by making all code in the assembly transparent by default. (Although the assembly can explicitly make some of the code critical or safe critical.)&lt;/td&gt;        &lt;td&gt;N/A – Silverlight does not have the AllowPartiallyTrustedCallers attribute&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Publicly visible security critical members are implicitly safe critical&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Yes – there is no such thing as a publicly visible safe critical API in level 1 transparency.&lt;/td&gt;        &lt;td&gt;No – only APIs explicitly annotated as SecuritySafeCritical are safe critical.&lt;/td&gt;        &lt;td&gt;No – only APIs explicitly annotated as SecuritySafeCritical are safe critical.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Link demands should be used for JIT time security enforcement&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Yes – since publicly visible critical APIs are implicitly safe critical, link demands must be used to prevent JIT time access to security sensitive APIs.&lt;/td&gt;        &lt;td&gt;No – since code must be critical to access either a link demand or a public critical API, level 2 transparency deprecates the use of granular link demands in favor of simply protecting security sensitive APIs by keeping them security critical.&lt;/td&gt;        &lt;td&gt;No – Silverlight does not support link demands.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Result if a transparent method attempts to call a method protected by a link demand&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;The link demand is converted into a full demand at runtime, which may fail with a SecurityException.&lt;/td&gt;        &lt;td&gt;A MethodAccessException will be thrown at JIT time.&lt;/td&gt;        &lt;td&gt;N/A – Silverlight does not support link demands.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Result if a transparent method attempts to call unmanaged code&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;A demand for SecurityPermission/UnmanagedCode will be triggered at runtime, which may fail with a SecurityException.&lt;/td&gt;        &lt;td&gt;A MethodAccessException will be thrown at JIT time.&lt;/td&gt;        &lt;td&gt;A MethodAccessException will be thrown at JIT time.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Result if a transparent method has unverifiable IL&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;A demand for SecurityPermission/UnmanagedCode will be triggered at runtime, which may fail with a SecurityException.&lt;/td&gt;        &lt;td&gt;A VerificationException will be thrown at JIT time.&lt;/td&gt;        &lt;td&gt;A VerificationException will be thrown at JIT time.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Result if a transparent method attempts to perform a security assert&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;An InvalidOperationException is thrown at runtime.&lt;/td&gt;        &lt;td&gt;An InvalidOperationException is thrown at runtime.&lt;/td&gt;        &lt;td&gt;N/A – Silverlight does not support security asserts.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Result if at transparent attempts to call a critical method&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;If the method is:          &lt;ul&gt;           &lt;li&gt;&lt;em&gt;Within the same assembly&lt;/em&gt; – a MethodAccessException is thrown at JIT time. &lt;/li&gt;            &lt;li&gt;&lt;em&gt;In another level 1 assembly&lt;/em&gt; – N/A (level 1 publicly visible critical code is implicitly safe critical, so there is no violation). &lt;/li&gt;            &lt;li&gt;&lt;em&gt;In a level 2 assembly&lt;/em&gt; – the critical code is treated as safe critical with a link demand for full trust.&amp;#160; This, in turn, triggers a runtime demand for full trust which may fail with a SecurityException. &lt;/li&gt;         &lt;/ul&gt;       &lt;/td&gt;        &lt;td&gt;A MethodAccessException is thrown at JIT time.&lt;/td&gt;        &lt;td&gt;A MethodAccessException is thrown at JIT time.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Transparency of partial trust assemblies&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Fully transparent – all transparency annotations are ignored for partial trust assemblies.&lt;/td&gt;        &lt;td&gt;Fully transparent – all transparency annotations are ignored for partial trust assemblies.&lt;/td&gt;        &lt;td&gt;Application assemblies are fully transparent – all transparency annotations are ignored for them.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Default transparency for assemblies which are security agnostic&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;All types are transparent, all methods are safe critical.&lt;/td&gt;        &lt;td&gt;All types and methods are security critical (except where this would violate inheritance rules).&lt;/td&gt;        &lt;td&gt;N/A – all Silverlight assemblies are exposed to the sandbox.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Protection for non-APTCA assemblies being used by partial trust code&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Provided to all signed assemblies by adding an implicit link demand for full trust to all code within the signed assembly.&lt;/td&gt;        &lt;td&gt;Provided to all fully trusted assemblies because all of the types and methods within a non-APTCA assembly are security critical by default (see above).&lt;/td&gt;        &lt;td&gt;N/A – all Silverlight assemblies are exposed to the sandbox.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Fully transparent assemblies are exposed to partial trust&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No – signed fully transparent assemblies still have an implicit link demand for full trust unless they are additionally marked APTCA&lt;/td&gt;        &lt;td&gt;Yes – no additional APTCA attribute is required for fully transparent code. &lt;/td&gt;        &lt;td&gt;Yes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Critical members can be converted to safe critical members protected by a link demand for FullTrust&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No&lt;/td&gt;        &lt;td&gt;Yes.&amp;#160; If a publicly visible security critical method is called by a security transparent level 1 method, the CLR will treat the critical method as if it was safe critical with a link demand for full trust on it.&amp;#160; (If the caller is level 2, this conversion does not occur).&lt;/td&gt;        &lt;td&gt;No&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Security critical annotations support both applying to a larger scope (type, assembly, etc) and all of its contained members, or only the scope itself&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Yes.&amp;#160; The SecurityCriticalScope enumeration is used to toggle between having a SecurityCritical attribute apply to only the container (SecurityCriticalScope.Explicit) or the container and all of its members (SecurityCriticalScope.Everything)&lt;/td&gt;        &lt;td&gt;No.&amp;#160; SecurityCriticalScope is not used in level 2 assemblies, and is ignored if it is provided.&amp;#160; All security critical attributes implicitly use SecurityCriticalScope.Everything.&lt;/td&gt;        &lt;td&gt;No.&amp;#160; All SecurityCritical attributes implicitly use SecurityCriticalScope.Everything.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Members introduced within a security critical scope can add additional attributes to become safe critical&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;Yes.&amp;#160; Adding a SecurityTreatAsSafe or SecuritySafeCritical attribute within a critical scope changed the contained member’s transparency.&lt;/td&gt;        &lt;td&gt;No.&amp;#160; The larger scope always wins, attributes applied at smaller scopes are not considered.&lt;/td&gt;        &lt;td&gt;No.&amp;#160; The larger scope always wins, attributes applied at smaller scopes are not considered. &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Critical or safe critical annotations at a larger scope (type, assembly, etc) introduce only to methods introduced directly in a type. Overridden virtuals and interface implementations do not use the larger scoped annotation and are transparent by default.&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No, the outer scope applies to all contained members.&lt;/td&gt;        &lt;td&gt;Yes.&amp;#160; Since the transparency of the members not introduced by the local type are not under its direct control, overrides and interface implementations must restate their intended transparency.&lt;/td&gt;        &lt;td&gt;Yes.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Can define security critical attributes that are protected from use by partial trust code&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No.&amp;#160; Link demands must be used for this purpose.&lt;/td&gt;        &lt;td&gt;Yes.&amp;#160; Security critical attributes cannot be applied to transparent targets.&lt;/td&gt;        &lt;td&gt;Yes.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;If reflected upon, security critical targets trigger a security demand&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No, although link demands do become full demands under reflection.&lt;/td&gt;        &lt;td&gt;Yes.&amp;#160; Reflecting upon a level 2 security critical target will trigger a full demand for full trust.&amp;#160; This happens based upon the target of the reflection, not based upon the code that is performing the reflection operation.&amp;#160; (For example, level 1 code reflecting on a level 2 critical method will still trigger the demand).&lt;/td&gt;        &lt;td&gt;Yes.&amp;#160; Transparent code may not reflect upon critical code.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;th&gt;&lt;strong&gt;Delegate binding rules are enforced&lt;/strong&gt;&lt;/th&gt;        &lt;td&gt;No.&lt;/td&gt;        &lt;td&gt;No.&lt;/td&gt;        &lt;td&gt;Yes – Silverlight contains delegate binding rules that prevent critical delegates from being bound to transparent targets and vice versa.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9921126" 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/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/CLR+v4/default.aspx">CLR v4</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Transparency/default.aspx">Transparency</category></item><item><title>MD5 on Silverlight</title><link>http://blogs.msdn.com/shawnfa/archive/2008/12/09/md5-on-silverlight.aspx</link><pubDate>Wed, 10 Dec 2008 04:39:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9188680</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/9188680.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=9188680</wfw:commentRss><description>&lt;p&gt;Reid Borsuk, an SDE/T on the CLR security team, has released &lt;a href="http://code.msdn.microsoft.com/SilverlightMD5"&gt;a fully transparent implementation of the MD5 hash algorithm to the MSDN Code Gallery&lt;/a&gt;.&amp;#160; Since the code is entirely transparent, it can be used as part of a Silverlight application that needs to compute MD5 hashes in order to interop with existing code or file formats that requires MD5.&lt;/p&gt;  &lt;p&gt;He's also released an MD5Managed type to wrap around his implementation, in case you want to plug the algorithm into the standard .NET hash object model.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9188680" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/shawnfa/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Dr. Dobbs Looks at Silverlight Security</title><link>http://blogs.msdn.com/shawnfa/archive/2008/07/09/dr-dobbs-looks-at-silverlight-security.aspx</link><pubDate>Wed, 09 Jul 2008 21:07:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8713138</guid><dc:creator>shawnfa</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/8713138.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=8713138</wfw:commentRss><description>&lt;p&gt;Dino Esposito has an article in the March Dr. Dobb's Journal taking a look at the Silverlight platform from a security perspective: &lt;a href="http://www.ddj.com/security/206902613"&gt;The Silverlight 2.0 Security Model&lt;/a&gt;.&amp;#160; The second half in particular boils down some of the details of &lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/14/silverlight-security-cheat-sheet.aspx"&gt;the transparency model used for security enforcement in Silverlight&lt;/a&gt;.&amp;#160; This article is quite good - I definitely recommend a read.&lt;/p&gt;  &lt;p&gt;In his article, Dino talks about the SecuritySafeCritical attribute as compared to the SecurityTreatAsSafe attribute, and points out that on the desktop framework any public critical method is implicitly TreatAsSafe.&amp;#160; He mentions that one of the reasons we didn't bring TreatAsSafe over to the Silverlight BCL is that this is not true on Silverlight.&lt;/p&gt;  &lt;p&gt;To add to this, there's one other thing that made The other thing that made us decide that SafeCritical would be better than TreatAsSafe was that the only time TreatAsSafe really makes sense is when you're combining it with SecurityCritical.&amp;#160; A TreatAsSafe transparent method, for instance, doesn't buy you anything.&amp;#160; Since 95% of the cases where the TreatAsSafe attribute was being used also used the SecurityCritical attribute, we decided to merge the two into a single attribute - SecuritySafeCritical.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8713138" 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/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight Security Cheat Sheet</title><link>http://blogs.msdn.com/shawnfa/archive/2007/05/14/silverlight-security-cheat-sheet.aspx</link><pubDate>Mon, 14 May 2007 18:45:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2627558</guid><dc:creator>shawnfa</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/2627558.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=2627558</wfw:commentRss><description>&lt;p&gt;Over the last week we took a look at the new &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt; security model.&amp;nbsp; When you're writing a Silverlight application though, there's a lot of information there that you may not want to wade through to get yourself unblocked.&amp;nbsp; Here's a quick cheat sheet highlighting the important points that you'll need to know when working with the Silverlight security model:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;All applications written for Silverlight are security transparent.&amp;nbsp; This means that they cannot: &lt;span style="font-size: x-small"&gt;[&lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx"&gt;details&lt;/a&gt;]&lt;/span&gt;  &lt;ul&gt; &lt;li&gt;Contain unverifiable code  &lt;li&gt;Call native code directly&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Silverlight applications can access&amp;nbsp;public methods exposed by platform assemblies which are either: &lt;span style="font-size: x-small"&gt;[&lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/10/silverlight-security-ii-what-makes-a-method-critical.aspx"&gt;details&lt;/a&gt;]&lt;/span&gt;  &lt;ul&gt; &lt;li&gt;Security transparent (neither the defining type nor the method has any security attributes)  &lt;li&gt;Security safe critical (the method has a SecuritySafeCriticalAttribute)&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Silverlight applications may contain types which derive from: &lt;span style="font-size: x-small"&gt;[&lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/11/silverlight-security-iii-inheritance.aspx"&gt;details&lt;/a&gt;]&lt;/span&gt;  &lt;ul&gt; &lt;li&gt;Other types defined in the application  &lt;li&gt;Unsealed,&amp;nbsp;public,&amp;nbsp;security transparent types and interfaces defined by the platform&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Silverlight applications may contain types which override virtual&amp;nbsp;methods and implements interface methods which are: &lt;span style="font-size: x-small"&gt;[&lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/11/silverlight-security-iii-inheritance.aspx"&gt;details&lt;/a&gt;]&lt;/span&gt;  &lt;ul&gt; &lt;li&gt;Defined in the application itself  &lt;li&gt;Defined by the platform and are transparent or safe critical&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2627558" 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/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight Security III: Inheritance</title><link>http://blogs.msdn.com/shawnfa/archive/2007/05/11/silverlight-security-iii-inheritance.aspx</link><pubDate>Fri, 11 May 2007 18:12:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2548108</guid><dc:creator>shawnfa</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/2548108.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=2548108</wfw:commentRss><description>&lt;p&gt;Over the last few days we've looked at &lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx"&gt;the basics of the CoreCLR security model in Silverlight&lt;/a&gt;, and &lt;a href="http://blogs.msdn.com/shawnfa/archive/2007/05/10/silverlight-security-ii-what-makes-a-method-critical.aspx"&gt;how to tell which platform APIs are available for applications to call&lt;/a&gt;.&amp;nbsp; Let's wrap up this mini-series on CoreCLR security by looking at how the CoreCLR transparency model interacts with inheritance in the Silverlight platform.&lt;/p&gt; &lt;p&gt;From what we already know, we can define a logical&amp;nbsp;ordering among the transparency levels:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Transparent (application / platform)  &lt;li&gt;Safe critical (platform only)  &lt;li&gt;Critical (platform only)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;What's all this got to do with inheritance?&amp;nbsp;&amp;nbsp;This ordering becomes very&amp;nbsp;important when determining if a class is allowed to derive from a parent class.&amp;nbsp; A class may only derive from a type at its level in that ladder or higher.&amp;nbsp; It may never derive from a base class lower on the ladder.&amp;nbsp; This means, for instance,&amp;nbsp;that critical types can derive from any other type while a transparent type may only derive from other transparent types.&lt;/p&gt; &lt;p&gt;We can apply this to types in a Silverlight application relatively easily.&amp;nbsp; Since all application code is transparent, it stands to reason that all of the types in application assemblies are also transparent.&amp;nbsp; Applying this rule, we see that application types may only derive from other application types or transparent platform types. (*)&lt;/p&gt; &lt;p&gt;In the same way that the security rules for method access are on top of the standard runtime access rules, the rules for inheritance are also in addition to the standard runtime inheritance rules.&amp;nbsp; So an application type may not derive from a sealed transparent type in a platform assembly for instance, since the CLR does not allow derivation from sealed types.&lt;/p&gt; &lt;p&gt;One of the more interesting things to do once you've derived from a type is to start overriding virtual methods (or implementing interface methods).&amp;nbsp; Not surprisingly, we have security checks for these overrides as well which are also based upon the transparency model.&amp;nbsp; When talking about overriding methods, it's convenient to group the different security groups into two accessibility levels:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Transparent and safe critical code  &lt;li&gt;Critical code&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;When grouped this way, we see that transparent code has access to everything in the first level while only critical (including safe critical) code has access to the second level.&lt;/p&gt; &lt;p&gt;With that in mind, the simple rule is that a method may only be overridden by another method in the same accessibility level.&amp;nbsp; So a Silverlight application may override any virtual from within their application, as well as any transparent or safe critical platform virtuals.&amp;nbsp; (Assuming, of course, that the application type was allowed to derive from the platform type).&lt;/p&gt; &lt;p&gt;The same rule applies when it comes to interface implementations.&amp;nbsp; A Silverlight application may implement all methods on any interface defined by the application itself.&amp;nbsp; If the interface is supplied by a platform assembly, then the application my only implement methods which are either transparent or safe critical.&amp;nbsp; Practically speaking this means that Silverlight applications may not implement any interface which contains any critical members.&lt;/p&gt; &lt;p&gt;We&amp;nbsp;can summarize the CoreCLR security inheritance rules for applications into three quick rules:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Types may only derive from base types that are&amp;nbsp;transparent.  &lt;li&gt;Only&amp;nbsp;transparent or safe critical methods may be overridden  &lt;li&gt;Only transparent or safe critical interface methods may be implemented&lt;/li&gt;&lt;/ol&gt; &lt;hr&gt;  &lt;p&gt;&amp;nbsp;(*) This true in 99.9% case.&amp;nbsp; There is another rule about the visibility of the default constructor of a class (which we'll get into next week when we dig deeper into the security model), which also requires that the base class' default constructor (if it has one), must be transparent as well.&amp;nbsp; Practically speaking, you're not generally going to find interesting transparent types in the platform which do not also have transparent default constructors, so this rule doesn't normally come into play.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2548108" 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/Silverlight/default.aspx">Silverlight</category></item><item><title>Silverlight Security II: What Makes a Method Critical</title><link>http://blogs.msdn.com/shawnfa/archive/2007/05/10/silverlight-security-ii-what-makes-a-method-critical.aspx</link><pubDate>Thu, 10 May 2007 18:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2524968</guid><dc:creator>shawnfa</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/2524968.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=2524968</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx"&gt;Yesterday we talked about the CoreCLR security model&lt;/A&gt;, and how it is built upon the transparency model introduced in the v2.0 .NET Framework.&amp;nbsp; The quick summary was that all Silverlight application code is transparent, and transparent code may only call other transparent code and safe critical code.&amp;nbsp; With that in mind, lets take a look at figuring out how can tell which platform APIs fall into each category ... allowing us to know which APIs our applications are allowed to call.&lt;/P&gt;
&lt;P&gt;In Silverlight, by default all code is transparent.&amp;nbsp; (This is different from the desktop CLR, where all code is critical by default).&amp;nbsp; For application code, that's the end of the story -- as we said yesterday, a fundamental tenant of the CoreCLR security model is that all application code is transparent.&lt;/P&gt;
&lt;P&gt;Platform code can be either transparent, safe critical, or critical however.&amp;nbsp; CoreCLR will detect platform code by knowing where the assembly is loaded from (platform assemblies must be loaded from the Silverlight installation directory), and also by checking the assembly's public key.&amp;nbsp; Only assemblies signed with specific Microsoft's public keys will be considered platform assemblies;&amp;nbsp;because of this public key requirement, no Silverlight application code can ever be considered a platform assembly.&lt;/P&gt;
&lt;P&gt;We can tell if a method is security critical or transparent by looking at the attributes on the method in question (and on the class that contains the method).&amp;nbsp; To simplify this discussion, I'll talk directly about attributes on methods, however if the class containing the method has one of the security attributes, then this attribute will apply to every method within the class.&lt;/P&gt;
&lt;P&gt;If a method in a platform assembly is marked with the SecurityCriticalAttribute, this means that it&amp;nbsp;contains critical code.&amp;nbsp; Even if the method is public, no application code can call it since transparent code may never directly call into critical code.&amp;nbsp; Any attempt to break this rule will lead to a MethodAccessException at runtime.&lt;/P&gt;
&lt;P&gt;For example, the constructor for FileStream in the Silverlight 1.1 alpha bits (snipped below)&amp;nbsp;is security critical which we can see from the SecurityCriticalAttribute on line 5:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 1em; FONT-SIZE: 10pt; BACKGROUND: lightgrey; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; COLOR: black; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; .method public hidebysig specialname rtspecialname &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; instance void&amp;nbsp; .ctor(string path,&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; valuetype System.IO.FileMode mode) cil managed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;B&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .custom instance void System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 )&lt;/B&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ...&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Similarly, every method in the Marshal class is also critical, since the entire class is marked with the SecurityCriticalAttribute on line 4:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 1em; FONT-SIZE: 10pt; BACKGROUND: lightgrey; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; COLOR: black; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/SPAN&gt;&amp;nbsp;.class public abstract auto ansi sealed beforefieldinit System.Runtime.InteropServices.Marshal&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; extends System.Object&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/SPAN&gt;&amp;nbsp;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/SPAN&gt;&lt;B&gt;&amp;nbsp;&amp;nbsp; .custom instance void System.Security.SecurityCriticalAttribute::.ctor() = ( 01 00 00 00 )&lt;/B&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; // ...&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/SPAN&gt;&amp;nbsp;} // end of class System.Runtime.InteropServices.Marshal&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A&amp;nbsp;method in a platform assembly marked with the SecuritySafeCriticalAttribute is, of course, safe critical.&amp;nbsp; Application code may call into these methods, since transparent code may call safe critical code.&amp;nbsp; And since safe critical code is critical, it can then turn around and call critical APIs on behalf of the application.&lt;/P&gt;
&lt;P&gt;One example of a safe critical API is the IsolatedStorageFileStream.Write, which we can see on line 6 of its disassembly:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black thin inset; PADDING-RIGHT: 1em; BORDER-TOP: black thin inset; PADDING-LEFT: 1em; FONT-SIZE: 10pt; BACKGROUND: lightgrey; PADDING-BOTTOM: 1em; MARGIN: 1em 1em 1em 2em; BORDER-LEFT: black thin inset; COLOR: black; PADDING-TOP: 1em; BORDER-BOTTOM: black thin inset; FONT-FAMILY: monospace"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; .method public hidebysig virtual instance void &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; Write(uint8[] buffer,&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int32 offset,&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int32 count) cil managed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/SPAN&gt;&lt;B&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .custom instance void System.Security.SecuritySafeCriticalAttribute::.ctor() = ( 01 00 00 00 )&lt;/B&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ...&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An interesting note is that the SecuritySafeCriticalAttribute is really just a combination of the desktop framework's SecurityCriticalAttribute and SecurityTreatAsSafeAttribute.&amp;nbsp; If you're familiar with the desktop CLR's &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/08/31/458641.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2005/08/31/458641.aspx"&gt;transparency&lt;/A&gt; &lt;A href="http://blogs.msdn.com/shawnfa/archive/2005/09/09/462975.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2005/09/09/462975.aspx"&gt;model&lt;/A&gt;, then you'll know that the TreatAsSafe attribute is implied for all public critical methods.&amp;nbsp; This is not true in the CoreCLR security model for Silverlight -- instead, safe critical methods must be explicitly marked.&lt;/P&gt;
&lt;P&gt;Since there&amp;nbsp;are no more implicit treat as safe methods, the need to explicitly annotate a method with both the SecurityCritical and the SecurityTreatAsSafe attributes became much more common, so SecuritySafeCritical was introduced as a shortcut; it saves time when typing and also reduces metadata size.&amp;nbsp; However, if you are familiar with the desktop CLR transparency model, it's safe to read "SecuritySafeCritical" as "SecurityCritical, SecurityTreatAsSafe" when reasoning about an API set.&lt;/P&gt;
&lt;P&gt;If a method has neither the SecurityCritical attribute nor the SecuritySafeCritical attribute applied to it, then the method must be transparent (since we said above that all code is transparent by default).&amp;nbsp; If this method is visible to the application code, that means that the application can call into it because transparent code is always allowed to call other transparent code.&lt;/P&gt;
&lt;P&gt;Incidentally, if a Silverlight application tries to be tricky and mark itself with one of the SecurityCritical or SecuritySafeCritical attributes nothing will happen.&amp;nbsp; The CLR knows that application code must be transparent, so it doesn't even bother to look for those two attributes when examining a method from a non-platform assembly.&amp;nbsp; Instead, the method with the disallowed attributes will continue to be treated as transparent, and if they try to do anything that is not allowed from a transparent method, an exception will be thrown.&lt;/P&gt;
&lt;P&gt;Finally, it's important to note that these rules do not replace the standard public / private / protected / internal access rules for the runtime; instead they supplement them.&amp;nbsp; So application code may not call an internal method in a platform assembly, even if the method is transparent.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;To summarize:&lt;/P&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 border=1 unselectable="on"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;&lt;I&gt;Security Attribute&lt;/I&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;&lt;I&gt;Means&lt;/I&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;&lt;I&gt;Directly callable by application code&lt;BR&gt;(if the method is visible)&lt;/I&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top&gt;Application Code&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;-&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Transparent&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Yes&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top&gt;Platform&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;None&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Transparent&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Yes&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top&gt;Platform&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;SecuritySafeCritical&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Safe critical&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Yes&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top&gt;Platform&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;SecurityCritical&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;Critical&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;No&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;Next time, we'll look at how this security model interacts with inheritance.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2524968" 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/Silverlight/default.aspx">Silverlight</category></item><item><title>The Silverlight Security Model</title><link>http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx</link><pubDate>Wed, 09 May 2007 18:07:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2504704</guid><dc:creator>shawnfa</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/shawnfa/comments/2504704.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shawnfa/commentrss.aspx?PostID=2504704</wfw:commentRss><description>&lt;a href="http://silverlight.net/" atomicselection="true"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; float: right; border-bottom-width: 0px; border-right-width: 0px" height="96" alt="Silverlight" src="http://blogs.msdn.com/blogfiles/shawnfa/WindowsLiveWriter/TheCoreCLRSecurityModel_834B/Silverlight_1.jpg" width="240" align="right" border="0"&gt;&lt;/a&gt;  &lt;p&gt;You may have &lt;a href="http://blogs.msdn.com/bclteam/archive/2007/04/30/introducing-microsoft-silverlight-1-1-alpha-justin-van-patten.aspx"&gt;heard&lt;/a&gt; &lt;a href="http://blogs.msdn.com/jasonz/archive/2007/04/30/announcing-net-framework-support-for-silverlight.aspx"&gt;a&lt;/a&gt; &lt;a href="http://www.techcrunch.com/2007/05/01/take-time-to-understand-silverlight-its-important/"&gt;thing&lt;/a&gt; &lt;a href="http://www.techcrunch.com/2007/04/30/silverlight-the-web-just-got-richer/"&gt;or&lt;/a&gt; &lt;a href="http://blogs.msdn.com/jasonz/archive/2007/05/03/silverlight-podcast-on-hanselminutes.aspx"&gt;two&lt;/a&gt; &lt;a href="http://arstechnica.com/news.ars/post/20070501-microsofts-flash-killer-steals-the-show-at-mix07.html"&gt;last&lt;/a&gt; &lt;a href="http://blogs.msdn.com/brada/archive/2007/05/02/silverlight-mix-the-home-games.aspx"&gt;week&lt;/a&gt; about a little project we like to call &lt;a href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt;, including a small version of the CLR that will run in the browser on both Windows and the Mac.&amp;nbsp; (If you haven't grabbed the Silverlight &lt;a href="http://msdn2.microsoft.com/en-us/asp.net/bb419317.aspx"&gt;v1.1 alpha&lt;/a&gt; bits yet, I highly recommend it -- as well as grabbing the &lt;a href="http://msdn.microsoft.com/vstudio/eula.aspx?id=c8bf88e7-841c-43fd-c63d-379943617f36"&gt;SDK&lt;/a&gt; and heading over to &lt;a href="http://www.silverlight.net/quickstarts/managed.aspx"&gt;the quickstarts site&lt;/a&gt; and &lt;a href="http://silverlight.net/forums/"&gt;forums&lt;/a&gt;&amp;nbsp;so that you can try it out for yourself).&lt;/p&gt; &lt;p&gt;Since the v1.1 release of Silverlight includes a slimmed down version of the CLR, you might be wondering what the managed security story for Silverlight is and how it compares to CAS on the desktop version of the CLR.&lt;/p&gt; &lt;p&gt;The good news for everyone who's spent hours deciphering cryptic caspol commands&amp;nbsp;is that Silverlight removes CAS entirely.&amp;nbsp; Instead, the security model is based around an enhanced version of the v2.0 &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/08/31/458641.aspx"&gt;transparency&lt;/a&gt; &lt;a href="http://blogs.msdn.com/shawnfa/archive/2005/09/09/462975.aspx"&gt;model&lt;/a&gt;.&amp;nbsp; When I say CAS is gone, I mean it's really gone --&amp;nbsp; there are no permissions, no policy levels, and no stack walks in CoreCLR.&amp;nbsp; The System.Security namespace is pretty barren indeed!&amp;nbsp; (But wait -- why is SecurityPermission still exposed from mscorlib then?&amp;nbsp; It turns out that the C# compiler will emit a RequestMinimum for SkipVerification if your assembly contains unverifiable code.&amp;nbsp; Since we need to be able to use the existing C# compiler to create Silverlight assemblies, we had to keep that one permission in the public surface area).&lt;/p&gt; &lt;p&gt;In place of CAS, the CoreCLR security model can be boiled down to the following two statements:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;All user code that runs on CoreCLR is entirely transparent  &lt;li&gt;Platform code may contain both transparent and critical code; it is responsible for providing a gateway for transparent code to safely access various system services.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Which means that the essence of the CoreCLR security model is that Silverlight applications may not contain unverifiable code and may only call transparent or safe critical APIs exposed from the platform.&amp;nbsp; Let's dig a little deeper into this.&lt;/p&gt; &lt;p&gt;Since transparency forms the, &lt;em&gt;ahem&lt;/em&gt;, core of the CoreCLR security model, let's take a minute to refresh the basics of what transparency means,&amp;nbsp;starting with the model we already know&amp;nbsp;on the v2.0 framework.&amp;nbsp; Transparent code is code which cannot perform any actions that would elevate the permissions of the call stack.&amp;nbsp; Essentially, security transparent code cannot cause any security check to succeed (although it can cause them to fail); so you can think of it as running with the permissions of its caller.&amp;nbsp; The opposite of transparent code is critical code, and assemblies may contain a combination of transparent and critical code.&amp;nbsp;&amp;nbsp;Individual methods may only be transparent or critical however; they cannot contain a mix of both.&lt;/p&gt; &lt;p&gt;The specific restrictions placed upon security transparent code is that it may not:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Satisfy a LinkDemand  &lt;li&gt;Perform a CAS Assert  &lt;li&gt;Contain unverifiable code  &lt;li&gt;Call native code via a P/Invoke or COM Interop  &lt;li&gt;Access critical code or data which does not specifically allow it.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;So let's start to translate this to the Silverlight world.&amp;nbsp; We know that there's no such thing as CAS in Silverlight, so the first two restrictions don't make sense there.&amp;nbsp; (Without CAS there are no permissions to assert or do a demand for, even just a LinkDemand).&amp;nbsp; On the desktop CLR, the next two restrictions are enforced by injecting a demand for UnmanagedCode.&amp;nbsp; Since we don't have a concept of demands in Silverlight, that enforcement mechanism isn't appropriate, and instead we just throw a MethodAccessException if transparent code tries to violate one of these rules.&lt;/p&gt; &lt;p&gt;The last rule is the most interesting in the group.&amp;nbsp; If transparent code attempts to directly call critical code, a MethodAccessException will be thrown.&amp;nbsp; However, most of the interesting system services are required to be implemented in critical code (for instance, in order to access the file system, we need to P/Invoke to&amp;nbsp;the&amp;nbsp;operating system's&amp;nbsp;file IO APIs.&amp;nbsp; Since calling native code is only available to critical code, any APIs which write to the file system must therefore be critical).&amp;nbsp; If that's the case, how does a Silverlight application access any of these interesting services?&lt;/p&gt; &lt;p&gt;This is accomplished by having an intermediate layer of safe critical code that act as gate keepers&amp;nbsp;for the critical methods, ensuring that it is safe for the transparent code to perform the operation that it is asking to do.&amp;nbsp; These safe critical APIs may do various checks before passing control to a critical API, including validating incoming parameters and ensuring that the application state is acceptable for this call to continue.&amp;nbsp; Since safe critical methods are in fact critical code, once they ensure that the caller is allowed to proceed they are allowed to invoke a critical method on the caller's behalf.&lt;/p&gt; &lt;p&gt;For example, earlier I mentioned that file IO must be implemented as critical code.&amp;nbsp;&amp;nbsp;Being able to&amp;nbsp;have some form of persistent storage&amp;nbsp;is&amp;nbsp;useful for an application however, so we'll need a&amp;nbsp;safe critical layer that&amp;nbsp;transparent code can call, and after ensuring that the call is&amp;nbsp;valid will pass on&amp;nbsp;requests to the critical&amp;nbsp;file IO layer.&amp;nbsp; In Silverlight, this&amp;nbsp;safe critical&amp;nbsp;layer is&amp;nbsp;IsolatedStorage.&amp;nbsp; &amp;nbsp;When a Silverlight application calls IsolatedStorage, the IsolatedStorage APIs will validate the request by making sure that the Silverlight application is requesting a valid file and is not over its quota.&amp;nbsp; Then it calls the critical file APIs to perform the actual work of reading or writing to disk.&lt;/p&gt; &lt;p&gt;You can think of this as being very similar to an operating system model.&amp;nbsp; In that analogy:&lt;/p&gt; &lt;table cellspacing="0" cellpadding="2" border="0" unselectable="on"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;i&gt;Operating System&lt;/i&gt;&lt;/td&gt; &lt;td&gt;&lt;i&gt;CoreCLR&lt;/i&gt;&lt;/td&gt; &lt;td&gt;&lt;i&gt;IsolatedStorage Example&lt;/i&gt;&lt;/td&gt; &lt;tr&gt; &lt;td valign="top"&gt;User mode code&lt;/td&gt; &lt;td valign="top"&gt;Transparent code&lt;/td&gt; &lt;td valign="top"&gt;Silverlight application&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;System call&lt;/td&gt; &lt;td valign="top"&gt;Safe critical API&lt;/td&gt; &lt;td valign="top"&gt;System.IO.IsolatedStorage&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt;Kernel code&lt;/td&gt; &lt;td valign="top"&gt;Critical API&lt;/td&gt; &lt;td valign="top"&gt;System.IO.FileStream&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&amp;nbsp;In the same way that applications running on Windows or the Mac cannot call directly into the kernel of the operating system without passing through a system call layer, Silverlight applications cannot directly call critical code without passing through a safe critical layer.&amp;nbsp; In the file IO example, a Silverlight application may not directly write to disk without first passing through the IsolatedStorage layer.&lt;/p&gt; &lt;p&gt;That's a lot of information -- but thankfully it can be summed up very easily:&amp;nbsp; The CoreCLR security model in Silverlight is that all Silverlight applications consist of entirely security transparent code, and this security transparent code may only call other transparent code or safe critical code.&lt;/p&gt; &lt;p&gt;Over the next few posts, we'll explore a few more details of the security model, such as how to tell what code is transparent and critical and some new rules regarding inheritance.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2504704" 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/Silverlight/default.aspx">Silverlight</category></item></channel></rss>