Skip to content

[critical] xray + wireguard confuses certificates when opening multiple tabs simultaneously. #4025

@devopg

Description

@devopg

Integrity requirements

  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • I searched issues and did not find any similar issues.
  • The problem can be successfully reproduced in the latest Release

Description

v24.11.11

After 26 hours of and 5 updates (#4022) to my investigation, I found the problem!
image

The main problem is that with high parallelism, xray + wireguard are mixing up the site certificates.

Here's what the problem looks like. I opened about 30 websites simultaneously without caches. As we can see, a couple of websites returned an error stating that the certificates do not match.

The interesting thing about the error on this site is that the certificate actually belongs to a neighboring site:
image

After countless combinations and usage variations, I found a scenario in which this bug appears.

This is a variation when using the inbound WireGuard protocol + sniffing. I try with 3 clients (WG official | WireSock | ASUS WG).
image


Additional information and interesting points that will also help you understand that the problem with xray + wireguard.

  1. During the tests, I created a combination of WG Inbound with "replace IP to domain" (unchecking the "Route only" option) -> outbound to another XRAY server to VLESS Inbound. On the first server, I set a rule to block all ".ru" domains, and on the second server, I enabled logging and noticed something strange: from time to time, domains with ".ru" appeared in the logs, which should never have been there in the this place.

This indicates that the xray sniffer + WireGuard correctly identifies the domains (IP <-> DOMAIN), BUT it incorrectly processes the domains cannot properly parse the packets/frames (I'm not sure what it's called) and make the correct routing.
image

  1. Another clue that will convince you that the problem lies specifically with the xray sniffer + WireGuard.
    I replaced the WireGuard Inbound in the above setup with VLESS without changing anything else. And you know what? Everything started working perfectly; there were no ".ru" domains in the logs on SERVER2. It worked flawlessly when opening more than 100 tabs simultaneously.

image


In summary,

The problem in the parsing/processing/routing of packets/frames (I'm not sure what it's called) when using WireGuard Inbound with Sniffer. You should take a look at the piece of code that is responsible for this.

Reproduction Method

For a quick understanding of whether this has been fixed, refer to the image with two server above. The first server has WireGuard inbound with a sniffer and blocking domains like ".com," and there should be no ".com" domains in the logs on the second server. This will already be a sign that you are fixing the issue in the right place.

Client config

Details

[Interface]
PrivateKey = WBN8MdW2A=
Address = 10.0.0.2/32
DNS = 1.1.1.1, 1.0.0.1
MTU = 1420

# wg_in-1
[Peer]
PublicKey = oQRrVxhEgU=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 192.168.50.254:31108

Server config

Details

`{
  "id": 1,
  "userId": 0,
  "up": 976856060,
  "down": 19195323780,
  "total": 0,
  "remark": "wg_in",
  "enable": true,
  "expiryTime": 0,
  "listen": "",
  "port": 39108,
  "protocol": "wireguard",
  "settings": "{\n  \"mtu\": 1420,\n  \"secretKey\": \"+APdM50E=\",\n  \"peers\": [\n    {\n      \"privateKey\": \"WBN8dW2A=\",\n      \"publicKey\": \"9+IdOQtwkMxJEc=\",\n      \"allowedIPs\": [\n        \"10.0.0.2/32\"\n      ],\n      \"keepAlive\": 0\n    },\n    {\n      \"privateKey\": \"uKQ+/a1UIQnvtsWHgdZet/5B1nJtxFfm4l5FrKMHEUs=\",\n      \"publicKey\": \"gw9HqqG5GPCxk=\",\n      \"allowedIPs\": [\n        \"10.0.0.3/32\"\n      ],\n      \"keepAlive\": 0\n    }\n  ],\n  \"noKernelTun\": true\n}",
  "streamSettings": "",
  "tag": "inbound-39108",
  "sniffing": "{\n  \"enabled\": true,\n  \"destOverride\": [\n    \"http\",\n    \"tls\",\n    \"quic\"\n  ],\n  \"metadataOnly\": false,\n  \"routeOnly\": false\n}",
  "clientStats": []
}`

routing for direct domains:

[ { "type": "field", "inboundTag": [ "api" ], "outboundTag": "api" }, { "type": "field", "outboundTag": "direct", "domain": [ "geosite:category-ru", "regexp:.*\\.ru" ] }, { "type": "field", "outboundTag": "direct", "ip": [ "geoip:ru" ] } ]

Client log

Details

no errors 

Server log

Details

no errors 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions