Skip to content

fix(a2a): allow literal CORS origins alongside patterns - #5088

Merged
trungutt merged 1 commit into
docker:mainfrom
la-fabrique:fix/a2a-cors-literal-origins
Dec 1, 2026
Merged

trungutt merged 1 commit into
docker:mainfrom
la-fabrique:fix/a2a-cors-literal-origins

Conversation

@deka

@deka deka commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

serve a2a dropped literal CORS origins whenever the --cors-origin spec also
contained a wildcard pattern. A spec mixing a literal origin and a pattern (e.g.
https://app.example.com,~^https://.+\.preview\.example\.com$) silently rejected
the literal origin.

Root cause

corsMiddlewareConfig set AllowOriginFunc to origins.MatchPattern as soon as
the spec had any pattern. echo ignores AllowOrigins once AllowOriginFunc is
set, and MatchPattern checks only the regex patterns — not the literal
origins nor the * wildcard. So every literal origin was dropped.

Fix

  • pkg/httpsec: add OriginMatcher.Match, which tests literals, * and
    patterns together — the single predicate needed when echo's AllowOriginFunc
    takes over from AllowOrigins.
  • pkg/a2a/server.go: switch the AllowOriginFunc branch from
    origins.MatchPattern to origins.Match.

Regression tests

  • pkg/a2a: TestCorsMiddlewareConfigMixedLiteralAndPattern configures CORS
    with a mixed literal + wildcard spec and asserts both the preflight and the
    actual response's Access-Control-Allow-Origin allow the literal origin and
    a pattern origin. It fails against MatchPattern and passes with Match
    (verified by temporarily reverting the fix).
  • pkg/httpsec: extend TestParseOrigins to exercise Match for literal, *
    and mixed specs.

Validation

task build, go test ./pkg/httpsec ./pkg/a2a and golangci-lint on both
packages all pass.

Fixes #5086

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>
@deka
deka requested a review from a team as a code owner December 1, 2026 14:36
@aheritier aheritier added area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication area/security Authentication, authorization, secrets, vulnerabilities kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Dec 1, 2026
@trungutt
trungutt added this pull request to the merge queue Dec 1, 2026
Merged via the queue into docker:main with commit 96f9a42 Dec 1, 2026
28 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/a2a Agent-to-Agent protocol, A2A server, inter-agent communication area/security Authentication, authorization, secrets, vulnerabilities kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(a2a): CORS drops literal origins when the spec also has a pattern

3 participants