From 40d10a846fd84ede8d936b93dc0c0cd06db9292a Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 27 Jun 2026 23:52:17 +0800 Subject: [PATCH] fix: URL-encode share link params for v2rayNG SNI parsing Co-authored-by: Cursor --- panel/links.py | 14 ++++++++++++-- scripts/render-client.sh | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/panel/links.py b/panel/links.py index 4f4f3c9..f688d0d 100644 --- a/panel/links.py +++ b/panel/links.py @@ -21,6 +21,13 @@ def load_env() -> dict[str, str]: return env +def _qs(value: str) -> str: + """URL-encode query / userinfo values for share links.""" + # quote() leaves unreserved chars like '.' unencoded; some clients (v2rayNG) + # misparsed sni=www.microsoft.com — force dots encoded for compatibility. + return quote(value, safe="").replace(".", "%2E") + + def build_links(node: dict, env: dict | None = None) -> dict[str, str]: env = env or load_env() vps_ip = env["VPS_IP"] @@ -34,8 +41,11 @@ def build_links(node: dict, env: dict | None = None) -> dict[str, str]: vless = ( f"vless://{node['uuid']}@{vps_ip}:443" f"?encryption=none&flow=xtls-rprx-vision&security=reality" - f"&sni={reality_sni}&fp=chrome&pbk={public_key}&sid={short_id}" + f"&sni={_qs(reality_sni)}&fp=chrome&pbk={_qs(public_key)}&sid={_qs(short_id)}" f"&spx=%2F&type=tcp#{name}" ) - hy2 = f"hy2://{node['hy2_password']}@{domain}:{port}?sni={domain}#{name}-Hy2" + hy2 = ( + f"hy2://{_qs(node['hy2_password'])}@{domain}:{port}" + f"?sni={_qs(domain)}#{name}-Hy2" + ) return {"vless": vless, "hy2": hy2} diff --git a/scripts/render-client.sh b/scripts/render-client.sh index 3e9cb86..f7e9cf2 100644 --- a/scripts/render-client.sh +++ b/scripts/render-client.sh @@ -17,6 +17,16 @@ done mkdir -p "$OUT_DIR" +urlencode() { + python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe='').replace('.', '%2E'))" "$1" +} + +REALITY_SNI_ENC="$(urlencode "$REALITY_SERVER_NAME")" +REALITY_PBK_ENC="$(urlencode "$REALITY_PUBLIC_KEY")" +REALITY_SID_ENC="$(urlencode "$REALITY_SHORT_ID")" +HY2_PASSWORD_ENC="$(urlencode "$HY2_PASSWORD")" +DOMAIN_SNI_ENC="$(urlencode "$DOMAIN")" + sed -e "s|\${VPS_IP}|${VPS_IP}|g" \ -e "s|\${DOMAIN}|${DOMAIN}|g" \ -e "s|\${UUID}|${UUID}|g" \ @@ -28,10 +38,10 @@ sed -e "s|\${VPS_IP}|${VPS_IP}|g" \ cat > "$OUT_DIR/share-links.txt" <