Skip to content

Commit c3ac8c3

Browse files
committed
fix: add ReDoS protection for excludedNamespaces regex validation
- Limit regex length to 512 characters to mitigate catastrophic backtracking (ReDoS) attacks via overly complex patterns - Improve error message to include the actual regexp compilation error for better debugging
1 parent 00b0ae5 commit c3ac8c3

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

api/v1alphav1/webhook_validations.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ func isClassDefault(class OvercommitClass, client client.Client) error {
7070
}
7171

7272
func checkIsRegexValid(regex string) error {
73+
// Limit regex length to prevent ReDoS (catastrophic backtracking)
74+
const maxRegexLen = 512
75+
if len(regex) > maxRegexLen {
76+
return fmt.Errorf("regex is too long (%d chars), maximum allowed is %d", len(regex), maxRegexLen)
77+
}
7378
_, err := regexp.Compile(regex)
7479
if err != nil {
75-
return errors.New("Error: the regex is not valid")
80+
return fmt.Errorf("invalid regex for excludedNamespaces: %w", err)
7681
}
7782
return nil
7883
}

0 commit comments

Comments
 (0)