fix (proxy-parser): ws-headers with multiple keys are not correctly handled when parsing Surge proxies

closes #120
This commit is contained in:
Peng-YM 2022-06-24 18:01:25 +08:00
parent 730986fed4
commit 305ae480bc
6 changed files with 28 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.1.2",
"version": "2.1.3",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -24,7 +24,7 @@ const grammars = String.raw`
if (obfs.type === "ws") {
proxy.network = "ws";
$set(proxy, "ws-opts.path", obfs.path);
$set(proxy, "ws-opts.headers.Host", obfs.host);
$set(proxy, "ws-opts.headers", obfs['ws-headers']);
}
}
}
@ -158,8 +158,14 @@ method = comma "encrypt-method" equals cipher:cipher {
cipher = ("aes-128-gcm"/"aes-192-gcm"/"aes-256-gcm"/"aes-128-cfb"/"aes-192-cfb"/"aes-256-cfb"/"aes-128-ctr"/"aes-192-ctr"/"aes-256-ctr"/"rc4-md5"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none");
ws = comma "ws" equals flag:bool { obfs.type = "ws"; }
ws_headers = comma "ws-headers" equals "Host:" host:domain {
obfs.host = host;
ws_headers = comma "ws-headers" equals headers:$[^,]+ {
const pairs = headers.split("|");
const result = {};
pairs.forEach(pair => {
const [key, value] = pair.trim().split(":");
result[key.trim()] = value.trim();
})
obfs["ws-headers"] = result;
}
ws_path = comma "ws-path" equals path:uri { obfs.path = path; }

View File

@ -22,7 +22,7 @@
if (obfs.type === "ws") {
proxy.network = "ws";
$set(proxy, "ws-opts.path", obfs.path);
$set(proxy, "ws-opts.headers.Host", obfs.host);
$set(proxy, "ws-opts.headers", obfs['ws-headers']);
}
}
}
@ -156,8 +156,14 @@ method = comma "encrypt-method" equals cipher:cipher {
cipher = ("aes-128-gcm"/"aes-192-gcm"/"aes-256-gcm"/"aes-128-cfb"/"aes-192-cfb"/"aes-256-cfb"/"aes-128-ctr"/"aes-192-ctr"/"aes-256-ctr"/"rc4-md5"/"chacha20-ietf-poly1305"/"chacha20-ietf"/"chacha20-poly1305"/"chacha20"/"none");
ws = comma "ws" equals flag:bool { obfs.type = "ws"; }
ws_headers = comma "ws-headers" equals "Host:" host:domain {
obfs.host = host;
ws_headers = comma "ws-headers" equals headers:$[^,]+ {
const pairs = headers.split("|");
const result = {};
pairs.forEach(pair => {
const [key, value] = pair.trim().split(":");
result[key.trim()] = value.trim();
})
obfs["ws-headers"] = result;
}
ws_path = comma "ws-path" equals path:uri { obfs.path = path; }

File diff suppressed because one or more lines are too long