OWASP Code Review Guide V1.1 2008
Total Page:16
File Type:pdf, Size:1020Kb
OWASP CODE REVIEW GUIDE 2008 V1.1 © 2002-2008 OWASP Foundation This document is licensed under the Creative Commons Attribution Share Alike 3.0 license. You must attribute your version to the OWASP Code Review Guide or the OWASP Foundation. OWASP Code Review Guide V1.1 2008 Table of Contents Foreword by Jeff Williams, OWASP Chair .................................................................................................................................... 4 Welcome to the OWASP Code Review Guide 1.1 ........................................................................................................................ 6 About The Open Web Application Security Project ..................................................................................................................... 8 Code Review Guide History ....................................................................................................................................................... 10 Introduction ............................................................................................................................................................................... 11 Preparation ................................................................................................................................................................................ 13 Security Code Review in the SDLC ............................................................................................................................................. 16 Security Code Review Coverage ................................................................................................................................................ 18 Application Threat Modeling ..................................................................................................................................................... 22 Code Review Metrics ................................................................................................................................................................. 45 Crawling code ............................................................................................................................................................................ 49 Searching for code in J2EE/Java ................................................................................................................................................. 56 Searching for code in Classic ASP ............................................................................................................................................... 60 Javascript / Web 2.0 keywords and pointers ............................................................................................................................. 63 Code review and PCI DSS ........................................................................................................................................................... 64 Reviewing by technical control: Authentication ........................................................................................................................ 66 Reviewing by technical control: Authorization .......................................................................................................................... 73 Reviewing by technical control: Session Management ............................................................................................................. 78 Reviewing by technical control: Input Validation ...................................................................................................................... 81 Reviewing by technical control: Error Handling......................................................................................................................... 83 Reviewing by technical control Secure application deployment ............................................................................................... 95 Reviewing by technical control Cryptographic controls ............................................................................................................ 99 Reviewing Code for Buffer Overruns and Overflows ............................................................................................................... 112 2 OWASP Code Review Guide V1.1 2008 Reviewing Code for OS Injection ............................................................................................................................................. 117 Reviewing Code for SQL Injection ............................................................................................................................................ 121 Reviewing Code for Data Validation ........................................................................................................................................ 127 Reviewing Code for Cross-site scripting ................................................................................................................................... 141 Reviewing code for Cross-Site Request Forgery issues ............................................................................................................ 148 Reviewing Code for Logging Issues .......................................................................................................................................... 153 Reviewing Code for Session Integrity issues ............................................................................................................................ 158 Reviewing Code for Race Conditions ....................................................................................................................................... 161 Additional security considerations: ......................................................................................................................................... 163 Java gotchas ............................................................................................................................................................................. 164 Java leading security practice .................................................................................................................................................. 170 Classic ASP Design Mistakes .................................................................................................................................................... 173 PHP Security Leading Practice ................................................................................................................................................. 177 Strings and Integers ................................................................................................................................................................. 180 Reviewing MySQL Security ...................................................................................................................................................... 184 Reviewing Flash Applications ................................................................................................................................................... 187 Reviewing Web services .......................................................................................................................................................... 190 How to write an application code review finding .................................................................................................................... 192 Automated Code revieW ......................................................................................................................................................... 195 Tool Deployment Model .......................................................................................................................................................... 196 The Owasp Orizon Framework ................................................................................................................................................ 197 The Owasp Code Review Top 9 ................................................................................................................................................ 208 Guide References ..................................................................................................................................................................... 216 3 OWASP Code Review Guide V1.1 2008 FOREWORD BY JEFF WILLIAMS, OWASP CHAIR Many organizations have realized that their code is not as secure as they may have thought. Now they're starting the difficult work of verifying the security of their applications. There are four basic techniques for analyzing the security of a software application - automated scanning, manual penetration testing, static analysis, and manual code review. This OWASP Guide is focused on the last of these techniques. Of course, all of these techniques have their strengths, weaknesses, sweet spots, and blind spots. Arguments about which technique is the best are like arguing whether a hammer or saw is more valuable when building a house. If you try to build a house with just a hammer, you'll do a terrible job. More important than the tool is probably the person holding the hammer anyway. The OWASP guides are intended to teach you how to use these techniques. But the fact that they are separate shouldn't be an indicator that they should be used alone. The Development Guide shows your project how to architect and build a secure application,