-
Notifications
You must be signed in to change notification settings - Fork 295
Closed
Labels
Description
Objective
Hoist two regexp.MustCompile calls in validateExpressionForDangerousProps to package-level var declarations to eliminate repeated regex compilation in a hot validation path.
Context
Reported in discussion #19993 (Sergo audit: scanner-buffer-revisit-plus-regexp-compilation-audit, 2026-03-07).
validateExpressionForDangerousProps in pkg/workflow/expression_validation.go calls regexp.MustCompile twice — once at function scope (per-call) and once inside a for loop (per-iteration) — on compile-time constant patterns. Since validateSingleExpression is recursive and called for every expression in every compiled workflow, these allocations accumulate significantly.
Files to Modify
pkg/workflow/expression_validation.go— hoist two regex vars
Approach
- Locate the two
regexp.MustCompilecalls invalidateExpressionForDangerousProps(lines ~212, ~216):regexp.MustCompile("[.\\[\\]]+")— at function scoperegexp.MustCompile("^\\d+$")— insideforloop
- Add package-level
vardeclarations alongside existing regex vars in the file:var ( exprPartSplitRe = regexp.MustCompile(`[.\[\]]+`) exprNumericPartRe = regexp.MustCompile(`^\d+$`) )
- Replace the inline
regexp.MustCompile(...)calls with references toexprPartSplitReandexprNumericPartRe. - Run
make fmtandmake test-unit(or selectively:go test -v -run "Test.*Expression" ./pkg/workflow/).
Acceptance Criteria
- Both regex patterns are declared as package-level vars in
expression_validation.go - No
regexp.MustCompilecalls remain insidevalidateExpressionForDangerousProps - All existing expression validation tests pass
-
make agent-finishpasses with no errors
Generated by Plan Command for issue #discussion #19993 · ◷
- expires on Mar 10, 2026, 5:59 AM UTC
Reactions are currently unavailable