-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Keep privacy of users censoring credentials
When debugging is turned on, anything resembling an email address or the password in the LOGIN of the IMAP client is fully censored.
- Loading branch information
Showing
5 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"regexp" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
emailRegexp = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`) | ||
detectPasswordInLOGIN = regexp.MustCompile(`^(.*LOGIN\s+\S+\s+)"[^"]+"(.*)$`) | ||
) | ||
|
||
func censorCredentials(in io.Reader, out io.Writer) { | ||
scanner := bufio.NewScanner(in) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
censoredLine := censorEmailAddress(censorPasswordInLogin(line)) | ||
|
||
_, err := out.Write([]byte(censoredLine + "\n")) | ||
|
||
if err != nil { | ||
logrus.Errorf("unable to write censored lines: %v", err) | ||
} | ||
} | ||
} | ||
|
||
func censorPasswordInLogin(in string) string { | ||
matches := detectPasswordInLOGIN.FindStringSubmatch(in) | ||
|
||
if len(matches) == 0 { | ||
return in | ||
} | ||
|
||
return matches[1] + `"****"` + matches[2] | ||
} | ||
|
||
func censorEmailAddress(in string) string { | ||
matches := emailRegexp.FindAllString(in, -1) | ||
|
||
if len(matches) == 0 { | ||
return in | ||
} | ||
|
||
return emailRegexp.ReplaceAllString(in, "*******@*****.***") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters