Static code analysis for detecting vulnerabilities
In this section, we will cover Bandit as a static code analyzer for detecting vulnerabilities. We'll do this by reviewing tools we can find in the Python ecosystem for static code analysis and then learning with the help of more detailed tools such as Bandit.
Introducing static code analysis
The objective of static analysis is to search the code and identify potential problems. This is an effective way to find code problems cheaply, compared to dynamic analysis, which involves code execution. However, running an effective static analysis requires overcoming a number of challenges.
For example, if we want to detect inputs that are not being validated when we are using the eval()
function or the subprocess
module, we could create our own parser that would detect specific rules to make sure that the different modules are used in a secure way.
The simplest form of static analysis would be to search through the code line...