Skip to content
Access control Disclosed report Advanced

Improper enforcement of CURLOPT_SOCKS5_AUTH due to missing reuse key validation in libcurl

libcurl's connection reuse key for SOCKS5 proxies omits the CURLOPT_SOCKS5_AUTH policy, so a connection established under a permissive auth setting is silently reused for a later transfer that sets a stricter policy. An application that sets CURLAUTH_NONE for a later transfer can still send traffic over an already-authenticated SOCKS5 tunnel instead of failing.

cutiapretaa Follow

Originally disclosed on HackerOne

  • Disclosed after 2 days

detail:

  • lib/setopt.c:1048-1051

    • CURLOPT_SOCKS5_AUTH is stored into data->set.socks5auth
  • lib/socks.c:597-641 (socks5_req0_init)

    • fresh SOCKS5 handshake reads data->set.socks5auth, if BASIC is not allowed, it clears sx->proxy_user at 618-620, so username/password auth is not even offered
  • lib/socks.c:665-688 (socks5_check_resp0)

    • on a fresh connection, if the proxy selects BASIC while BASIC is disabled, or if no acceptable method exists, the connection fails
  • lib/urldata.h:345-351

    • struct proxy_info stores host / port / proxytype / user / passwd, but no SOCKS5 auth-method policy
  • lib/url.c:578-590 (proxy_info_matches)

    • reuse match compares only proxy type, port, host, proxy user, and proxy password
  • lib/url.c:879-913 (url_match_proxy_use)

    • SOCKS proxy reuse uses proxy_info_matches()
  • lib/url.c:1207-1229 (url_match_conn)

    • connection reuse is accepted if that proxy match succeeds
  • lib/url.c:2965-2998 (url_conn_reuse_adjust)

    • on reuse, curl may refresh proxy credentials, but it does not compare or refresh the SOCKS5 auth-method policy

so the invariant break is:

fresh SOCKS5 connections enforce CURLOPT_SOCKS5_AUTH, but connection reuse does not include that policy in the reuse key

docs:

this is not an API misuse case

changing options between transfers on the same easy handle is a documented libcurl usage pattern, and connection reuse is the default behavior unless the application forces a fresh connection,

if curl wanted CURLOPT_SOCKS5_AUTH to be “new connection only,” its docs should say so the same way they do for CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256, they do not, that makes silent reuse under a stricter later auth policy a bug, not intended behavior

( ref: https://curl.se/libcurl/c/CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256.html, https://curl.se/libcurl/c/curl_easy_setopt.html , https://curl.se/libcurl/c/CURLOPT_SOCKS5_AUTH.html , https://curl.se/libcurl/c/CURLOPT_FRESH_CONNECT.html )

exploit:

  1. create a normal easy handle

  2. set:

    • CURLOPT_URL = http://127.0.0.1:18081/
    • CURLOPT_PROXY = socks5://127.0.0.1:19081
    • CURLOPT_PROXYUSERPWD = "user:pass"
    • CURLOPT_SOCKS5_AUTH = CURLAUTH_BASIC
  3. perform transfer #1

    • the SOCKS5 proxy requires username/password, so the SOCKS handshake succeeds and the connection stays alive for reuse
  4. on the same easy handle, change only:

    • CURLOPT_SOCKS5_AUTH = CURLAUTH_NONE
  5. perform transfer #2 to the same proxy/destination

    • libcurl reuses the existing connection because the reuse key ignores the SOCKS5 auth-method policy
  6. no new SOCKS5 handshake happens, so the request succeeds over the already-authenticated tunnel

  7. do the same “NONE only” transfer on a fresh easy handle

    • it fails with CURLE_PROXY / error 97, because CURLAUTH_NONE means only no-auth is allowed and the proxy requires username/password

poc:

i ran a local setup:

  • SOCKS5 proxy on 127.0.0.1:19081 that requires username/password
  • HTTP origin on 127.0.0.1:18081
  • C poc using the uploaded libcurl build

what happened:

  1. transfer #1 on one easy handle with

    • CURLOPT_PROXY = socks5://127.0.0.1:19081
    • CURLOPT_PROXYUSERPWD = "user:pass"
    • CURLOPT_SOCKS5_AUTH = CURLAUTH_BASIC
    • result: success
  2. transfer #2 on the same easy handle, changing only

    • CURLOPT_SOCKS5_AUTH = CURLAUTH_NONE
    • result: success
    • log: reusing existing http: connection with proxy 127.0.0.1
  3. transfer #3 on a fresh easy handle with

    • CURLOPT_SOCKS5_AUTH = CURLAUTH_NONE
    • result: failure
    • error: 97 (proxy handshake error)
    • log: no authentication method was acceptable

server-side logs:

  • first connection offered methods [0, 2] and completed username/password auth
  • second transfer reused the same SOCKS connection and sent the HTTP request with no new SOCKS handshake
  • fresh third attempt offered only method [0] and the proxy rejected it

Impact

impacts:

  • SOCKS5 proxy-auth policy bypass
  • a transfer that is explicitly configured with CURLOPT_SOCKS5_AUTH = CURLAUTH_NONE can succeed when it should fail
  • the second transfer silently continues over an already-authenticated SOCKS5 tunnel created under a less restrictive earlier policy
  • applications can believe they enforced “no proxy authentication” for a later transfer, while libcurl actually keeps using a previously BASIC-authenticated proxy connection

The original report as published on HackerOne, by cutiapretaa. 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 connection reuse key (proxy_info_matches) compares proxy type, host, port, user and password but not the SOCKS5 auth-method policy, so a cached connection created under a looser policy is accepted for a stricter one.

Impact

A transfer explicitly configured to forbid proxy authentication can succeed by silently riding an earlier authenticated SOCKS5 tunnel, so applications may believe a stricter policy was enforced when it was not.

What the attacker needed

Application reuses one easy handle; first transfer uses BASIC proxy auth; later transfer sets CURLAUTH_NONE

How it was found

  1. Create an easy handle and set the URL, a SOCKS5 proxy, proxy credentials and CURLAUTH_BASIC for SOCKS5 auth.
  2. Perform the first transfer so the SOCKS5 handshake authenticates and the connection is kept for reuse.
  3. On the same handle, change only the SOCKS5 auth option to CURLAUTH_NONE.
  4. Perform a second transfer to the same proxy and destination; libcurl reuses the existing connection and the request succeeds.
  5. Repeat the NONE-only transfer on a fresh handle and observe it fails with a proxy handshake error.

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.

A SOCKS5 proxy is a middlebox that relays traffic, and it can require a username and password. libcurl lets an application say which login methods are allowed, and here a later request said 'no login allowed' but libcurl quietly reused an earlier connection that had already logged in. So the setting looked enforced but was not, because the check only happens when a brand new connection is opened.

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 cutiapretaa

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.