From 7410b80e7accecadc9ffeac98fe8bc1ddbed7b7f Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sat, 25 Nov 2023 16:11:26 +0100 Subject: [PATCH] optimize security in front codes --- web/assets/js/model/xray.js | 106 +------- web/html/common/qrcode_modal.html | 2 +- web/html/xui/form/protocol/trojan.html | 2 +- web/html/xui/form/protocol/vless.html | 2 +- web/html/xui/form/tls_settings.html | 326 +++++++++++++------------ web/html/xui/inbound_info_modal.html | 6 +- web/html/xui/inbound_modal.html | 4 +- web/translation/translate.en_US.toml | 15 ++ web/translation/translate.fa_IR.toml | 16 ++ web/translation/translate.ru_RU.toml | 15 ++ web/translation/translate.zh_Hans.toml | 15 ++ 11 files changed, 243 insertions(+), 266 deletions(-) diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index a8ef47c8..fdaeef97 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -8,13 +8,6 @@ const Protocols = { HTTP: 'http', }; -const VmessMethods = { - AES_128_GCM: 'aes-128-gcm', - CHACHA20_POLY1305: 'chacha20-poly1305', - AUTO: 'auto', - NONE: 'none', -}; - const SSMethods = { AES_256_GCM: 'aes-256-gcm', AES_128_GCM: 'aes-128-gcm', @@ -86,7 +79,6 @@ const SNIFFING_OPTION = { }; Object.freeze(Protocols); -Object.freeze(VmessMethods); Object.freeze(SSMethods); Object.freeze(TLS_FLOW_CONTROL); Object.freeze(TLS_VERSION_OPTION); @@ -413,7 +405,7 @@ class HttpStreamSettings extends XrayCommonClass { } class QuicStreamSettings extends XrayCommonClass { - constructor(security=VmessMethods.NONE, + constructor(security='none', key='', type='none') { super(); this.security = security; @@ -856,30 +848,6 @@ class Inbound extends XrayCommonClass { } } - get tls() { - return this.stream.security === 'tls'; - } - - set tls(isTls) { - if (isTls) { - this.stream.security = 'tls'; - } else { - this.stream.security = 'none'; - } - } - - get reality() { - return this.stream.security === 'reality'; - } - - set reality(isReality) { - if (isReality) { - this.stream.security = 'reality'; - } else { - this.stream.security = 'none'; - } - } - get network() { return this.stream.network; } @@ -1005,85 +973,29 @@ class Inbound extends XrayCommonClass { } canEnableTls() { - switch (this.protocol) { - case Protocols.VMESS: - case Protocols.VLESS: - case Protocols.TROJAN: - break; - default: - return false; - } - - switch (this.network) { - case "tcp": - case "ws": - case "http": - case "quic": - case "grpc": - return true; - default: - return false; - } + if(![Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; + return ["tcp", "ws", "http", "quic", "grpc"].includes(this.network); } //this is used for xtls-rprx-vision canEnableTlsFlow() { if ((this.stream.security != 'none') && (this.network === "tcp")) { - switch (this.protocol) { - case Protocols.VLESS: - return true; - default: - return false; - } + return this.protocol === Protocols.VLESS; } return false; } - canSetTls() { - return this.canEnableTls(); - } - canEnableReality() { - switch (this.protocol) { - case Protocols.VLESS: - case Protocols.TROJAN: - break; - default: - return false; - } - - switch (this.network) { - case "tcp": - case "http": - case "grpc": - return true; - default: - return false; - } + if(![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; + return ["tcp", "http", "grpc"].includes(this.network); } canEnableStream() { - switch (this.protocol) { - case Protocols.VMESS: - case Protocols.VLESS: - case Protocols.TROJAN: - case Protocols.SHADOWSOCKS: - return true; - default: - return false; - } + return [Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol); } canSniffing() { - switch (this.protocol) { - case Protocols.VMESS: - case Protocols.VLESS: - case Protocols.TROJAN: - case Protocols.SHADOWSOCKS: - return true; - default: - return false; - } + return [Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol); } reset() { @@ -1485,7 +1397,7 @@ class Inbound extends XrayCommonClass { toJson() { let streamSettings; - if (this.canEnableStream() || this.protocol === Protocols.TROJAN) { + if (this.canEnableStream()) { streamSettings = this.stream.toJson(); } return { diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index ce07907b..4d237edb 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -38,7 +38,7 @@ address = this.dbInbound.address; this.subId = ''; this.qrcodes = []; - if (this.inbound.tls && !ObjectUtil.isArrEmpty(this.inbound.stream.tls.settings.domains)) { + if (this.inbound.stream.isTls && !ObjectUtil.isArrEmpty(this.inbound.stream.tls.settings.domains)) { this.inbound.stream.tls.settings.domains.forEach((domain) => { remarkText = [remark, domain.remark].filter(Boolean).join('-'); this.qrcodes.push({ diff --git a/web/html/xui/form/protocol/trojan.html b/web/html/xui/form/protocol/trojan.html index c550ed43..8031de58 100644 --- a/web/html/xui/form/protocol/trojan.html +++ b/web/html/xui/form/protocol/trojan.html @@ -19,7 +19,7 @@ -