Udostępnij za pośrednictwem


Writing Secure Class Libraries

Programming errors in class libraries can expose security vulnerabilities because class libraries often access protected resources and unmanaged code. If you design class libraries, you need to understand code access security and be careful to secure your class library.

The following table describes the three main elements you need to consider when securing a class library.

Security element

Description

Security demand

Demands are applied at the class and method level as a mechanism for requiring that callers of your code have the permissions that you want them to have. Demands invoke a stack walk, in which all callers that directly or indirectly call your code are checked on the stack when your code is called. Demands are usually used in class libraries to help protect resources.

Security override

Overrides are applied on the class and method scope as a way to overrule certain security decisions made by the runtime. They are invoked when callers use your code. They are used to stop stack walks and limit the access of callers who have already been granted certain permissions.

Warning

Overrides can be dangerous and should be used with care.

Security optimization

A combination of demands and overrides can enhance performance during the interaction of your code and the security system.

See Also

Concepts

Security Demands

Overriding Security Checks

Declarative Security Used with Class and Member Scope

Security Optimizations

Other Resources

Code Access Security