@@ -676,18 +676,42 @@ func validSHA256(value string) bool {
676676}
677677
678678var (
679- reportSensitiveAssignment = regexp .MustCompile (
679+ reportSensitiveAssignment * regexp.Regexp
680+ reportBearerValue * regexp.Regexp
681+ reportOpenAIKey * regexp.Regexp
682+ reportJWT * regexp.Regexp
683+ reportPrivateKey * regexp.Regexp
684+ )
685+
686+ func init () {
687+ var compileErr error
688+ reportSensitiveAssignment , compileErr = regexp .Compile (
680689 `(?i)\b(authorization|api[ _-]?key|access[ _-]?token|refresh[ _-]?token|token|password|` +
681690 `client[ _-]?secret|secret|credential|credentials|private[ _-]?key|cookie)` +
682691 `(\s*[:=]\s*)[^\r\n,;|]+` ,
683692 )
684- reportBearerValue = regexp .MustCompile (`(?i)\bbearer\s+[^\s,;|]+` )
685- reportOpenAIKey = regexp .MustCompile (`\bsk-[A-Za-z0-9_-]{12,}\b` )
686- reportJWT = regexp .MustCompile (`\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b` )
687- reportPrivateKey = regexp .MustCompile (
693+ if compileErr != nil {
694+ panic (fmt .Errorf ("report sensitive assignment regex: %w" , compileErr ))
695+ }
696+ reportBearerValue , compileErr = regexp .Compile (`(?i)\bbearer\s+[^\s,;|]+` )
697+ if compileErr != nil {
698+ panic (fmt .Errorf ("report bearer value regex: %w" , compileErr ))
699+ }
700+ reportOpenAIKey , compileErr = regexp .Compile (`\bsk-[A-Za-z0-9_-]{12,}\b` )
701+ if compileErr != nil {
702+ panic (fmt .Errorf ("report OpenAI key regex: %w" , compileErr ))
703+ }
704+ reportJWT , compileErr = regexp .Compile (`\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\b` )
705+ if compileErr != nil {
706+ panic (fmt .Errorf ("report JWT regex: %w" , compileErr ))
707+ }
708+ reportPrivateKey , compileErr = regexp .Compile (
688709 `(?is)-----BEGIN [^-\r\n]*PRIVATE KEY-----.*?-----END [^-\r\n]*PRIVATE KEY-----` ,
689710 )
690- )
711+ if compileErr != nil {
712+ panic (fmt .Errorf ("report private key regex: %w" , compileErr ))
713+ }
714+ }
691715
692716func sanitizeReportText (value string ) string {
693717 value = reportPrivateKey .ReplaceAllString (value , redactedReportValue )
0 commit comments