@@ -76,57 +76,18 @@ type Results struct {
7676var i * indexer
7777var allFields []string = []string {"url" , "title" , "text" , "favicon" , "html" , "domain" , "added" }
7878var ErrSensitiveContent = errors .New ("document contains sensitive data" )
79- var sensitiveContentPatterns = []string {
80- // AWS Access Key
81- `AKIA[0-9A-Z]{16}` ,
82- // AWS Secret Key
83- `(?i)aws(.{0,20})?(secret)?(.{0,20})?['"][0-9a-zA-Z\/+]{40}['"]` ,
84- // Private Key
85- `-----BEGIN (RSA|EC|DSA)? PRIVATE KEY-----` ,
86- // Generic API Key
87- `(?i)(api|token|secret)[\s:=]+['"]?[a-z0-9]{32,}['"]?` ,
88- // Slack Token
89- `xox[baprs]-[0-9a-zA-Z]{10,48}` ,
90- // GitHub Token
91- `(ghp|gho|ghu|ghs|ghr)_[a-zA-Z0-9]{36}` ,
92- // Google API Key
93- `AIza[0-9A-Za-z\-_]{35}` ,
94- // Heroku API Key
95- `[hH][eE][rR][oO][kK][uU].{0,30}[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}` ,
96- // SSH Private Key
97- `-----BEGIN OPENSSH PRIVATE KEY-----` ,
98- // PGP Private Key
99- `-----BEGIN PGP PRIVATE KEY BLOCK-----` ,
100- // JWT Token
101- `eyJ[a-zA-Z0-9\/_-]{10,}\.[a-zA-Z0-9\/_-]{10,}\.[a-zA-Z0-9\/_-]{10,}` ,
102- // Credit Card Number - disabled, too many false positives - TODO refine regexp
103- //`\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})\b`,
104- // Basic Auth Credentials - disabled, too many false positives
105- //`(?i)basic [a-z0-9=:_\+\/-]{5,100}`,
106- // Docker Registry Auth
107- `"auth"\s*:\s*"[a-z0-9=:_\+\/-]{5,100}"` ,
108- // Azure Storage Key
109- `DefaultEndpointsProtocol=https;AccountName=[a-z0-9]{3,24};AccountKey=[a-z0-9\/+]{88}==` ,
110- // Google OAuth Token
111- `ya29\.[a-zA-Z0-9\-_]+` ,
112- // Facebook Access Token
113- `EAACEdEose0cBA[0-9A-Za-z]+` ,
114- // Twitter API Key
115- `(?i)twitter(.{0,20})?['"][0-9a-z]{35,44}['"]` ,
116- // Database Connection String
117- //`(?i)(jdbc:|mongodb:\/\/|postgresql:\/\/|mysql:\/\/).+:[^@]+@[a-z0-9\.-]+`,
118- }
11979var sensitiveContentRe * regexp.Regexp
12080
121- func init () {
122- sensitiveContentRe = regexp .MustCompile (fmt .Sprintf ("(%s)" , strings .Join (sensitiveContentPatterns , "|" )))
123- }
124-
125- func Init (idxPath string ) error {
126- idx , err := bleve .Open (idxPath )
81+ func Init (cfg * config.Config ) error {
82+ sp := make ([]string , 0 , len (cfg .SensitiveContentPatterns ))
83+ for _ , v := range cfg .SensitiveContentPatterns {
84+ sp = append (sp , v )
85+ }
86+ sensitiveContentRe = regexp .MustCompile (fmt .Sprintf ("(%s)" , strings .Join (sp , "|" )))
87+ idx , err := bleve .Open (cfg .IndexPath ())
12788 if err != nil {
12889 mapping := createMapping ()
129- idx , err = bleve .New (idxPath , mapping )
90+ idx , err = bleve .New (cfg . IndexPath () , mapping )
13091 if err != nil {
13192 return err
13293 }
0 commit comments