Skip to content

Commit

Permalink
Move back
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Jan 20, 2025
1 parent e64ac24 commit f041dec
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sql_injection/detect_sql_injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

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);
Expand Down

0 comments on commit f041dec

Please sign in to comment.