Python SQL Injection not being detected for CWE-089
- Dominant language
- CodeQL
- Stars
- 10.1k
- Forks
- 2.1k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 141
Description
In one of our projects we have identified a python SQL Injection Vulnerability for CWE-089 which doesn't appear to be being identified by the python SqlInjection.ql found here:
https://github.com/github/codeql/tree/main/python/ql/src/Security/CWE-089/SqlInjection.ql
Here is an example of the code which has vulnerabilities. Note that running **bandit -r -t B608 [script name]** does seem to work to identify the vulnerability, however, Code QL does not detect it.
def contract_sql_query(
contract_name: str,
col: list = ["*"],
cancel: bool = False,
risk_cat: str = "Aurizon",
current_month: bool = True,
):
if cancel:
table_name = "[interface.batch.yield].[YieldVisCancellation]"
else:
table_name = "[interface.batch.yield].[YieldVisAddition]"
current_month = int(current_month)
sql_string = (
"SELECT "
+ ", ".join(col)
+ f" FROM {table_name} WHERE ContractName = '{contract_name}' AND MonthCorrect = {current_month}"
)
sql_string += f" AND {risk_cat} = 1" if cancel else ""
sql_string += f" AND TimeStored = (SELECT MAX(TimeStored) FROM {table_name} WHERE ContractName = '{contract_name}')"
# print(sql_string)
return sql_string
Contributor guide
Assessment
This issue has not been assessed yet.