← All advisories

CORS origin bypass via unanchored allow_origin_patterns regex in cors plugin

Code
GHSA-36ph-2f82-fmrj
Severity
medium
Product
Higress
Vendor
Alibaba
Published
2026-11-01

Summary

The Higress cors WASM-Go plugin compiles each configured allow_origin_patterns entry into a regular expression that is not anchored with ^ and $, and then matches the incoming Origin request header with pattern.MatchString, which performs an unanchored substring match. An attacker-controlled origin that merely contains an allowed pattern as a substring is therefore accepted. The plugin then reflects the attacker's Origin value back in Access-Control-Allow-Origin and, when allow_credentials is enabled, also returns Access-Control-Allow-Credentials: true. This allows credentialed cross-origin reads of the protected API from attacker-owned domains, defeating the origin allow-list.

This was confirmed end to end against a real running Higress gateway: the official higress/gateway:v2.1.0 image (Envoy 1.27.7 with the envoy.wasm.runtime.v8 proxy-wasm host) running the actual compiled cors plugin, using only curl.

Details

The matcher is built in newOriginPatternFromString (plugins/wasm-go/extensions/cors/config/cors_config.go). The configured pattern is wrapped in \Q ... \E literal escapes, each * is expanded to .*, and the result is compiled with regexp.MustCompile without any start or end anchors.

GO
patternValue = "\\Q" + patternValue + "\\E"
patternValue = strings.ReplaceAll(patternValue, "*", "\\E.*\\Q")
...
return OriginPattern{
    declaredPattern: declaredPattern,
    patternValue:    patternValue,
    pattern:         regexp.MustCompile(patternValue),   // no ^ ... $ anchors
}

So the operator pattern https://*.example.com compiles to the regex \Qhttps://\E.*\Q.example.com\E, which has no anchors.

checkOrigin then tests the incoming Origin with MatchString and, on a match, returns the raw request origin to be reflected:

GO
for _, allowOriginPattern := range c.allowOriginPatterns {
    if allowOriginPattern.declaredPattern == defaultMatchAll || allowOriginPattern.pattern.MatchString(matchOrigin) {
        return origin, true   // returns the raw request Origin to be reflected
    }
}

regexp.MatchString succeeds if the pattern matches anywhere in the input. Because the generated regex is left-anchored only by the literal https:// prefix and is open on the right, any origin of the form https://<anything>.example.com<attacker-controlled-suffix> matches. For example https://app.example.com.evil.com contains the substring matched by \Qhttps://\E.*\Q.example.com\E, so checkOrigin returns it as allowed. The caller reflects that origin in Access-Control-Allow-Origin and sets Access-Control-Allow-Credentials from the plugin's allow_credentials setting.

The implementation appears modeled on Spring Framework's CorsConfiguration origin-pattern feature, but Spring anchors the generated pattern. The missing anchors here are the defect.

Proof of Concept

Step 1: build the plugin to wasm (unmodified upstream source)

The plugin is built with the project's own documented local-build recipe (plugins/wasm-go/Makefile). No source patch, no special flags.

SH
git clone https://github.com/alibaba/higress
cd higress/plugins/wasm-go/extensions/cors
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm .

Step 2: data-plane config (docker/envoy.yaml)

The wasm filter loads main.wasm on the V8 runtime with a common, documented configuration that enables credentials together with a wildcard pattern. The route forwards to the httpbin upstream cluster.

YAML
static_resources:
  listeners:
    - name: main
      address:
        socket_address: { address: 0.0.0.0, port_value: 18000 }
      filter_chains:
        - filters:
            - name: envoy.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: ingress_http
                codec_type: auto
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route: { cluster: httpbin }
                http_filters:
                  - name: envoy.filters.http.wasm
                    typed_config:
                      "@type": type.googleapis.com/udpa.type.v1.TypedStruct
                      type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
                      value:
                        config:
                          configuration:
                            "@type": type.googleapis.com/google.protobuf.StringValue
                            value: |-
                              {
                                "allow_origins": [],
                                "allow_origin_patterns": ["https://*.example.com"],
                                "allow_methods": ["GET","POST","OPTIONS"],
                                "allow_credentials": true,
                                "allow_headers": ["Content-Type","Authorization"],
                                "expose_headers": ["X-Custom-Header"],
                                "max_age": 3600
                              }
                          vm_config:
                            runtime: "envoy.wasm.runtime.v8"
                            code:
                              local: { filename: "/etc/envoy/main.wasm" }
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: httpbin
      connect_timeout: 1s
      type: STRICT_DNS
      lb_policy: ROUND_ROBIN
      dns_lookup_family: V4_ONLY
      load_assignment:
        cluster_name: httpbin
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address: { address: httpbin, port_value: 8080 }
admin:
  access_log_path: "/dev/null"
  address:
    socket_address: { address: 0.0.0.0, port_value: 8001 }

Step 3: harness (docker/docker-compose.yml)

Two stock containers: the official gateway Envoy run directly with our config, and a go-httpbin upstream.

YAML
services:
  httpbin:
    image: mccutchen/go-httpbin:latest
    container_name: cors-poc-httpbin
    networks: [corsnet]

  gateway:
    image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway:v2.1.0
    container_name: cors-poc-gateway
    depends_on: [httpbin]
    entrypoint:
      - /usr/local/bin/envoy
      - -c
      - /etc/envoy/envoy.yaml
      - --concurrency
      - "1"
      - --log-level
      - info
      - --component-log-level
      - wasm:info
    volumes:
      - ./envoy.yaml:/etc/envoy/envoy.yaml:ro
      - ./main.wasm:/etc/envoy/main.wasm:ro
    ports: ["18000:18000", "8001:8001"]
    networks: [corsnet]

networks:
  corsnet: { driver: bridge }

Bring it up (the gateway logs [cors] ... plugin start successfully once the real plugin is loaded):

SH
docker-compose up -d
docker logs cors-poc-gateway 2>&1 | grep "plugin start successfully"

Proof Attack

image.png

Impact

When the protected API serves authenticated, credentialed responses and the operator uses a wildcard allow_origin_patterns together with allow_credentials: true, an attacker can register a domain whose name embeds the allowed domain as a substring (for example example.com.evil.com, served from app.example.com.evil.com) and host a page that makes credentialed cross-origin requests to the protected API. Because the gateway reflects the attacker origin with Access-Control-Allow-Credentials: true, the victim's browser permits the cross-origin read and returns the authenticated response to the attacker page. This enables session-scoped data exfiltration and defeats the purpose of the origin allow-list. The trigger is a normal cross-origin request from a victim browser, which is why the vector is scored UI:R and S:C (the same-origin policy boundary enforced for the victim's session is crossed).

Remediation

Anchor the generated regular expression and match the whole string, so a pattern only matches a complete origin rather than any substring.

  • Compile the matcher anchored, for example regexp.MustCompile("^(?:" + patternValue + ")$"), or replace pattern.MatchString(matchOrigin) with an exact full-match comparison.
  • Additionally validate that the request Origin is a syntactically valid origin (scheme, host, optional port, with no path or trailing data) before matching.
  • Follow the upstream model (Spring CorsConfiguration), which anchors the *-expanded patterns.

← All advisories · Home

© 2026 Nikko Enggaliano Pratama
RSS