-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FALSE NEGATIVE] "S608 Possible SQL injection" #12044
Comments
I just tried and the rule works as expected for triple-quoted f-strings. Any chance that you're using a line continuation token? |
Than you for a quick reply. Basically, it does not work, when |
The rule seems to be sensitive to certain indentation. Here are a few examples where the rule is not triggered but it should be: def sql():
foo = "foo"
f"""
SELECT {foo}
FROM bar
""" def sql():
foo = "foo"
f"""
SELECT
{foo}
FROM bar
""" def sql():
foo = "foo"
f"""
SELECT {foo}
FROM
bar
""" |
Yeah, I think the regex is not considering the case where there could be "one or more whitespace characters": ruff/crates/ruff_linter/src/rules/flake8_bandit/rules/hardcoded_sql_expression.rs Lines 13 to 16 in 7027344
So, the |
@dhruvmanila do you plan to PR or should we mark this as a good first issue? |
@dhruvmanila Shall I pick this issue? |
@DataEnggNerd For sure! Thanks |
Need help here. |
@MichaReiser I need a clarity here. As per my understanding based on the documentation here, every SQL statement which have string formatting should be reported with |
@DataEnggNerd Yes, the rule ideally flags all SQL statements with as few false positives as possible. The change mentioned in this issue is that we should re-visit Ruff's regex to allow optional whitespace between the different keywords. It's a non-goal to change how the rule detects SQL expressions significantly. As reference, the Regex used by bandit |
@MichaReiser Yes, I have started with modifying the regex first and faced some problem with the regex. @dhruvmanila mentioned there is something missing beyond the regex(you can refer closer PR linked to the issue), so i started looking into this. Apologies it is making more time to implement at code. |
Playing with it in Regex101, the following should work: |
@MichaReiser With the changes you suggested, along with the regex from bandit, unfortunately both are not helping. |
Hello.
I'm very exited to migrate our codebase to ruff. However, while doing so I've noticed, that rule
S608
works different from the correspondingB608
.It only triggers if
SELECT
is on the same line.So
SELECT * FROM {foo}.table
is an error andIs not.
Kind regards, Mikhail
The text was updated successfully, but these errors were encountered: