Skip to content
Access control Disclosed report Advanced CVE-2022-22576

Connection Reuse Ignores OAuth Bearer Token Mismatch

The connection pool in libcurl can reuse a persistent HTTP connection for a request with a different OAuth bearer token, because the token match check is skipped for HTTP. An attacker using a shared libcurl instance could have their request sent with another user's bearer token, gaining that user's API access.

sabari_n Follow

Originally disclosed on HackerOne

  • Disclosed after 5 hours

Summary:

The connection pool reuse function url_match_conn() in lib/url.c checks oauth_bearer in its credential match block — but only for protocols marked as requiring per-connection credentials. For HTTP, OAuth bearer is passed as a header, not a protocol-level credential. If a libcurl application reuses an easy handle to connect to two different API endpoints using different bearer tokens without setting CURLOPT_FRESH_CONNECT=1, the connection pool may serve the second request on the first connection, attaching the WRONG bearer token. This is closely related to the class of bugs that produced CVE-2022-22576 (OAuth2 bearer bypass in connection reuse).

Affected version

Identified in current master

Steps To Reproduce:

Multi-tenant API server using a shared libcurl instance (common in thread pools, connection-pooling proxies, Go/Python/Java bindings):

  1. User attacker1 authenticates → curl makes HTTP request with CURLOPT_XOAUTH2_BEARER = token_attacker1 → TCP connection opened to api.example.com:443 → conn->oauth_bearer = token_alice → Connection returned to pool (keep-alive)

  2. User attacker2 makes a request to the SAME host → curl sets CURLOPT_XOAUTH2_BEARER = token_attacker2 on easy handle → url_match_conn() finds Alice's connection in pool → oauth_bearer check is SKIPPED (PROTOPT_CREDSPERREQUEST gate) → attacker2's connection is reused → lib/http.c builds: Authorization: Bearer token_alice ← BUG → API server receives attacker2's request authenticated as Alice → attacker2 receives attacker1's data / can take attacker2's actions

python3 poc_bearer_reuse.py

Impact

impact:

Requests to different APIs on the same host may share a persistent HTTP connection, causing the wrong OAuth bearer token to be used. In multi-tenant applications (serving different users from the same libcurl instance) this can lead to cross-account credential leakage and unauthorized API access.

##recommended Set CURLOPT_FRESH_CONNECT=1 when switching bearer tokens between requests on the same host. Application-level fix: call curl_easy_reset() or create a new easy handle per token boundary. Structural fix: ensure oauth_bearer changes force connection pool expiry for HTTP connections regardless of per-connection credential flag.

Attachments

Screenshot_from_2026-03-10_13-12-47.png
Screenshot_from_2026-03-10_13-12-47.png From the original on HackerOne

The original report as published on HackerOne, by sabari_n. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 credential match in url_match_conn() only compares oauth_bearer for protocols flagged as needing per-request credentials, so HTTP connections are reused even when the bearer token differs.

Impact

Requests to different APIs on the same host may share a persistent HTTP connection, causing the wrong OAuth bearer token to be used, which in multi-tenant applications could lead to cross-account credential leakage and unauthorised API access.

What the attacker needed

Shared libcurl instance across users; same host for both requests; different bearer tokens per request; no fresh connection forced

The fix

Applications should set CURLOPT_FRESH_CONNECT=1 when switching bearer tokens, reset or recreate the easy handle per token, and structurally the library should expire pooled HTTP connections when oauth_bearer changes.

How it was found

  1. A first user authenticates and libcurl sends a request with their bearer token, opening a keep-alive connection that is returned to the pool.
  2. A second user makes a request to the same host with a different bearer token set on the easy handle.
  3. The connection pool matches the first user's connection and skips the bearer token check.
  4. libcurl reuses that connection and sends the second user's request with the first user's bearer token.
  5. The API server treats the second user's request as the first user, returning the first user's data or allowing their actions.

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 program talks to a web server, it can keep the network connection open and reuse it for later requests. libcurl, a common library for this, decides whether a reused connection is suitable by checking things like the address and credentials. Here it forgot to check that the OAuth bearer token (a secret string proving who you are) is the same, so a second user's request could go out carrying the first user's token.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by sabari_n

View all

1 more disclosed report, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.