07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

246<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

In general, threats can be classified as spoofing identity, tampering with data, repudiation,<br />

information disclosure, denial of service, and elevation of privileges. To<br />

learn more about these threats, see Threat Modeling Web Applications on MSDN in the<br />

Microsoft patterns & practices Developer Center.<br />

General Security <strong>Test</strong>s<br />

All the application blocks are required to request code access security permissions for<br />

the appropriate assemblies. Code access security allows code to be trusted to varying<br />

degrees depending on where the code originates and on other aspects of the code’s<br />

identity.<br />

<strong>Test</strong> Case<br />

The application blocks use reflection in multiple places to create domain objects. The<br />

test case was to review the code in the AssemblyInfo file to determine whether the<br />

application block requests permission to use reflection. This permission is necessary<br />

for the application block to run in low-trust environments. (The AssemblyInfo file<br />

contains information such as attributes, files, resources, types, versioning information,<br />

and signing information for modifying an assembly’s metadata.)<br />

Problem<br />

The test case revealed that the ReflectionPermission class that controls access to<br />

the metadata was not defined in the AssemblyInfo file. This class defines the set of<br />

permissions that are required for application block assemblies to run in low-trust<br />

environments.<br />

When the application block runs in a low-trust environment, the system administrator<br />

must explicitly grant those permissions that allow the application block to run.<br />

The explicit permission to use reflection allows the ObjectBuilder subsystem to use<br />

reflection and access private class members and metadata.<br />

Solution<br />

The solution was to add a ReflectionPermission object with the necessary permissions<br />

to the AssemblyInfo file. The following code shows how to do this.<br />

[assembly: ReflectionPermission(SecurityAction.RequestMinimum, MemberAccess =<br />

true)]<br />

Verification<br />

Examining the AssemblyInfo file after applying the preceding code showed that it<br />

included a ReflectionPermission object.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!