11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

172 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sIf there are other paths to OpenAndWorkWithResource, <strong>and</strong> a separate thread callsthe method on the same object, it is possible for the second thread to omit the securitydem<strong>and</strong>, because it sees _callerOK=true, set by another thread.Consider Impersonation TokensWhen you create a new thread, it assumes the security context defined by the processlevel token. If a parent thread is impersonating while it creates a new thread, theimpersonation token is not passed to the new thread.Synchronize Static Class ConstructorsIf you use static class constructors, make sure they are not vulnerable to raceconditions. If, for example, they manipulate static state, add thread synchronizationto avoid potential vulnerabilities.Synchronize Dispose MethodsIf you develop non-synchronized Dispose implementations, the Dispose code maybe called more than once on separate threads. The following code sample shows anexample of this.void Dispose(){if (null != _theObject){ReleaseResources(_theObject);_theObject = null;}}In this example, it is possible for two threads to execute the code before the firstthread has set _theObject reference to null. Depending on the functionality providedby the ReleaseResources method, security vulnerabilities may occur.ReflectionWith reflection, you can dynamically load assemblies, discover information abouttypes, <strong>and</strong> execute code. You can also obtain a reference to an object <strong>and</strong> get or set itsprivate members. This has a number of security implications:● If your code uses reflection to reflect on other types, make sure that only trustedcode can call you. Use code access security permission dem<strong>and</strong>s to authorizecalling code. For more information, see Chapter 8, “Code Access <strong>Security</strong> inPractice.”

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

Saved successfully!

Ooh no, something went wrong!