-
Notifications
You must be signed in to change notification settings - Fork 129
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
Add patterns functionality to whitelist #231
Add patterns functionality to whitelist #231
Conversation
if err != nil { | ||
return false, ErrPatternSyntaxError | ||
return false, ErrPatternCheckError |
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.
can we log the first error (err
) before returning ErrPatternCheckError to know what actually happened?
return matchDetected | ||
} | ||
|
||
// handle SELECT * FROM table %%WHERE%% pattern |
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.
better to format comment to godoc style // <methodName> some comment
t.Fatal(err) | ||
} | ||
acceptableQueries := []string{ | ||
"SELECT a, b, c FROM z WHERE a = 'someValue'", |
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.
can we test here queries that we use for star pattern too (https://github.com/cossacklabs/acra/blob/acracensor/acra-censor/acra-censor_test.go#L545) ? to test different where
clauses without star and columns
@@ -151,6 +151,9 @@ func handleSelectWherePattern(queryNodes, patternNodes []sqlparser.SQLNode) bool | |||
patternWhereDetected := false | |||
queryWhereDetected := false | |||
for index, patternNode := range patternNodes { | |||
if index >= len(queryNodes) { |
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.
maybe it makes sense to compare slice's lengths before loop?
if len(queryNodes) != len(patternNodes)
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.
Yes, actually we can perform this comparison before loop. But instead !=
it's better <
, because length of query is allowed to be equal or greater than pattern. The intention here was to prevent case when pattern is greater than query, and index out of range when use queryNodes[index]
i noticed in many places in code and logs we use |
ahh, |
if patternSelectExpr, ok := patternNodes[index+patternNodeOffset].(sqlparser.SelectExprs); ok && starFound(patternSelectExpr) { | ||
if _, ok := queryNodes[index+queryNodeOffset].(sqlparser.SelectExprs); ok { | ||
i := index | ||
for i < len(queryNodes) { |
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.
for ;i<len(queryNodes); i++
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.
Thanks
continue | ||
} | ||
if patternSelectExpr, ok := patternNodes[index+patternNodeOffset].(sqlparser.SelectExprs); ok && starFound(patternSelectExpr) { | ||
if _, ok := queryNodes[index+queryNodeOffset].(sqlparser.SelectExprs); ok { |
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.
what if not ok?
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.
thank you, @storojs72
this is huge feature!
No description provided.