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

test prepared statements with acra-censor #283

Merged
merged 5 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions acra-censor/acra-censor_implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@ func (acraCensor *AcraCensor) ReleaseAll() {

// HandleQuery processes every query through each handler.
func (acraCensor *AcraCensor) HandleQuery(query string) error {
if query == "" {
return nil
}
if len(acraCensor.handlers) == 0 {
// no handlers, AcraCensor won't work
return nil
}
normalizedQuery, queryWithHiddenValues, err := handlers.NormalizeAndRedactSQLQuery(query)
if err == handlers.ErrQuerySyntaxError && acraCensor.ignoreParseError {
acraCensor.logger.WithError(err).Infof("Parsing error on query (first %v symbols): %s", handlers.LogQueryLength, handlers.TrimStringToN(queryWithHiddenValues, handlers.LogQueryLength))

}
if err != nil {
// ignore parsing errors to forward it as is to acra-censor to allow filter it via QueryIgnore handler
normalizedQuery = query
}
for _, handler := range acraCensor.handlers {
// in QueryCapture Handler use only redacted queries
Expand Down
2 changes: 1 addition & 1 deletion acra-censor/handlers/blacklist_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (handler *BlacklistHandler) CheckQuery(query string) (bool, error) {
if len(handler.tables) != 0 {
parsedQuery, err := sqlparser.Parse(query)
if err != nil {
handler.logger.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCensorQueryParseError).WithError(ErrQuerySyntaxError).Errorln("Query has been blocked by blacklist [tables]. Parsing error")
handler.logger.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCensorQueryParseError).WithError(err).Errorln("Query has been blocked by blacklist [tables]. Parsing error")
return false, ErrQuerySyntaxError
}
switch parsedQuery := parsedQuery.(type) {
Expand Down
5 changes: 5 additions & 0 deletions acra-censor/handlers/queryignore_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package handlers

import "github.com/sirupsen/logrus"

// QueryIgnoreHandler allows to ignore any query
type QueryIgnoreHandler struct {
ignoredQueries map[string]bool
Expand Down Expand Up @@ -52,6 +54,9 @@ func (handler *QueryIgnoreHandler) AddQueries(queries []string) {
for _, query := range queries {
normalizedQuery, _, err := NormalizeAndRedactSQLQuery(query)
if err != nil {
logrus.WithError(err).Warningln("Can't add query to QueryIgnoreHandler in normalized form, added as is")
// add as is
handler.ignoredQueries[query] = true
continue
}
handler.ignoredQueries[normalizedQuery] = true
Expand Down
2 changes: 1 addition & 1 deletion acra-censor/handlers/whitelist_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (handler *WhitelistHandler) CheckQuery(query string) (bool, error) {
if len(handler.tables) != 0 {
parsedQuery, err := sqlparser.Parse(query)
if err != nil {
handler.logger.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCensorQueryParseError).WithError(ErrQuerySyntaxError).Errorln("Query has been blocked by whitelist [tables]. Parsing error")
handler.logger.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCensorQueryParseError).WithError(err).Errorln("Query has been blocked by whitelist [tables]. Parsing error")
return false, ErrQuerySyntaxError
}
switch parsedQuery := parsedQuery.(type) {
Expand Down
2 changes: 1 addition & 1 deletion decryptor/mysql/response_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (handler *MysqlHandler) ClientToDbConnector(errCh chan<- error) {
if err == handlers.ErrQuerySyntaxError {
clientLog.WithError(err).Infof("Parsing error on query: %s", queryWithHiddenValues)
} else {
clientLog.WithField("sql", queryWithHiddenValues).Debugln("Com_query")
clientLog.WithFields(logrus.Fields{"sql": queryWithHiddenValues, "command": cmd}).Debugln("Query command")
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/acra-censor_configs/acra-censor_blacklist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ handlers:
- SELECT CAST('test collated returns' AS CHAR CHARACTER SET utf8mb4) COLLATE utf8mb4_bin AS anon_1
- select 1
- SET AUTOCOMMIT = 0
- SET NAMES 'ascii' COLLATE 'ascii_general_ci'
- SET @@session.autocommit = OFF
#postgres
- BEGIN
- "SELECT t.oid, typarray\nFROM pg_type t JOIN pg_namespace ns\n ON typnamespace = ns.oid\nWHERE typname = 'hstore';\n"
Expand Down
2 changes: 2 additions & 0 deletions tests/acra-censor_configs/acra-censor_whitelist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ handlers:
- SELECT CAST('test collated returns' AS CHAR CHARACTER SET utf8mb4) COLLATE utf8mb4_bin AS anon_1
- select 1
- SET AUTOCOMMIT = 0
- SET NAMES 'ascii' COLLATE 'ascii_general_ci'
- SET @@session.autocommit = OFF
#postgres
- BEGIN
- "SELECT t.oid, typarray\nFROM pg_type t JOIN pg_namespace ns\n ON typnamespace = ns.oid\nWHERE typname = 'hstore';\n"
Expand Down
Loading