Addressing Other Security Issues

This final section discusses a number of security issues, encompassing most of the security infrastructure discussed in this chapter. For the most part you only need to be aware of the issues, but in some cases you need to take specific actions to ensure proper secure execution of your applications.

Link-Time Demand and Reflection

When you demand a security permission at link time using the SecurityAction.LinkDemand value for the security action, the demand applies only to early-bound code—that is, code that uses the compile time (or actually, the JIT compilation-time) linker. Malicious code can use reflection with late-binding invocation to avoid the link-time demand. To close this potential security hole, when a method is invoked using late binding the .NET reflection libraries reflect the method, looking for security permission attributes with link-time demands. If any such attributes are found, the reflection libraries programmatically demand these permissions, triggering a stack walk that verifies whether a caller has circumvented the demand for the permissions. As a result, code that works with a certain call chain that uses early binding may not work when one of the callers uses late binding. This is because the reflection libraries convert a link-time demand (which affects only the immediate caller) to a full stack walk that affects all callers. This behavior is yet another reason to avoid late-binding invocation.

Link-Time Demand and Inheritance ...

Get Programming .NET Components, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.