Presentation on theme: "Reduce Security Risk in Your Development"— Presentation transcript:
1Reduce Security Risk in Your Development Part III: Secure Code ReviewTrent R. Hein, CCIE, CISSP, ISSMP, ISSAP, CSSA#SecureDev
2What We’ll Cover Today Recap of Secure Agile Development key topics How does secure code review fit in an Agile workflow?Code review documentationTips & Tricks#SecureDev
3How is Secure Agile Development Different? Traditional / WaterfallAgileSecurity TimingDistinct security-focused project phases, often at beginning and end of project.Security skills brought in from outside project, often disconnected from dev/test resources.Specific security testing phase, often at end of project.Every iteration considers security, but is not limited by it.Every team member is responsible for security. Security skills are embedded in the team.Hybrid security and functionality testing, throughout project.Security ResourcesSecurity Validation
4Secure Agile Development Guiding Principles Product value improves with security.Security is integral to the product, not an afterthought.Outside security resources (standards, threats, experts) provide background, not a cage.
5Our Secure Code Review Motto It’s not done until it’s provably secure.
7Why do we perform code review? Detect potential issues earlyMore effective than post-completion vulnerability testingOne layer of defense-in-depth“Inside the barn” viewpoint
8What code review is and isn’t A great opportunity for everyone to learnOne component of a complete secure lifecycle strategyDifficult to do consistently and wellEssential to modern-day development teamsCode review isn’t..FoolproofAn opportunity to discredit your co-workersPersonalA checkbox
9Secure code review high-level steps Review Agile Threat Map for the productReview the code for the security tests relevant to the user story/taskEnsure the code for the tests verify both the desired functionality, and the lack of undesired functionality (from a security standpoint)Execute test code against a known noop/broken moduleExecute test code against “good” moduleReview code repo diffs for possible areas of weakness
10Why write/execute tests first? Provable securityBuilds a lifetime of security (and value!) into the productEnsures future changes don’t negate security controlsRemoves significant subjectivity from secure review process
11Reviewers: Pair programming environment In pair programming environment, the pair members can review each other’s codeBest practice is one writes the tests, one writes the module codePairs should rotate frequently (not just for secure code review reasons!)
12Reviewers: Non-Pair Programmers In non-paired programming, another qualified coder on the team should act as the reviewerThis is a dedicated coder, not a dedicated security personIf possible, qualified coder should be selected randomlyFor extremely small teams, consider trading review services with an external team
13Tool-assisted review Lots of great tools out there! Keep in mind that automated tools catch only a small percentage of security vulnerabilitiesEven with a tool, you should be performing test-driven development, testing, and review by qualified coders
14Code review pitfallsDon’t perform secure code review outside of iterationsAs tempting as this may be, this forms a habit that security can be deferredIt’s not “done” until it’s secureMake sure reviewers are always “fresh”Frequent rotation of programming pairsRandomized selection of non-paired reviewersMake sure reviewers understand what they are looking atIf it’s just a checkbox, you’re missing the pointPerform reviews in contextReview Agile Threat Map before each review sessionDon’t code/excuse security workaroundsIf another layer/module is the problem, schedule a defect to fix it rather than accept “yet another hack”
15Documenting Code Review Every code review step/result should be visible to the teamTransparency is keyCode review documentation is important for training and retrospectivesNo documentation of review? Wasn’t reviewed.
17But.. But..How do we know what to look for when performing code review??
19Issues to watch for.. Authentication Require authentication for all pages/resources, except those specifically intended to be publicAll authentication controls must be enforced on a trusted system (e.g., The server)Establish and utilize standard, tested, authentication services whenever possibleAll administrative and account management functions must be at least as secure as the primary authentication mechanismIf your application manages a credential store, it should ensure that only cryptographically strong one-way salted hashes of passwords are stored and that the table/file that stores the passwords and keys is write-able only by the application. (Do not use the MD5 algorithm if it can be avoided)
20Issues to watch for.. Session Mgmt Use the server or framework’s session management controls. The application should only recognize these session identifiers as validSession identifier creation must always be done on a trusted system (e.g., The server)Session management controls should use well vetted algorithms that ensure sufficiently random session identifiersLogout functionality should fully terminate the associated session or connectionDisallow persistent logins and enforce periodic session terminations, even when the session is active. Especially for applications supporting rich network connections or connecting to critical systems. Termination times should support business requirements and the user should receive sufficient notification to mitigate negative impacts.
21Issues to watch for.. Data Protection Implement least privilege, restrict users to only the functionality, data and system information that is required to perform their tasks.Protect all cached or temporary copies of sensitive data stored on the server from unauthorized access and purge those temporary working files a soon as they are no longer required.Encrypt highly sensitive stored information, like authentication verification data, even on the server side. Always use well vetted algorithms.Protect server-side source-code from being downloaded by a user.Do not store passwords, connection strings or other sensitive information in clear text or in any non-cryptographically secure manner on the client side.
22Issues to watch for.. General Use tested and approved managed code rather than creating new unmanaged code for common tasks.Utilize task specific built-in APIs to conduct operating system tasks. Do not allow the application to issue commands directly to the Operating System, especially through the use of application initiated command shells.Protect shared variables and resources from inappropriate concurrent access.Explicitly initialize all your variables and other data stores, either during declaration or just before the first usage.Avoid calculation errors by understanding your programming language's underlying representation and how it interacts with numeric calculation.
23Issues to watch for..See these, and many more, great ideas of issues to watch for in the OWASP Secure Coding Practices Quick Reference Guide available at https://www.owasp.org/index.php/OWASP_Secure_Coding_Practices_-_Quick_Reference_Guide
24Quick recap Secure code review should be grounded in: 1. Agile Threat Map2. Test Driven DevelopmentCode reviewers always need to be FRESH and CAPABLEResults of code review should always be documented, even if “no issues”Need ideas what to look for? Use available resources such as OWASP for ideas.