Skip to content

fix: prevent panic on invalid regex in reload annotation#1193

Open
nikolauspschuetz wants to merge 1 commit into
stakater:masterfrom
nikolauspschuetz:fix/reload-annotation-invalid-regex-panic
Open

fix: prevent panic on invalid regex in reload annotation#1193
nikolauspschuetz wants to merge 1 commit into
stakater:masterfrom
nikolauspschuetz:fix/reload-annotation-invalid-regex-panic

Conversation

@nikolauspschuetz

Copy link
Copy Markdown
Contributor

Problem

ShouldReload compiles each comma-separated value of a named reload annotation with regexp.MustCompile:

// pkg/common/common.go
re := regexp.MustCompile("^" + value + "$")

The value comes directly from a user-set annotation on a watched workload (e.g. secret.reloader.stakater.com/reload / configmap.reloader.stakater.com/reload, which support regex). regexp.MustCompile panics on an invalid pattern, and the queue worker (wait.Until(c.runWorker, …)) has no recover(). So a single malformed annotation on any workload in any watched namespace — e.g.:

metadata:
  annotations:
    secret.reloader.stakater.com/reload: "app-config["   # unbalanced bracket

crashes the Reloader process and stops reloads cluster-wide — a low-privilege, cross-namespace availability issue.

Fix

Use regexp.Compile and, on error, log and skip that pattern instead of panicking. Valid patterns behave exactly as before; an invalid one is logged and simply doesn't match.

Test

Added TestShouldReload_InvalidRegexAnnotation_DoesNotPanic in pkg/common/common_test.go. It panics before this change and passes after (verified with go test ./pkg/common/...).

ShouldReload compiled each comma-separated value of a named reload
annotation (e.g. secret.reloader.stakater.com/reload) with
regexp.MustCompile, which panics on an invalid pattern. The value comes
straight from a user-set annotation on a watched workload, and the queue
worker has no recover(), so a single malformed annotation (e.g.
"app-config[") on any workload in any watched namespace crashes Reloader
and stops reloads cluster-wide.

Use regexp.Compile and, on error, log and skip that pattern instead of
panicking.
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 22, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant