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
Move back
  • Loading branch information
hansott committed Jan 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f041dec46920da1574e967dc9a2b40f6c3376918
16 changes: 8 additions & 8 deletions src/sql_injection/detect_sql_injection.rs
Original file line number Diff line number Diff line change
@@ -19,14 +19,6 @@ pub fn detect_sql_injection_str(query: &str, userinput: &str, dialect: i32) -> b
return false;
}

// Remove leading and trailing spaces from user input
let trimmed_userinput = userinput.trim_matches(SPACE_CHAR);

if trimmed_userinput.len() <= 1 {
// If the trimmed user input is one character or empty, no injection took place.
return false;
}

// Tokenize query :
let tokens = tokenize_with_fallback(query, dialect);
if tokens.len() <= 0 {
@@ -48,6 +40,14 @@ pub fn detect_sql_injection_str(query: &str, userinput: &str, dialect: i32) -> b
return false;
}

// Remove leading and trailing spaces from user input
let trimmed_userinput = userinput.trim_matches(SPACE_CHAR);
Copy link
Member

Choose a reason for hiding this comment

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

trimmed userinput is now only used for length check? everything else moved to replace_user_input_with_safe_str


if trimmed_userinput.len() <= 1 {
// If the trimmed user input is one character or empty, no injection took place.
return false;
}

// Replace user input with string of equal length and tokenize again :
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);