Code Review

The Code Review practice includes use of code review tools, development of tailored rules, customized profiles for tool use by different roles (for example, developers versus auditors), manual analysis, and tracking/measuring results.

Code Review Level 1

[CR1.2: 82] Have the SSG perform ad hoc review.

The SSG performs an ad hoc code review for high-risk applications in an opportunistic fashion, such as by following up the design review for high-risk applications with a code review. At higher maturity levels, this informal targeting is replaced with a systematic approach. SSG review could involve the use of specific tools and services, or it might be manual, but it has to be proactive. When new technologies pop up, new approaches to code review might become necessary.

[CR1.4: 76] Use automated tools along with manual review.

Incorporate static analysis into the code review process to make code review more efficient and more consistent. The automation doesn’t replace human judgment, but it does bring definition to the review process and security expertise to reviewers who are not security experts. Note that a specific tool might not cover an entire portfolio, especially when new languages are involved, but that’s no excuse not to review the code. A firm may use an external service vendor as part of a formal code review process for software security, and this service should be explicitly connected to a larger SSDL applied during software development, not just used to “check the security box” on the path to deployment.

[CR1.5: 40] Make code review mandatory for all projects.

Code review is a mandatory release gate for all projects under the SSG’s purview. Lack of code review or unacceptable results will stop a release or slow it down. While all projects must undergo code review, the review process might be different for different kinds of projects. The review for low-risk projects might rely more heavily on automation, for example, whereas high-risk projects might have no upper bound on the amount of time spent by reviewers. In most cases, a code review gate with a minimum acceptable standard forces projects that don’t pass to be fixed and reevaluated before they ship. A code review tool with nearly all the rules turned off so it can run at CI/CD automation speeds won’t provide sufficient defect coverage.

[CR1.6: 44] Use centralized reporting to close the knowledge loop and drive training.

The bugs found during code review are tracked in a centralized repository that makes it possible to do both summary and trend reporting for the organization. Code review information can be incorporated into a CISOlevel dashboard that includes feeds from other parts of the security organization (e.g., penetration tests, security testing, black-box testing, and white-box testing). The SSG can also use the reports to demonstrate progress and drive the training curriculum (see [SM2.5 Identify metrics and use them to drive budgets]). Individual bugs make excellent training examples.

Code Review Level 2

[CR2.5: 28] Assign tool mentors.

Mentors are available to show developers how to get the most out of code review tools. If the SSG is most skilled with the tools, it could use office hours to help developers establish the right configuration or get started interpreting results. Alternatively, someone from the SSG might work with a development team for the duration of the first review they perform. Centralized use of a tool can be distributed into the development organization over time through the use of tool mentors. Providing installation instructions and URLs to centralized tools does not count as mentoring.

[CR2.6: 20] Use automated tools with tailored rules.

Customize static analysis to improve efficiency and reduce false positives. Use custom rules to find errors specific to the organization’s coding standards or custom middleware. Turn off checks that aren’t relevant. The same group that provides tool mentoring will likely spearhead the customization. Tailored rules can be explicitly tied to proper usage of technology stacks in a positive sense and avoidance of errors commonly encountered in a firm’s code base in a negative sense.

[CR2.7: 25] Use a top N bugs list (real data preferred).

The SSG maintains a list of the most important kinds of bugs that it wants to eliminate from the organization’s code and uses it to drive change. It’s okay to start with a generic list pulled from public sources, but a list is much more valuable if it’s specific to the organization and built from real data gathered from code review, testing, and actual incidents. The SSG can periodically update the list and publish a “most wanted” report. (For another way to use the list, see [T1.6 Create and use material specific to company history]). Some firms use multiple tools and real code base data to build top N lists, not constraining themselves to a particular service or tool. One potential pitfall with a top N list is the problem of “looking for your keys only under the street light”—that is, it only includes known problems. For example, the OWASP Top 10 list rarely reflects an organization’s bug priorities. Simply sorting the day’s bug data by number of occurrences doesn’t produce a satisfactory top N list because these data change so often. A top N bugs list should be used to kill bugs.



Code Review Level 3

[CR3.2: 4] Build a factory.

Combine assessment results so that multiple analysis techniques feed into one reporting and remediation process. The SSG might write scripts to invoke multiple detection techniques automatically and combine the results into a format that can be consumed by a single downstream review and reporting solution. Analysis engines may combine static and dynamic analysis, and different review streams, such as mobile versus standard approaches, can be unified with a factory. The tricky part of this activity is normalizing vulnerability information from disparate sources that use conflicting terminology. In some cases, using a standardized taxonomy (perhaps a CWE-like approach) can help with normalization. Combining multiple sources helps drive better-informed risk mitigation decisions.

[CR3.3: 1] Build a capability for eradicating specific bugs from the entire codebase.

When a new kind of bug is found, the SSG writes rules to find it and uses the rules to identify all occurrences of the new bug throughout the entire codebase. It’s possible to eradicate the bug type entirely without waiting for every project to reach the code review portion of its lifecycle. A firm with only a handful of software applications will have an easier time with this activity than firms with a large number of large applications.

[CR3.4: 4] Automate malicious code detection.

Automated code review is used to identify dangerous code written by malicious in-house developers or outsource providers. Examples of malicious code that could be targeted include back doors, logic bombs, time bombs, nefarious communication channels, obfuscated program logic, and dynamic code injection. Although out-of-the-box automation might identify some generic malicious-looking constructs, custom rules for static analysis tools used to codify acceptable and unacceptable code patterns in the organization’s codebase will quickly become a necessity. Manual code review for malicious code is a good start, but it is insufficient to complete this activity.

[CR3.5: 3] Enforce coding standards.

A violation of the organization’s secure coding standards is sufficient grounds for rejecting a piece of code. Code review is objective—it shouldn’t devolve into a debate about whether or not bad code is exploitable. The enforced portion of the standard could start out being as simple as a list of banned functions. In some cases, coding standards for developers are published specific to technology stacks (for example, guidelines for C++, Spring, or Swift) and then enforced during the code review process or directly in the IDE. Standards can be positive (“do it this way”) or negative (“do not use this API”).