Skip to content

Commit

Permalink
executor: remove sensitive information in slow-log and statement (#18107
Browse files Browse the repository at this point in the history
) (#18129)

Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
ti-srebot authored Jul 6, 2020
1 parent c7c017d commit 65406be
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,12 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
if costTime < threshold && level > zapcore.DebugLevel {
return
}
sql := FormatSQL(a.Text, sessVars.PreparedParams)
var sql stringutil.StringerFunc
if sensitiveStmt, ok := a.StmtNode.(ast.SensitiveStmtNode); ok {
sql = FormatSQL(sensitiveStmt.SecureText(), nil)
} else {
sql = FormatSQL(a.Text, sessVars.PreparedParams)
}

var tableIDs, indexNames string
if len(sessVars.StmtCtx.TableIDs) > 0 {
Expand Down Expand Up @@ -837,10 +842,13 @@ func (a *ExecStmt) SummaryStmt() {
if sessVars.User != nil {
userString = sessVars.User.Username
}

sql := a.Text
if sensitiveStmt, ok := a.StmtNode.(ast.SensitiveStmtNode); ok {
sql = sensitiveStmt.SecureText()
}
stmtsummary.StmtSummaryByDigestMap.AddStatement(&stmtsummary.StmtExecInfo{
SchemaName: strings.ToLower(sessVars.CurrentDB),
OriginalSQL: a.Text,
OriginalSQL: sql,
NormalizedSQL: normalizedSQL,
Digest: digest,
PrevSQL: prevSQL,
Expand Down

0 comments on commit 65406be

Please sign in to comment.