Skip to content

Detect misuse of psycopg2.sql.SQL composable#608

Open
wtkm11 wants to merge 12 commits into
PyCQA:mainfrom
wtkm11:psycopg2-sql-misuse
Open

Detect misuse of psycopg2.sql.SQL composable#608
wtkm11 wants to merge 12 commits into
PyCQA:mainfrom
wtkm11:psycopg2-sql-misuse

Conversation

@wtkm11
Copy link
Copy Markdown

@wtkm11 wtkm11 commented May 1, 2020

Add a plugin test to detect when something other than a string literal is passed to the constructor of the psycopg2.sql.SQL composable object.

See issue #412

Closes #412

Add a plugin test to detect when something other than a string
literal is passed to the constructor of the `psycopg2.sql.SQL`
composable object.

Resolves: PyCQA#412
@lukehinds lukehinds self-requested a review May 7, 2020 11:51
Comment thread README.rst Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread tests/functional/test_functional.py Outdated
Comment thread tests/functional/test_functional.py Outdated
Comment thread tests/functional/test_functional.py Outdated
@ericwb ericwb requested a review from sigmavirus24 as a code owner July 12, 2022 03:09
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread tests/functional/test_functional.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
Comment thread bandit/plugins/psycopg2_sql_injection.py
Comment thread bandit/plugins/psycopg2_sql_injection.py
Copy link
Copy Markdown
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

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

This solution is specific to psycopg2. I'd rather see a fix that can reuse the existing general SQL statements plugin to detect this particular case.

Comment thread bandit/plugins/psycopg2_sql_injection.py Outdated
@Changaco
Copy link
Copy Markdown

This plugin needs to be updated so that it works for psycopg3 in addition to psycopg2.

@ericwb The general plugin injection_sql.py looks for SQL fragments in string literals, whereas this one looks for specific calls with non-literal arguments. Can they and should they really be combined?

If consensus can't be reached on merging this plugin into bandit, then it should be released as a separate package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detecting misuse of the psycopg2.sql module

3 participants