Skip to content
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

Handle ClickHouse queries with other statements being invalid #58

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Format query
hansott committed Jan 20, 2025
commit e063c962910a6d2baec413b23ca1af055e2368ee
8 changes: 2 additions & 6 deletions src/sql_injection/detect_sql_injection.rs
Original file line number Diff line number Diff line change
@@ -70,8 +70,7 @@ fn extra_statement_was_created_by_user_input(query: &str, userinput: &str, diale
}

let query_without_input = replace_user_input_with_safe_str(query, userinput);
let tokens_without_input =
tokenize_with_fallback(query_without_input.as_str(), dialect);
let tokens_without_input = tokenize_with_fallback(query_without_input.as_str(), dialect);

if tokens_without_input.len() <= 0 {
// Invalid query without user input
@@ -84,10 +83,7 @@ fn extra_statement_was_created_by_user_input(query: &str, userinput: &str, diale
fn is_single_statement(tokens: &Vec<Token>) -> bool {
let has_semicolon = tokens.iter().any(|x| matches!(x, Token::SemiColon));
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Count them


if !has_semicolon
|| (matches!(tokens.last(), Some(Token::SemiColon))
&& has_semicolon)
{
if !has_semicolon || (matches!(tokens.last(), Some(Token::SemiColon)) && has_semicolon) {
return true;
}