-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevisionist.go
61 lines (46 loc) · 1.28 KB
/
revisionist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Please see discussion and usage instructions at
// https://dev.to/lbonanomi/sterilizing-bash-history-5455
//
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func curl_u(cmdline string)(after string) {
curl := regexp.MustCompile(`:\S+?\s+\b`)
after = curl.ReplaceAllString(cmdline, ":REDACTED ")
return
}
func https_creds(cmdline string)(after string) {
pattern := regexp.MustCompile(`https://(\S+?):\S+?@`)
after = pattern.ReplaceAllString(cmdline, "https://REDACTED:REDACTED@")
return
}
func header_creds(cmdline string)(after string) {
pattern := regexp.MustCompile(`(-H|--header)\s.*?(token|auth.*?)\s\S+?\s`)
after = pattern.ReplaceAllString(cmdline, "-H AUTH_HEADER_REDACTED ")
return
}
func main() {
reader := bufio.NewReader(os.Stdin)
for {
text, _ := reader.ReadString('\n')
if (text == "") {
break
}
newtext := ""
for _, word := range(strings.Fields(text)[1:]) { // Remove history line number
newtext = newtext + " " + word //
}
// Redact credential patterns
//
text = newtext
text = curl_u(text)
text = https_creds(text)
text = header_creds(text)
fmt.Println(text)
}
}