Skip to content

Commit

Permalink
Fix lark DLP error for messages containing emails (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
nt0xa authored Feb 15, 2023
1 parent 84d74b0 commit 47e1851
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/modules/lark/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package lark
import (
"bytes"
"fmt"
"regexp"
"strings"
"unicode/utf8"

larkcard "github.com/larksuite/oapi-sdk-go/v3/card"
Expand All @@ -16,6 +18,7 @@ var (
messageBodyTemplate = tpl(`
{{ .Data }}
`)
emailRegexp = regexp.MustCompile("(?i)([A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,24})")
)

func (lrk *Lark) Notify(u *models.User, p *models.Payload, e *models.Event) error {
Expand All @@ -41,12 +44,18 @@ func (lrk *Lark) Notify(u *models.User, p *models.Payload, e *models.Event) erro
return fmt.Errorf("message header render error: %w", err)
}

data := string(e.RW)

for _, m := range emailRegexp.FindAllString(data, -1) {
data = strings.ReplaceAll(data, m, strings.Replace(m, "@", "(AT)", 1))
}

bodyData := struct {
Data string
Protocol string
Meta map[string]interface{}
}{
string(e.RW),
data,
e.Protocol.String(),
e.Meta,
}
Expand Down

0 comments on commit 47e1851

Please sign in to comment.