12.07.2015 Views

Secure Coding SwA Pocket Guide - Build Security In - US-CERT

Secure Coding SwA Pocket Guide - Build Security In - US-CERT

Secure Coding SwA Pocket Guide - Build Security In - US-CERT

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

o Filter and Sanitize Output and Callouts .............................. 16o Minimize Retention of State <strong>In</strong>formation ............................ 16o Do Not Allow Unauthorized Privilege Escalation ................ 17o Leverage <strong>Security</strong> through Obscurity Only as anAdditional Deterrence Measure ................................. 17o Use Strongly Typed Parameterized Queries ...................... 17o <strong>In</strong>corporate <strong>In</strong>terprocess Authentication ............................. 17o Leverage Attack Patterns ................................................... 18o Implement Encryption and Hashing ................................... 18o Protect Sensitive <strong>In</strong>formation ............................................. 19o Disable Debugging Tools Prior to Deployment .................. 19» <strong>Secure</strong> Memory and Cache Management ................................ 20o Limit Persistent Memory Caching ....................................... 20o Allocate Memory and Other Resources Carefully .............. 21» <strong>Secure</strong> Error and Exception Handling ....................................... 21o <strong>In</strong>tegrate Anomaly Awareness ........................................... 23o <strong>In</strong>corporate Runtime Error Checking and SafetyEnforcement .............................................................. 23o Use Event Monitors ............................................................ 23o Fail <strong>Secure</strong>ly ....................................................................... 23» What to Avoid ............................................................................ 24o Do Not Use Deprecated or <strong>In</strong>secure Functions .................. 24o Do Not Use Filenames in an Improper Manner .................. 25» Questions to Ask Software Developers .................................... 25» Conclusion ................................................................................ 27Preparing to Write <strong>Secure</strong> CodeBefore writing code, the development team must first determine how they plan to accomplish their assigned task. It is importantto remember that writing secure code needs the support of secure requirements, architecture, and design. To find more on thesetopics, reference “Requirements and Analysis for <strong>Secure</strong> Software” and “Architecture and Design Considerations for <strong>Secure</strong>Software.” Both of these documents are part of the <strong>SwA</strong> <strong>Pocket</strong> <strong>Guide</strong> Series.Choose a Language with <strong>Security</strong> in MindThe choice of a programming language is an important factor in software security. <strong>In</strong> many cases, legacy code, the available skillsets, or customer requirements, including the environment, may restrict programming language options. When evaluating andselecting the programming language(s), you should ask these key security-relevant questions:» Which languages have your programmers used? Programmers are likely to make more errors when developing inlanguages they have little experience using.» Does the language help or inhibit the development of secure code?» What secure coding standards are available for the language (if any)?» What security issues exist in the language? What mitigation strategies exist? How effective are they?Weighing language choices: <strong>In</strong> many situations, the choice of language can directly affect the system’s security. The mostprominent example is the effect of array bounds checking, which Java provides but C does not. Although most modern Ccompilers support runtime bounds checking, this feature (or lack thereof) has left a legacy of buffer-overflow-based vulnerabilitiesin web servers, operating systems, and applications. Java is without these specific vulnerabilities, but may not be appropriate forSoftware Assurance <strong>Pocket</strong> <strong>Guide</strong> Series:Development Volume VI – Version 2.0, , May 18, 2012<strong>Secure</strong> <strong>Coding</strong>4

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

Saved successfully!

Ooh no, something went wrong!