MSDN Library

Protected Objects

Some objects hold security state in themselves. These objects should not be passed to untrusted code, which would then acquire security authorization beyond its own permissions.

One example is creating a FileStream object. The FileIOPermission is demanded at the time of creation and, if it succeeds, the file object is returned. However, if this object reference is passed to code without file permissions, the object will be able to read and write to this particular file.

The simplest defense for such an object is to demand the same FileIOPermission of any code that seeks to get the object reference through a public API element.

© 2016 Microsoft