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.

Chapter 7: Building Secure Assemblies 161Exception ManagementDo not reveal implementation details about your application in exception messagesreturned to the client. This information can help malicious users plan attacks on yourapplication. To provide proper exception management:●●●●●Use structured exception h<strong>and</strong>ling.Do not log sensitive data.Do not reveal system or sensitive application information.Consider exception filter issues.Consider an exception management framework.Use Structured Exception H<strong>and</strong>lingMicrosoft Visual C# <strong>and</strong> Microsoft Visual Basic .NET provide structured exceptionh<strong>and</strong>ling constructs. C# provides the try / catch <strong>and</strong> finally construct. Protect code byplacing it inside try blocks <strong>and</strong> implement catch blocks to log <strong>and</strong> process exceptions.Also use the finally construct to ensure that critical system resources such asconnections are closed irrespective of whether an exception condition occurs.try{// Code that could throw an exception}catch (SomeExceptionType ex){// Code to h<strong>and</strong>le the exception <strong>and</strong> log details to aid// problem diagnosis}finally{// This code is always run, regardless of whether or not// an exception occurred. Place clean up code in finally// blocks to ensure that resources are closed <strong>and</strong>/or released.}Use structured exception h<strong>and</strong>ling instead of returning error codes from methodsbecause it is easy to forget to check a return code <strong>and</strong> as a result fail to an insecuremode.

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

Saved successfully!

Ooh no, something went wrong!