Repository navigation
fix(a2a): allow literal CORS origins alongside patterns - #5088
Merged
Merged
Conversation
echo ignores AllowOrigins once AllowOriginFunc is set, so a --cors-origin spec mixing a literal origin and a wildcard pattern silently dropped every literal origin: AllowOriginFunc only ran MatchPattern, which tests the regex patterns and neither the literals nor the "*" wildcard. Add OriginMatcher.Match, which tests literals, "*" and patterns together, and use it in the a2a server's AllowOriginFunc branch. Regression tests cover a mixed literal+pattern spec through the preflight and the actual response, and the Match predicate directly. Fixes docker#5086 Signed-off-by: deka <dimitri.rayer@gmail.com>
trungutt
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
serve a2adropped literal CORS origins whenever the--cors-originspec alsocontained a wildcard pattern. A spec mixing a literal origin and a pattern (e.g.
https://app.example.com,~^https://.+\.preview\.example\.com$) silently rejectedthe literal origin.
Root cause
corsMiddlewareConfigsetAllowOriginFunctoorigins.MatchPatternas soon asthe spec had any pattern. echo ignores
AllowOriginsonceAllowOriginFuncisset, and
MatchPatternchecks only the regex patterns — not the literalorigins nor the
*wildcard. So every literal origin was dropped.Fix
pkg/httpsec: addOriginMatcher.Match, which tests literals,*andpatterns together — the single predicate needed when echo's
AllowOriginFunctakes over from
AllowOrigins.pkg/a2a/server.go: switch theAllowOriginFuncbranch fromorigins.MatchPatterntoorigins.Match.Regression tests
pkg/a2a:TestCorsMiddlewareConfigMixedLiteralAndPatternconfigures CORSwith a mixed literal + wildcard spec and asserts both the preflight and the
actual response's
Access-Control-Allow-Originallow the literal origin anda pattern origin. It fails against
MatchPatternand passes withMatch(verified by temporarily reverting the fix).
pkg/httpsec: extendTestParseOriginsto exerciseMatchfor literal,*and mixed specs.
Validation
task build,go test ./pkg/httpsec ./pkg/a2aandgolangci-linton bothpackages all pass.
Fixes #5086