gitlab.com/gitlab-org/labkit@v1.21.0/mask/matchers.go (about)

     1  package mask
     2  
     3  import (
     4  	"bytes"
     5  	"regexp"
     6  )
     7  
     8  var parameterMatches = []string{
     9  	`token$`,
    10  	`password`,
    11  	`secret`,
    12  	`key$`,
    13  	`signature`,
    14  	`^authorization$`,
    15  	`^certificate$`,
    16  	`^encrypted_key$`,
    17  	`^hook$`,
    18  	`^import_url$`,
    19  	`^elasticsearch_url$`,
    20  	`^otp_attempt$`,
    21  	`^sentry_dsn$`,
    22  	`^trace$`,
    23  	`^variables$`,
    24  	`^content$`,
    25  	`^body$`,
    26  	`^description$`,
    27  	`^note$`,
    28  	`^text$`,
    29  	`^title$`,
    30  	`^jwt$`,
    31  	`^redirect$`,
    32  }
    33  
    34  var headerMatches = []string{
    35  	`token$`,
    36  	`password`,
    37  	`secret`,
    38  	`key$`,
    39  	`signature`,
    40  	`^authorization$`,
    41  }
    42  
    43  // parameterMatcher is precompiled for performance reasons. Keep in mind that
    44  // `IsSensitiveParam`, `IsSensitiveHeader` and `URL` may be used in tight loops
    45  // which may be sensitive to performance degradations.
    46  var parameterMatcher = compileRegexpFromStrings(parameterMatches)
    47  
    48  // headerMatcher is precompiled for performance reasons, same as `parameterMatcher`.
    49  var headerMatcher = compileRegexpFromStrings(headerMatches)
    50  
    51  func compileRegexpFromStrings(paramNames []string) *regexp.Regexp {
    52  	var buffer bytes.Buffer
    53  	buffer.WriteString("(?i)")
    54  	for i, v := range paramNames {
    55  		if i > 0 {
    56  			buffer.WriteString("|")
    57  		}
    58  		buffer.WriteString(v)
    59  	}
    60  
    61  	return regexp.MustCompile(buffer.String())
    62  }