libXray icon indicating copy to clipboard operation
libXray copied to clipboard

Incorrect json generation from vless url

Open popovme opened this issue 7 months ago • 5 comments

Hello I used xray-core v25.6.8, libXray commit from 06.04.2025

vless examle: vless://[email protected]:12345?encryption=none&type=tcp#my-vless

The json output generated by the method CGoConvertShareLinksToXrayJson (.xcframework) is as follows:

{
  "api" : null,
  "inbounds" : null,
  "outbounds" : [
    {
      "protocol" : "vless",
      "mux" : null,
      "sendThrough" : "my-vless",
      "tag" : "",
      "streamSettings" : {
        "splithttpSettings" : null,
        "tlsSettings" : null,
        "tcpSettings" : null,
        "xhttpSettings" : null,
        "kcpSettings" : null,
        "wsSettings" : null,
        "httpupgradeSettings" : null,
        "sockopt" : null,
        "rawSettings" : null,
        "address" : null,
        "security" : "none",
        "grpcSettings" : null,
        "network" : "tcp",
        "realitySettings" : null,
        "port" : 0
      },
      "proxySettings" : null,
      "settings" : {
        "vnext" : [
          {
            "address" : "host-xxx.example.com",
            "users" : [
              {
                "id" : "123e4567-e89b-12d3-a456-4266xxxxxxx",
                "encryption" : "none"
              }
            ],
            "port" : 12345
          }
        ]
      }
    }
  ],
  "metrics" : null,
  "transport" : null,
  "burstObservatory" : null,
  "stats" : null,
  "routing" : null,
  "observatory" : null,
  "reverse" : null,
  "fakeDns" : null,
  "dns" : null,
  "log" : null,
  "policy" : null
}

LibXray produces incorrect JSON where the URL fragment (the part after #) is placed into the "sendThrough" field: "sendThrough": "my-vless"

LibXray run result: failed to build outbound config with tag infra/conf: unable to send through: my-vless

Also the result is very different from previous versions of LibXray, why so many null parameters? For example, the old version of the CGoConvertShareLinksToXrayJson method returned this result, and json works successfully:

{
  "outbounds" : [
    {
      "protocol" : "vless",
      "name" : "my-vless",
      "settings" : {
        "vnext" : [
          {
            "address" : "host-xxx.example.com",
            "users" : [
              {
                "id" : "123e4567-e89b-12d3-a456-4266xxxxxxx",
                "encryption" : "none"
              }
            ],
            "port" : 12345
          }
        ]
      },
      "streamSettings" : {
        "network" : "tcp",
        "security" : "none"
      }
    }
  ]
}

popovme avatar Jun 09 '25 15:06 popovme

It only parses the uri to xray outbound possibly. so you need to create the inbound and other null fields on your own as shown on test cases

codewithtamim avatar Jun 09 '25 17:06 codewithtamim

It only parses the uri to xray outbound possibly. so you need to create the inbound and other null fields on your own as shown on test cases

I understand, but "sendThrough" : "my-vless" is definitely not correct.

popovme avatar Jun 09 '25 17:06 popovme

libXray uses "sendThrough" to store the config name. It is designed by purpose. There is not "name" field in Outbound config. You should deal with it before sending the final config to Xray-core.

yiguodev avatar Jun 10 '25 00:06 yiguodev

libXray uses "sendThrough" to store the config name. It is designed by purpose. There is not "name" field in Outbound config. You should deal with it before sending the final config to Xray-core.

I don't understand where I can read this? I found this in the documentation: sendThrough: address The IP address used to send data. It is effective when the host has multiple IP addresses, and the default value is "0.0.0.0".

popovme avatar Jun 10 '25 11:06 popovme

I know how this field should be used. The current implementation is a last resort. The best solution is to add a name field in XrayConfig. However, Xray-core refuses to accept this implementation. After libXray parses the share link, it will return XrayJson. You should read sendThrough from it, get the config name, and then set sendThrough to null.

yiguodev avatar Jun 10 '25 11:06 yiguodev