Hysteria 2 Protocol Specification¶
- Document: The Hysteria 2 Protocol Specification
- Category: Informational
- Chinese edition: 简体中文
Status of This Memo¶
This document specifies the wire format and runtime behavior of the Hysteria protocol used since version 2.0.0 (internally also referred to as "v4"). It is provided for implementers and interoperability testing and is not an Internet Standard.
Abstract¶
Hysteria 2 is a QUIC-based TCP and UDP proxy protocol designed for high throughput, security, and censorship resistance. This document details its underlying transport requirements, HTTP/3 masqueraded authentication, TCP/UDP request multiplexing, congestion-control rate signaling, and optional Salamander obfuscation layer.
1. Introduction¶
Hysteria 2 multiplexes TCP streams and UDP datagrams over an encrypted QUIC connection. To resist active probing and Deep Packet Inspection (DPI), initial authentication is disguised as a standard HTTP/3 request/response exchange; upon authentication, the connection transitions into proxy frame processing.
2. Conventions and Terminology¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
3. Underlying Transport and Wire Encoding¶
Hysteria 2 MUST operate over standard QUIC [RFC9000] and MUST support the Unreliable Datagram Extension [RFC9221].
- Byte Order: All fixed-width multi-byte integers are big-endian (network byte order).
- Variable-Length Integers: All varints are encoded and decoded as specified in QUIC [RFC9000] Section 16.
4. Authentication and HTTP/3 Masquerading¶
A defining property of Hysteria 2 is that to any unauthenticated observer (middlebox or active prober), a server behaves indistinguishably from a standard HTTP/3 web server.
Accordingly, a Hysteria 2 server MUST implement an HTTP/3 server [RFC9114] and serve normal HTTP requests. To avoid static fingerprinting, servers SHOULD host real content or reverse-proxy a legitimate website.
4.1. Client Authentication Request¶
After establishing the QUIC connection, the client MUST send the following HTTP/3 request:
:method: POST
:path: /auth
:host: hysteria
Hysteria-Auth: [string]
Hysteria-CC-RX: [uint]
Hysteria-Padding: [string]
Hysteria-Auth: Authentication credentials.Hysteria-CC-RX: Client maximum receive rate in bytes per second (0indicates unknown).Hysteria-Padding: OPTIONAL random variable-length string to obfuscate header size.
4.2. Server Authentication Response¶
The server MUST recognize this request, MUST NOT forward it to the camouflage upstream or serve content for it, and MUST validate the credentials.
On success, the server MUST reply with:
:status: 233 HyOK
Hysteria-UDP: [true/false]
Hysteria-CC-RX: [uint/"auto"]
Hysteria-Padding: [string]
:status: MUST be exactly233.Hysteria-UDP: Indicates whether UDP relaying is supported.Hysteria-CC-RX: Server maximum receive rate in bytes per second (0means unlimited; the literal"auto"declines to specify a cap and directs the client to use congestion control autonomously).Hysteria-Padding: OPTIONAL random variable-length string that SHOULD be ignored by the receiver.
4.2.1. Authentication Failure¶
If authentication fails, the server MUST behave identically to a standard web server that does not understand the request (e.g., returning 404 / 403, or forwarding to the camouflage upstream).
The client MUST check :status; any status other than 233 MUST be treated as authentication failure and the client MUST disconnect immediately.
4.2.2. Post-Authentication Transition¶
After (and only after) successful authentication, the server MUST transition the QUIC connection state into a Hysteria proxy connection and process proxy requests.
5. Proxy Requests¶
5.1. TCP Proxying¶
For each new TCP connection, the client MUST open a new bidirectional QUIC stream and send a TCPRequest message.
5.1.1. TCPRequest Message¶
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0x401 (varint) | Address length (varint) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Address string (host:port)... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Padding length (varint) | Random padding... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
5.1.2. TCPResponse Message¶
The server MUST reply on the same bidirectional stream with a TCPResponse message:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Status | Message length (varint) | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| Message string... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Padding length (varint) | Random padding... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Status(1B): Unsigned 8-bit status code (0x00= OK,0x01= Error).
If Status is 0x00, the server MUST immediately begin full-duplex forwarding between the QUIC stream and the target TCP connection until either side closes. If Status is 0x01, the server MUST close the QUIC stream.
5.2. UDP Proxying¶
UDP packets MUST be encapsulated in UDPMessage frames and sent over QUIC Unreliable Datagrams in both directions. If the server signaled no UDP support during authentication, it SHOULD silently discard all UDP messages received from the client.
5.2.1. UDPMessage Format¶
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Session ID (4B) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Packet ID (2B) | Frag ID (1B) | Frag Cnt (1B) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Address length (varint) | Address string (host:port)... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Payload... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Session ID(4B): Big-endian unsigned 32-bit identifier unique per logical UDP session. The server SHOULD assign a distinct outbound UDP port perSession ID(absent symmetric NAT or similar constraints).Packet ID(2B): Big-endian unsigned 16-bit identifier shared across fragments of one packet.Frag ID(1B): Zero-based fragment index.Frag Cnt(1B): Total number of fragments (Fragment Count).
5.2.2. UDP Session Lifecycle¶
No explicit teardown message exists. Clients MAY retain and reuse a Session ID indefinitely. Servers SHOULD expire inactive sessions and reclaim ports; a message carrying an unrecognized or expired Session ID MUST be treated as a new session with a freshly allocated outbound port.
5.2.3. Fragmentation Rules¶
Large UDP packets exceeding the QUIC datagram limit MUST be fragmented or dropped:
- Unfragmented packets MUST set
Fragment Countto1(Packet IDandFragment IDare ignored). - Fragmented packets MUST share
Packet IDacross all fragments; receivers MUST buffer until all fragments arrive and MUST discard the entire packet if any fragment is lost.
6. Congestion Control Signaling¶
Endpoints exchange receive-rate ceilings via Hysteria-CC-RX during authentication:
- Client sends its maximum receive rate in the request header.
- Server sends its maximum receive rate in the response header.
Special values:
- Client sends
0: Client receive ceiling is unknown; the server MUST use standard congestion control (e.g., BBR, Cubic). - Server sends
0: Server imposes no bandwidth cap; the client MAY transmit at any rate. - Server sends
"auto": Server declines to specify a cap; the client MUST manage its sending rate autonomously via standard congestion control.
7. Salamander Obfuscation (Optional)¶
Hysteria 2 defines an OPTIONAL obfuscation layer codenamed Salamander that wraps every underlying QUIC UDP packet when enabled.
7.1. Encapsulation Format¶
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Salt (8B) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Obfuscated Payload... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7.2. Obfuscation Algorithm¶
For each outgoing QUIC packet:
- Generate a random 8-byte
Salt. - Compute a 32-byte BLAKE2b-256 digest over the Pre-Shared Key (PSK) concatenated with
Salt:hash = BLAKE2b-256(PSK || Salt). - XOR the original QUIC packet bytes cyclically with the 32-byte hash:
7.3. Deobfuscation Algorithm¶
For each incoming packet:
- Split the leading 8-byte
SaltfromObfuscated Payload. - Compute the same 32-byte BLAKE2b-256 digest using the local PSK and extracted
Salt. - Apply the identical cyclic XOR operation to recover the payload.
- If the recovered bytes are not a valid QUIC packet, silently discard the packet.
8. Security Considerations¶
- Confidentiality and integrity rely on the underlying QUIC (TLS 1.3) transport; clients SHOULD verify server certificates to prevent interception of
Hysteria-Authcredentials. - Salamander obscures QUIC packet headers against passive fingerprinting and does not provide cryptographic confidentiality or integrity.
- Servers SHOULD bound concurrent UDP sessions, fragment reassembly buffers, and connection counts to mitigate memory exhaustion and UDP amplification abuse.
9. References¶
- [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
- [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, May 2017.
- [RFC9000] Iyengar, J., Ed., and M. Thomson, Ed., "QUIC: A UDP-Based Multiplexed and Secure Transport", RFC 9000, May 2021.
- [RFC9114] Bishop, M., Ed., "HTTP/3", RFC 9114, June 2022.
- [RFC9221] Pauly, T., Kinnear, E., and D. Schinazi, "An Unreliable Datagram Extension to QUIC", RFC 9221, March 2022.