PyCQA / PyCQA/bandit

SQL Injection flagged when concatenating strings

Open
#727 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
835
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Describe the bug

It seems that when concatenating strings in a cur.execute() call, it flags up sql injection possibilities, even though all the string arguments are being passed into the execute() call. So, this looks safe to me.

Reproduction steps

See the # noqa: S608 lines in this file: https://github.com/aio-libs/aiohttp-session/blob/master/examples/postgres_storage.py#L68-L72

Expected behavior

No errors from concatenating string literals.

Bandit version

1.7.0 (Default)

Python version

3.7

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the S608 warnings reproduced at examples/postgres_storage.py lines 68-72 and inspect how the cur.execute() call with concatenated string literals is classified. Confirm the change by rerunning Bandit on that example and verifying those lines no longer report SQL injection while unsafe cases remain detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sql
Domain
security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.