Skip to content

socks: support CURLAUTH_ONLY in CURLOPT_SOCKS5_AUTH - #23003

Closed
MegaManSec wants to merge 1 commit into
curl:masterfrom
MegaManSec:socks5-auth-doc-noauth
Closed

MegaManSec wants to merge 1 commit into
curl:masterfrom
MegaManSec:socks5-auth-doc-noauth

Conversation

@MegaManSec

@MegaManSec MegaManSec commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

socks5_req0_init() always advertises method 0 and socks5_check_resp0() always accepts it, so a SOCKS5 proxy can select "no authentication" whatever the bitmask says. The bitmask cannot express "authentication required" either, since CURLAUTH_NONE is zero: CURLAUTH_BASIC | CURLAUTH_NONE is just CURLAUTH_BASIC. That matters most for GSS-API, which asks for GSS_C_MUTUAL_FLAG: answering method 0 strips the proxy's authentication to the client.

CURLAUTH_ONLY is currently rejected by setopt for this option, so accepting it cannot change any existing application. When set:

  • method 0 is not advertised, and a proxy selecting it anyway fails with CURLE_PROXY
  • a pooled connection whose SOCKS5 handshake did not authenticate is not reused, since url_match_proxy_use() otherwise matches on proxy type, destination and credentials only, and the handshake does not re-run on reuse
  • CURLAUTH_ONLY without CURLAUTH_BASIC or CURLAUTH_GSSAPI returns CURLE_BAD_FUNCTION_ARGUMENT

The man page is updated to say that no-auth is otherwise always offered and accepted, which it did not before.

Tests: 1742 has the test proxy require exactly one advertised method, 1743 has it answer method 0, 1744 does an unauthenticated transfer first and then requires auth on the same handle. Each fails without the change. Tests 700-799 pass.

@MegaManSec
MegaManSec force-pushed the socks5-auth-doc-noauth branch from 4677194 to bf64669 Compare September 18, 2026 22:26
@MegaManSec MegaManSec changed the title CURLOPT_SOCKS5_AUTH.md: no-auth is always offered and accepted socks: support CURLAUTH_ONLY in CURLOPT_SOCKS5_AUTH Sep 18, 2026
@github-actions github-actions Bot added the tests label Sep 18, 2026
The SOCKS5 method negotiation always offered "no authentication" and
accepted it, so the bitmask could not express that the connection has to
be authenticated. CURLAUTH_NONE is zero and cannot say it either.

With CURLAUTH_ONLY set, the method is neither offered nor accepted, and
a connection that did not authenticate is not reused.

Document both, and add tests 1742, 1743 and 1744.
@MegaManSec
MegaManSec force-pushed the socks5-auth-doc-noauth branch from bf64669 to 33cf1f3 Compare September 18, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently enforces the documented authentication requirement and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds opt-in enforcement of SOCKS5 authentication through CURLAUTH_ONLY, including safe connection reuse and documentation.

Changes:

  • Rejects unauthenticated SOCKS5 negotiation when authentication is required.
  • Prevents reuse of unauthenticated SOCKS5 connections.
  • Adds coverage for validation, negotiation, and reuse behavior.
File Description
lib/​setopt.c Accepts and validates CURLAUTH_ONLY.
lib/​socks.c Enforces authenticated negotiation.
lib/​url.c Restricts connection reuse appropriately.
lib/​urldata.h Tracks authentication requirements and connection state.
docs/​libcurl/​opts/​CURLOPT_SOCKS5_AUTH.md Documents the new behavior.
tests/​libtest/​lib1742.c Tests validation and required authentication.
tests/​libtest/​lib1744.c Tests unauthenticated connection reuse prevention.
tests/​libtest/​Makefile.inc Registers new libtests.
tests/​data/​test1742 Covers excluding no-auth from negotiation.
tests/​data/​test1743 Covers rejecting proxy-selected no-auth.
tests/​data/​test1744 Covers reuse behavior.
tests/​data/​Makefile.am Registers new test cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants