Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detecting SQL injections in f-strings #917

Merged
merged 2 commits into from
Feb 24, 2023

Commits on Feb 24, 2023

  1. 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.
    
    Resolves: PyCQA#916
    kfrydel committed Feb 24, 2023
    Configuration menu
    Copy the full SHA
    631a384 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d703ae7 View commit details
    Browse the repository at this point in the history