Skip to content

Commit 9c0ba5b

Browse files
committed
fix: protect safety-critical keys from advancedJson override
advancedJson is merged last, so a user could override FD_CONTROL_UNIX_SOCKET / LISTEN_IP / LISTEN_PORT / PROTOCOL_TYPE / SOCKS5_AUTH and silently break VPN-mode socket protection or the loopback SOCKS contract. Skip those keys (logged) so the override can only set tuning fields.
1 parent ed5e20b commit 9c0ba5b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

app/src/main/java/io/nekohasekai/sagernet/fmt/masterdnsvpn/MasterDnsVpnFmt.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,22 @@ fun MasterDnsVpnBean.buildMasterDnsVpnConfig(port: Int, protectPath: String): St
7171
put("FD_CONTROL_UNIX_SOCKET", protectPath)
7272
}
7373

74-
// Merge the advanced JSON override last so it can set/replace any key.
74+
// Merge the advanced JSON override last so it can set/replace tuning keys, but never
75+
// safety-critical ones: the protect socket and the loopback SOCKS listener must stay
76+
// as generated, or VPN-mode socket protection / routing would silently break.
7577
if (advancedJson.isNotBlank()) {
7678
// Malformed override JSON must not crash config generation / VPN start.
7779
try {
80+
val protectedKeys = setOf(
81+
"FD_CONTROL_UNIX_SOCKET", "LISTEN_IP", "LISTEN_PORT",
82+
"PROTOCOL_TYPE", "SOCKS5_AUTH",
83+
)
7884
val extra = JSONObject(advancedJson)
7985
for (key in extra.keys()) {
86+
if (key in protectedKeys) {
87+
Logs.w("MasterDnsVPN: ignoring protected key '$key' in advanced JSON override")
88+
continue
89+
}
8090
cfg.put(key, extra.get(key))
8191
}
8292
} catch (e: Exception) {

0 commit comments

Comments
 (0)