github / github/codeql

Python SQL Injection not being detected for CWE-089

未關閉
#16,353 4 則留言 0 個 reaction 已指派 1 人 已被 @tausbn 認領 在 GitHub 檢視
Python question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。