
Interfaces and Link Demands
If a virtual method, property, or event with LinkDemand overrides a base class method, the base class method must also have the same LinkDemand for the overridden method in order to be effective. It is possible for malicious code to cast back to the base type and call the base class method. Also note that link demands can be added implicitly to assemblies that do not have the AllowPartiallyTrustedCallersAttribute assembly-level attribute.
It is a good practice to protect method implementations with link demands when interface methods also have link demands. Note the following about using link demands with interfaces:
The AllowPartiallyTrustedCallersAttribute attribute also applies to interfaces.
You can place link demands on interfaces to selectively protect certain interfaces from being used by partially trusted code, such as when using the AllowPartiallyTrustedCallersAttribute attribute.
If you have an interface defined in an assembly that does not contain the AllowPartiallyTrustedCallersAttribute attribute, you can implement that interface on a partially trusted class.
If you place a LinkDemand on a public method of a class that implements an interface method, the LinkDemand will not be enforced if you then cast to the interface and call the method. In this case, because you linked against the interface, only the LinkDemand on the interface is honored.
Review the following items for security issues:
Explicit link demands on interface methods. Make sure these link demands offer the expected protection. Determine whether malicious code can use a cast to get around the link demands as described previously.
Virtual methods with link demands applied.
Types and the interfaces they implement. These should use link demands consistently.