Skip to content

client: Extract proxy handshakes into a new proxy_handshake crate - #61427

Merged
eholk merged 4 commits into
mainfrom
proxy-handshake-crate
Jul 23, 2026
Merged

client: Extract proxy handshakes into a new proxy_handshake crate#61427
eholk merged 4 commits into
mainfrom
proxy-handshake-crate

Conversation

@eholk

@eholk eholk commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This consolidates the proxy code in client/src/proxy into a new proxy_handshake crate that implements the client side of HTTP CONNECT and SOCKS4/4a/5/5h handshakes sans-IO: the protocol logic is a pure state machine that never touches a socket, with thin drivers behind futures-io and tokio feature flags. client now drives the websocket's proxy tunnel through the tokio driver, and the tokio-socks dependency goes away.

The main win is testability: the handshakes are now covered by synchronous byte-level tests on both sides of each exchange, plus a property test that the outcome is invariant under how the proxy's bytes are chunked across reads — the class of partial-read bug that's hard to hit with hand-written tests but easy to hit in production behind a buffering proxy. The crate is written as if it were standalone (no zed-internal dependencies, structured errors instead of anyhow), which is also why it grows both driver flavors rather than just the one client needs today.

Two deliberate behavior changes, both converging on spec/curl semantics:

  • Proxy credentials embedded in URLs are now percent-decoded before use, per RFC 3986 §3.2.1. Previously they were sent in their encoded form, which only worked for credentials with no reserved characters. A password that literally contains something like %40 and relied on the old behavior now needs the RFC-correct %2540 spelling.
  • NO_PROXY is now honored for the collaboration connection, matching the exclusions reqwest already applies to the rest of Zed's HTTP traffic.

