-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
If the original query is ``` insert into cats (name) values (' + var + '); ``` And the user input is ``` foo'||version()); ``` Then the query will be ```sql insert into cats_table (id, petname) values (null, 'foo'||version());'); ``` Which isn't a valid query. The second statement is `');` Clickhouse seems to ignore this because it does not allow multiple statements. It will still execute the first part so we need to detect this.
} | ||
} | ||
|
||
// If the query is invalid, we can't determine if it's an injection | ||
return false; | ||
} | ||
|
||
// Remove leading and trailing spaces from userinput : | ||
let trimmed_userinput = userinput.trim_matches(SPACE_CHAR); |
There was a problem hiding this comment.
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 dialect == 3 && has_multiple_statements(query, dialect) { | ||
// Clickhouse does not support multiple statements | ||
// The first statement will still be executed if the other statements are invalid | ||
// We'll assume the original query is valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I still don't fully understand, where do we make the assumption?
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
return true; | ||
} | ||
|
||
matches!(tokens.last(), Some(Token::SemiColon)) && has_semicolon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has_semicolon
is not necessary
} | ||
|
||
fn is_single_statement(tokens: &Vec<Token>) -> bool { | ||
let has_semicolon = tokens.iter().any(|x| matches!(x, Token::SemiColon)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Count them
If the original query is
And the user input is
Then the query will be
Which isn't a valid query. The second statement is
');
Clickhouse seems to ignore this because it does not allow multiple statements. It will still execute the first part so we need to detect this.