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

Create successful ePaper yourself

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

Chapter 21: Code Review 619●Does your class validate data streams?If your code includes a method that receives a serialized data stream, check thatevery field is validated as it is read from the data stream.Do You Use Reflection?To help locate code that uses reflection, search for “System.Reflection”— this is thenamespace that contains the reflection types. If you do use reflection, review thefollowing questions to help identify potential vulnerabilities:● Do you dynamically load assemblies?If your code loads assemblies to create object instances <strong>and</strong> invoke types, does itobtain the assembly or type name from input data? If so, check that the code isprotected with a permission dem<strong>and</strong> to ensure all calling code is authorized. Forexample, use a StrongNameIdentity permission dem<strong>and</strong> or dem<strong>and</strong> full trust.●●Do you create code dynamically at runtime?If your assemblies dynamically generate code to perform operations for a caller,check that the caller is in no way able to influence the code that is generated. Forexample, does your code generation rely on caller-supplied input parameters?This should be avoided, or if it is absolutely necessary, make sure that the input isvalidated <strong>and</strong> that it cannot be used to adversely affect code generation.Do you use reflection on other types?If so, check that only trusted code can call you. Use code access securitypermission dem<strong>and</strong>s to authorize calling code.Do You H<strong>and</strong>le Exceptions?Secure exception h<strong>and</strong>ling is required for robust code, to ensure that sufficientexception details are logged to aid problem diagnosis <strong>and</strong> to help prevent internalsystem details being revealed to the client. Review the following questions to helpidentify potential exception h<strong>and</strong>ling vulnerabilities:● Do you fail early?Check that your code fails early to avoid unnecessary processing that consumesresources. If your code does fail, check that the resulting error does not allow auser to bypass security checks to run privileged code.● How do you h<strong>and</strong>le exceptions?Avoid revealing system or application details to the caller. For example, do notreturn a call stack to the end user. Wrap resource access or operations that couldgenerate exceptions with try/catch blocks. Only h<strong>and</strong>le the exceptions you knowhow to h<strong>and</strong>le <strong>and</strong> avoid wrapping specific exceptions with generic wrappers.

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

Saved successfully!

Ooh no, something went wrong!