TLS to the proxy itself (for https:// proxy URLs) and DNS policy stay in client, since those are I/O concerns the sans-IO crate deliberately doesn't own.

Release Notes:

  • Improved proxy support: the collaboration connection now respects NO_PROXY and percent-encoded proxy credentials.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 21, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jul 21, 2026

@swannysec swannysec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good on the security side 🔒

eholk added 4 commits July 23, 2026 15:33
The CONNECT and SOCKS4/4a/5/5h client handshakes move from
client/src/proxy into a new sans-IO crate. The protocol logic is a pure
state machine (feed bytes in, get bytes to send out), with thin drivers
behind futures-io and tokio feature flags; client uses the tokio
driver. This drops the tokio-socks dependency and makes the protocol
logic testable synchronously, including a proptest that the outcome is
invariant under how proxy bytes are chunked across reads.

Two behavior changes, both converging on spec/curl semantics:

- Proxy credentials in URLs are now percent-decoded before use
  (RFC 3986 s3.2.1); previously they were sent encoded.
- NO_PROXY is now honored for the collaboration connection, matching
  the exclusions reqwest already applies to HTTP traffic.
- Rename percent_decode to decode_userinfo and document that it exists
  because RFC 3986 s3.2.1 defines userinfo as percent-encoded.
- Document that the SOCKS5 refusal messages are verbatim from
  RFC 1928 s6.
- Expand ProxySpec's docs to explain its relationship to url::Url.
- Free the Tunneled leftover buffer once it has been fully replayed.
Address two non-blocking security review findings:

- Enforce the HTTP CONNECT response-head cap on complete heads too,
  not just partial ones, so the cap holds regardless of how large the
  driver's read chunks are.
- Reject ASCII control bytes in Target::Domain at Handshake::new
  (they could forge protocol structure in the CONNECT request line
  and NUL-terminated SOCKS4a fields), and reject NUL in the SOCKS4
  user id (the field is NUL-terminated on the wire). Enforcement
  lives in Handshake::new rather than ProxySpec::parse because
  ProxySpec's fields are public and parse can be bypassed.

HTTP Basic and SOCKS5 credentials are deliberately not filtered:
base64 encoding and length prefixes already neutralize control bytes
there, and RFC 1929 allows arbitrary octets in SOCKS5 passwords.
@eholk
eholk force-pushed the proxy-handshake-crate branch from 55755f9 to 3140693 Compare July 23, 2026 22:35
@eholk
eholk enabled auto-merge July 23, 2026 22:40
@eholk
eholk added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit dd3a94e Jul 23, 2026
36 checks passed
@eholk
eholk deleted the proxy-handshake-crate branch July 23, 2026 22:49
mdz-axo added a commit to mdz-axo/zed-kask that referenced this pull request Jul 25, 2026
Upstream changes (zed-industries/zed main, 27 commits):
- agent: Add agent.compaction_model setting for context compaction (zed-industries#60012)
- agent: Show effort selector for anthropic compatible providers (zed-industries#61579)
- acp: Update agent-client-protocol SDK to 2.0.0 (zed-industries#61570)
- client: Extract proxy handshakes into new proxy_handshake crate (zed-industries#61427)
- collab: Fix multiworkspace location out of sync bugs (zed-industries#61598)
- editor: Fix sticky header drag cancels autoscroll (zed-industries#53592)
- editor: Fix crash when copying and pasting using multiple cursors (zed-industries#61545)
- editor: Skip untitled buffers when saving a multi-buffer (zed-industries#61380)
- gpui: Fix images not being drawn with rounded corners with ObjectFit::Cover (zed-industries#61383)
- gpui: Fix deadlock in performance profiler and reenable it (zed-industries#61584)
- git_ui: Prevent Git panel bindings in repository selector (zed-industries#61282)
- language_model: Add explicit OpenAI conversation compaction and fix Anthropic compaction (zed-industries#61370)
- markdown: Fix squashed Mermaid diagrams in markdown preview (zed-industries#61260)
- Opus 5 BYOK Support (zed-industries#61596)
- repl: Show add-cell controls in empty notebooks (zed-industries#61329)
- search: Escape seeded buffer search query in regex mode (zed-industries#57748)
- settings: Fix VS Code import appending duplicate file associations (zed-industries#61355)
- settings: Split VSCode and Zed keymap files (zed-industries#61532)
- Treat blank spawn_agent session IDs as absent (zed-industries#60893)
- worktree: Reload git state when a watcher rescan covers a repository (zed-industries#61541)
- Plus 7 more minor fixes.

Merge fixes:
- crates/agent/src/thread.rs: replay_tool_call used 'message_ix' (undefined)
  after auto-merge; renamed to 'owning_message_ix' (the parameter name).
- Cargo.toml: Removed stale workspace members hkask-wallet and hkask-git-cas
  (both directories deleted in prior commits but workspace entries remained).
- kask/crates/hkask-regulation/src/wallet_manager.rs: Stubbed consume() and
  settle_rjoules() on WalletBudgetPort — these were API-key encumbrance
  operations from the deleted hkask-wallet crate; regulation tracks per-agent
  gas balances, not per-key encumbrances.
- kask/crates/hkask-regulation/src/wallet_gas_calibrator.rs: Fixed test to
  use crate::agent_wallet_store::WalletStore instead of hkask_storage::WalletStore.
- kask/crates/hkask-regulation/Cargo.toml: Added tokio macros feature to
  dev-dependencies for #[tokio::test].
- kask/crates/kask_bridge/Cargo.toml: Added futures dependency (needed by
  context_injector.rs for futures::executor::block_on).
- kask/crates/kask_bridge/src/context_injector.rs: Fixed futures_util::executor
  to futures::executor (futures-util doesn't include executor module).

Release Notes:

- N/A
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…d-industries#61427)

This consolidates the proxy code in `client/src/proxy` into a new
`proxy_handshake` crate that implements the client side of HTTP CONNECT
and SOCKS4/4a/5/5h handshakes sans-IO: the protocol logic is a pure
state machine that never touches a socket, with thin drivers behind
`futures-io` and `tokio` feature flags. `client` now drives the
websocket's proxy tunnel through the tokio driver, and the `tokio-socks`
dependency goes away.

The main win is testability: the handshakes are now covered by
synchronous byte-level tests on both sides of each exchange, plus a
property test that the outcome is invariant under how the proxy's bytes
are chunked across reads — the class of partial-read bug that's hard to
hit with hand-written tests but easy to hit in production behind a
buffering proxy. The crate is written as if it were standalone (no
zed-internal dependencies, structured errors instead of `anyhow`), which
is also why it grows both driver flavors rather than just the one
`client` needs today.

Two deliberate behavior changes, both converging on spec/curl semantics:

- Proxy credentials embedded in URLs are now percent-decoded before use,
per RFC 3986 §3.2.1. Previously they were sent in their encoded form,
which only worked for credentials with no reserved characters. A
password that literally contains something like `%40` and relied on the
old behavior now needs the RFC-correct `%2540` spelling.
- `NO_PROXY` is now honored for the collaboration connection, matching
the exclusions reqwest already applies to the rest of Zed's HTTP
traffic.

TLS to the proxy itself (for `https://` proxy URLs) and DNS policy stay
in `client`, since those are I/O concerns the sans-IO crate deliberately
doesn't own.

Release Notes:

- Improved proxy support: the collaboration connection now respects
`NO_PROXY` and percent-encoded proxy credentials.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants