XTLS / Xray-core

Xray, Penetrates Everything. Also the best v2ray-core, with XTLS support. Fully compatible configuration.
https://t.me/projectXray
Mozilla Public License 2.0
24.19k stars 3.8k forks source link

[BUG] Cloudflare WS on Xray 1.8.10 #3280

Closed X-Oracle closed 4 months ago

X-Oracle commented 4 months ago

Hi @yuhan6665 .

I have problem with WS connection when suing Cloudflare-CDN or Cloudflare-worker-relays when using 1.8.10. I investigated the problem, and I figured out that 7e3a8d3a04fe94de544184353a2545b2f269c34e commit is the problem (when I build e2302b421c89195ea7b7a1f5389bae2e74623314. it connects)

as I think the code may be the problem I decided to make an issue.

Log: well surprisingly no error showed even in debug level.

config I used: normal config available in Xray examples.

PS: it connects if it is a direct connection.

yuhan6665 commented 4 months ago

What is your client version, server version? Please post your config

X-Oracle commented 4 months ago

What is your client version, server version? Please post your config

OK.

Client:

Server:

config

{
  "log": {
    "loglevel": "debug"
  },
  "inbounds": [
    {
      "listen": null,
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "email": "EMAIL",
            "flow": "",
            "id": "UUID"
          }
        ],
        "decryption": "none",
        "fallbacks": []
      },
      "sniffing": {
        "destOverride": [
          "http",
          "tls"
        ],
        "enabled": true
      },
      "streamSettings": {
        "network": "ws",
        "security": "none",
        "wsSettings": {
          "acceptProxyProtocol": false,
          "headers": {},
          "host": "SUBDOMAIN.workers.dev",
          "path": "PATH"
        }
      },
      "tag": "in-443"
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {},
      "tag": "blocked"
    }
  ],
  "policy": {
    "levels": {
      "0": {
        "statsUserDownlink": true,
        "statsUserUplink": true
      }
    },
    "system": {
      "statsInboundDownlink": true,
      "statsInboundUplink": true
    }
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked",
        "type": "field"
      },
      {
        "outboundTag": "blocked",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      }
    ]
  },
  "stats": {}
}

this only works when built using https://github.com/XTLS/Xray-core/commit/e2302b421c89195ea7b7a1f5389bae2e74623314 and older

PS: here is header generated by worker-relay for sending request to my server:

{
            "accept-encoding": "gzip, br",
            "cf-connecting-ip": "IP",
            "cf-ipcountry": "DE",
            "cf-ray": "CF_RAY",
            "cf-visitor": "{\"scheme\":\"https\"}",
            "connection": "Upgrade",
            "host": "SUBDOMAIN.workers.dev",
            "sec-websocket-key": "SEC_WS_KEY",
            "sec-websocket-version": "13",
            "upgrade": "websocket",
            "user-agent": "USER_AGENT",
            "x-forwarded-proto": "https",
            "x-real-ip": "IP"
}
yuhan6665 commented 4 months ago

Try remove host setting in

        "wsSettings": {
          "acceptProxyProtocol": false,
          "headers": {},
          "host": "SUBDOMAIN.workers.dev",
          "path": "PATH"
        }
X-Oracle commented 4 months ago

Try remove host setting in

        "wsSettings": {
          "acceptProxyProtocol": false,
          "headers": {},
          "host": "SUBDOMAIN.workers.dev",
          "path": "PATH"
        }

Oh right I forgot to mention. It works when I don't fill host field in server config.

PS: filling host field or adding host header has the same result.

Fangliding commented 4 months ago

或许应该把ws里校验host的部分移除掉算了 这种问题见到有人说不是一次两次了 不过这个请求看起来正确发送了host才对啊 翻了一下代码 这个校验会不会存在大小写问题? 顺便要不在代码里加上日志输出 Want host a.com but received b.com 这样的输出方便确定问题?

yuhan6665 commented 4 months ago

日志加了 @X-Oracle 1.8.10 added new logic to validate ws host. It is expected and consistent behavior with other transport.