Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion vulns/sql_injection/sql_injection_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def sql_injection_login_api(request, app):
password = form.get('password')
password_hash = _hash_password(password)

sql = f"SELECT * FROM users WHERE username='{username}' AND password='{password_hash}'"
sql = f"SELECT * FROM users WHERE username='{username}' AND password='{password_hash}'"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semgrep identified an issue in your code:
Detected user input used to manually construct a SQL string. This is usually bad practice because manual construction could accidentally result in a SQL injection. An attacker could use a SQL injection to steal or modify contents of the database. Instead, use a parameterized query which is available by default in most database engines. Alternatively, consider using the Django object-relational mappers (ORM) instead of raw SQL queries.

Dataflow graph
flowchart LR
    classDef invis fill:white, stroke: none
    classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none

    subgraph File0["<b>vulns/sql_injection/sql_injection_login.py</b>"]
        direction LR
        %% Source

        subgraph Source
            direction LR

            v0["<a href=https://github.com/Buildkite007/bad-python-app/blob/48afdaa451e81f9c9e7c8ad928f108d862e4395d/vulns/sql_injection/sql_injection_login.py#L14 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 14] request.form</a>"]
        end
        %% Intermediate

        subgraph Traces0[Traces]
            direction TB

            v2["<a href=https://github.com/Buildkite007/bad-python-app/blob/48afdaa451e81f9c9e7c8ad928f108d862e4395d/vulns/sql_injection/sql_injection_login.py#L14 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 14] form</a>"]

            v3["<a href=https://github.com/Buildkite007/bad-python-app/blob/48afdaa451e81f9c9e7c8ad928f108d862e4395d/vulns/sql_injection/sql_injection_login.py#L16 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 16] username</a>"]
        end
            v2 --> v3
        %% Sink

        subgraph Sink
            direction LR

            v1["<a href=https://github.com/Buildkite007/bad-python-app/blob/48afdaa451e81f9c9e7c8ad928f108d862e4395d/vulns/sql_injection/sql_injection_login.py#L21 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 21] f&quot;SELECT * FROM users WHERE username=&apos;{username}&apos; AND password=&apos;{password_hash}&apos;&quot;</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    Traces0:::invis
    File0:::invis

    %% Connections

    Source --> Traces0
    Traces0 --> Sink


Loading

To resolve this comment:

🔧 No guidance has been designated for this issue. Fix according to your organization's approved methods.

💬 Ignore this finding

Reply with Semgrep commands to ignore this finding.

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by tainted-sql-string.

You can view more details about this finding in the Semgrep AppSec Platform.

flask.render_template_string(username)

Expand All @@ -42,4 +43,4 @@ def sql_injection_login_api(request, app):

def _hash_password(password):
md5_pass = hashlib.md5(password.encode('utf-8')).hexdigest()
return md5_pass
return md5_pass