Skip to content
Misconfiguration Disclosed report Advanced CVE-2025-0239

Only the first Alt-Svc ALPN negotiation is verified

Firefox only verifies the ALPN protocol negotiation on the first connection to an alternative service, not on subsequent connections. A man-in-the-middle attacker can forward the first connection to a valid server and later connections to a different server, bypassing the protocol check.

pspaul Follow

Originally disclosed on Mozilla

  • Fixed in 29 days
  • Paid in 30 days
  • Disclosed after 29 days
Text
Version: Firefox 131.0.3 (64-bit)
OS: Manjaro Linux 24.1.1

How was this issue discovered?
Manual testing. I was researching cross-protocol attacks using the Alt-Svc header when I found this bypass.


General Description:

The Alt-Svc spec's section 2.4 (https://httpwg.org/specs/rfc7838.html#switching) mandates that the browser verifies that the alternative service negotiates the correct protocol, for example via ALPN:

> If the connection to the alternative service does not negotiate the expected protocol (for example, ALPN fails to negotiate h2, or an Upgrade request to h2c is not accepted), the connection to the alternative service MUST be considered to have failed.

Firefox only verifies this for the first connection but not for subsequent ones. Therefore, a Man-in-the-Middle attacker can bypass the ALPN check by forwarding the first connection to a valid server, closing the connection after some time, and forwarding all subsequent requests to a different server.

The PoC demonstrates this by running three TLS servers, all using the same certificate:
- HTTP/1.1 on port `:8443` (ALPN offers `http1.1`)
- HTTP/2 on port `:8444` (ALPN offers `h2`)
- Plain TLS on port `:8445` (ALPN list is empty)

Firefox should never use the alternative service `h2=":8445"` because ALPN will not negotiate `h2`. However, by forwarding the first request to `:8444`, which correctly negotiates `h2`, Firefox can be tricked into trusting all later connections.


Steps to reproduce:

1. Start the PoC: `node server.js`
2. Add `127.0.0.1 foo.example.com` to your `/etc/hosts` file
3. Visit `https://foo.example.com:8443/?alt-svc=:1337` in Firefox
4. Accept the self-signed certificate warning (or replace `privkey.pem` and `fullchain.pem` with valid certificates before step 1)
5. Now the following should happen:
    1. The page will first be served via HTTP/1.1 over TLS from `:8443`, delivering the `Alt-Svc: h2=":1337"` header
    2. After 1 second, the page refreshes, causing the browser to make the first connection to the attacker's alternative service on `:1337`
    3. The attacker forwards this first request to the legitimate HTTP/2 server on `:8444`
    4. The new page loads, showing that it was loaded via HTTP/2
    5. The attacker now closes the forwarded connection between the browser and the HTTP/2 server
    6. The page then refreshes again, causing the browser to open a new connection to the attacker on `:1337`
    7. The attacker now forwards the request to the invalid TLS server at `:8445`
    8. The page loads, showing that it was loaded from `:8445`, which shouldn't happen

The PoC script's output should demonstrate the same:

'''plain
[h1] GET /?alt-svc=:1337
[attacker] Forwarding to h2 (:8444)
[h1] GET /favicon.ico
[h2] GET /?refresh
[attacker] Terminating first connection
[attacker] Forwarding to plain (:8445)
[plain] Got connection
[plain] Got data: GET / HTTP/1.1
[plain] Got data: Host: foo.example.com:8443
[plain] Got data: User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
...
'''

I also recorded a demo of the PoC, I hope you enjoy it ;)


Root cause analysis:

I'm not very familiar with the Firefox code base, but it looks like `TRRServiceChannel::BeginConnect()` is consulting the Alt-Svc cache here: https://searchfox.org/mozilla-central/rev/387f3edbef37d31b2e91fb0812c74b54729e86ff/netwerk/protocol/http/TRRServiceChannel.cpp#405-407

If there's a matching entry, it means that the alternative service was previously validated, and Firefox connects to the `mConnectionInfo` from the cache entry instead of the original one.

I think the problem here is that the Alt-Svc cache holds the validation state. To me, the spec sounds like each new TLS connection needs to do the validation individually to prevent a Man-in-the-Middle attacker from switching the destination server at some point.

The original report as published on Mozilla's Bugzilla, by pspaul. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the Alt-Svc cache stores the validation state, so Firefox skips re-verifying ALPN on subsequent connections to the same alternative service.

Impact

A man-in-the-middle attacker could bypass the ALPN check and cause Firefox to use an alternative service that does not negotiate the expected protocol, potentially enabling cross-protocol attacks.

What the attacker needed

Man-in-the-middle position; victim uses Firefox; victim visits a page with Alt-Svc header

How it was found

  1. Start the PoC server.
  2. Add a hosts file entry mapping the test domain to localhost.
  3. Visit the test URL in Firefox and accept the certificate warning.
  4. The page loads over HTTP/1.1 and delivers an Alt-Svc header pointing to the attacker's port.
  5. The attacker forwards the first connection to a valid HTTP/2 server, then closes it.
  6. On refresh, the attacker forwards the new connection to a plain TLS server that does not negotiate HTTP/2, and the page still loads.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a website tells the browser to use a different server (an 'alternative service'), the browser should check that the new server speaks the right protocol. This report shows Firefox only checks the first time, so an attacker who can intercept traffic can trick the browser into talking to the wrong server later.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.