@@ -82,16 +82,32 @@ func (m *WildcardMatcher) wildcardMatch(origin, pattern string) bool {
8282// This expands wildcard patterns based on the request origin
8383func (m * WildcardMatcher ) GetAllowedOrigins (requestOrigin string , staticOrigins []string ) []string {
8484 allowedOrigins := make ([]string , 0 , len (staticOrigins ))
85+ hasMatchingWildcard := false
8586
87+ // First pass: check if any wildcard matches
88+ for _ , origin := range staticOrigins {
89+ if strings .Contains (origin , "*" ) {
90+ if m .matchPattern (requestOrigin , origin ) {
91+ hasMatchingWildcard = true
92+ break
93+ }
94+ }
95+ }
96+
97+ // Second pass: build the result based on the logic
8698 for _ , origin := range staticOrigins {
8799 if strings .Contains (origin , "*" ) {
88100 // This is a wildcard pattern
89101 if m .matchPattern (requestOrigin , origin ) {
90102 // Add the actual request origin instead of the pattern
91103 allowedOrigins = append (allowedOrigins , requestOrigin )
104+ } else if ! hasMatchingWildcard {
105+ // No wildcards match, so include this wildcard pattern as-is
106+ allowedOrigins = append (allowedOrigins , origin )
92107 }
108+ // If a wildcard matches but this one doesn't, skip it (don't add anything)
93109 } else {
94- // This is a static origin, add as-is
110+ // This is a static origin, always add as-is
95111 allowedOrigins = append (allowedOrigins , origin )
96112 }
97113 }
0 commit comments