-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve detecting SQL injections in f-strings
This commit fixes detecting SQL injection in statements like: f"SELECT {column_name} FROM foo WHERE id = 1" f"INSERT INTO {table_name} VALUES (1)" f"UPDATE {table_name} SET id = 1" Before this change, the bandit was analyzing statements by parts, especially, in the case of: "SELECT {column_name} FROM foo WHERE id = 1" it was firstly checking "SELECT " for being an SQL statement and then " FROM foo WHERE id = 1". Neither of these parts match to defined regular expressions: r"(select\s.*from\s|" r"delete\s+from\s|" r"insert\s+into\s.*values\s|" r"update\s.*set\s)", Thus SQL injection was not detected. This commit makes bandit checking the whole SQL statement for matching the above regexps. However, since it uses ast.unparse it works only for python >= 3.9. Resolves: #916
- Loading branch information
Showing
3 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters