Skip to content

XHTTP server: Accept OPTIONS as uplinkHTTPMethod - #7290

Merged
RPRX merged 1 commit into
XTLS:mainfrom
konstpic:xhttp-options-uplink
Oct 31, 2026
Merged

RPRX merged 1 commit into
XTLS:mainfrom
konstpic:xhttp-options-uplink

Conversation

@konstpic

Copy link
Copy Markdown
Contributor

uplinkHTTPMethod accepts any method except GET outside packet-up (infra/conf/transport_method.go), and the client sends the configured method as is. So "uplinkHTTPMethod": "OPTIONS" passes config validation, but the server never processes such a request.

Cause. requestHandler.ServeHTTP answers every OPTIONS request with 200 right after writing the padding/CORS headers, treating it as a CORS preflight. An uplink request sent with OPTIONS is dropped there, so its body is never read and the session stalls.

Change. Treat OPTIONS as a preflight only when it carries Access-Control-Request-Method, which every browser preflight has. Any other OPTIONS request goes through the normal uplink handling (the existing code already treats every non-GET method as an uplink). Behaviour for POST/PUT/GET and for real preflights is unchanged. No config or protocol change; clients need no update.

Tests (transport/internet/splithttp):

  • Test_UplinkHTTPMethodOptions: echo over packet-up, stream-up, stream-one and auto, plain and TLS, with POST, PUT and OPTIONS. Without the change OPTIONS times out or gets EOF in every mode; with it all pass (also 20x with -race).
  • Test_CORSPreflightStillAnswered: a preflight with Access-Control-Request-Method still gets 200 and Access-Control-Allow-Methods.
  • Test_ServerMaxHeaderBytes: oversized headers are rejected with 431 (this setting had no test).

Also checked end to end with real binaries: VLESS+XHTTP packet-up, uplinkHTTPMethod: OPTIONS, unmodified client against the patched server returns data; the same config against an unpatched server does not.

go run ./infra/vformat/main.go -mode check -pwd ./, go run ./infra/vprotogen/main.go -mode check -pwd ./ and go test ./... pass locally (macOS arm64; the TLS cases of the new test were run with the package's arm64 skip lifted).

@Fangliding

Copy link
Copy Markdown
Member

GET够了吧 OPTIONS 更奇怪了

@Fangliding Fangliding closed this Oct 29, 2026
@konstpic

Copy link
Copy Markdown
Contributor Author

Thanks for looking at this. Not trying to reopen, just a few facts in case they change the picture.

Why a non-POST method matters. Yandex Cloud CDN allows only GET, HEAD and OPTIONS for client requests by default; POST, PUT, PATCH and DELETE are unavailable unless support enables them (docs). Behind such a CDN the default XHTTP uplink (POST) is rejected with 405. Our panel users hit exactly this.

Why GET is not enough.

  • GET is only allowed in packet-up (uplinkHTTPMethod can be GET only in packet-up mode), so in stream-up / stream-one there is no uplink method left that such a CDN passes.
  • GET carries the data in headers/cookies in 2–3 KiB chunks, and the server already needs Cache-Control: no-store for bodiless requests because they get cached. OPTIONS carries a body like POST.

What the change does. Today uplinkHTTPMethod: "OPTIONS" passes config validation, but the server answers 200 as a CORS preflight and silently drops the data. The change treats OPTIONS as a preflight only when Access-Control-Request-Method is present. Tested in packet-up, stream-up, stream-one and auto, plain and TLS. If OPTIONS is not wanted, I would rather make config validation reject it with a clear error than leave a silent failure, and can send that instead.

@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

可以加

@RPRX RPRX reopened this Oct 29, 2026
@RPRX RPRX changed the title XHTTP transport: Accept OPTIONS as uplinkHTTPMethod XHTTP server: Accept OPTIONS as uplinkHTTPMethod Oct 31, 2026
@RPRX
RPRX merged commit 89a26d1 into XTLS:main Oct 31, 2026
39 checks passed
legiz-ru added a commit to legiz-ru/Prizrak-Core that referenced this pull request Nov 1, 2026
- The HTTP/2 client transport dials one connection at a time
  (MaxConnsPerHost 1). Requests that start together used to open a
  connection each: 16 requests on a fresh transport made 13 connections,
  and 16 while a TLS handshake hung made 16 (XTLS/Xray-core#6797). That
  burst of handshakes is a pattern censors look for and it went past
  reuse-settings max-connections. They now share one dial; more
  connections open only when the server's stream limit is reached.
- packet-up requests set GetBody, so HTTP/2 can send a packet again on a
  new connection after a GOAWAY instead of failing it
  (XTLS/Xray-core#6632).
- The server takes an OPTIONS request without
  Access-Control-Request-Method as an upload, as Xray does since
  XTLS/Xray-core#7290; before, every OPTIONS was answered as a CORS
  preflight and uplink-http-method OPTIONS did not work.
legiz-ru added a commit to legiz-ru/Prizrak-Core that referenced this pull request Nov 2, 2026
- The HTTP/2 client transport dials one connection at a time
  (MaxConnsPerHost 1). Requests that start together used to open a
  connection each: 16 requests on a fresh transport made 13 connections,
  and 16 while a TLS handshake hung made 16 (XTLS/Xray-core#6797). That
  burst of handshakes is a pattern censors look for and it went past
  reuse-settings max-connections. They now share one dial; more
  connections open only when the server's stream limit is reached.
- packet-up requests set GetBody, so HTTP/2 can send a packet again on a
  new connection after a GOAWAY instead of failing it
  (XTLS/Xray-core#6632).
- The server takes an OPTIONS request without
  Access-Control-Request-Method as an upload, as Xray does since
  XTLS/Xray-core#7290; before, every OPTIONS was answered as a CORS
  preflight and uplink-http-method OPTIONS did not work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants