From 721e370ad3ed369dd6635547420ce3cd2a2be86b Mon Sep 17 00:00:00 2001 From: CityFun <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 6 Jun 2025 10:10:55 +0800 Subject: [PATCH] feat: add domain validate for appinstall webUI (#8939) Refs https://github.com/1Panel-dev/1Panel/issues/8936 --- .../app-store/installed/detail/index.vue | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/app-store/installed/detail/index.vue b/frontend/src/views/app-store/installed/detail/index.vue index 2530afebb..e26a86277 100644 --- a/frontend/src/views/app-store/installed/detail/index.vue +++ b/frontend/src/views/app-store/installed/detail/index.vue @@ -130,8 +130,8 @@ import { getAppInstallParams, updateAppInstallParams, updateInstallConfig } from import { reactive, ref } from 'vue'; import { FormInstance } from 'element-plus'; import { Rules, checkNumberRange } from '@/global/form-rules'; -import { MsgSuccess } from '@/utils/message'; -import { getLabel, splitHttp } from '@/utils/util'; +import { MsgError, MsgSuccess } from '@/utils/message'; +import { getLabel, splitHttp, checkIpV4V6, checkDomain } from '@/utils/util'; import i18n from '@/lang'; interface ParamProps { @@ -176,6 +176,31 @@ const webUI = reactive({ domain: '', }); +function checkWebUI() { + if (webUI.domain !== '') { + let domain = webUI.domain; + let port = null; + if (domain.includes(':')) { + const parts = domain.split(':'); + domain = parts[0]; + port = parts[1]; + + if (!checkPort(port)) { + return false; + } + } + if (checkIpV4V6(domain) && checkDomain(domain)) { + return false; + } + } + return true; +} + +function checkPort(port: string) { + const portNum = parseInt(port, 10); + return !isNaN(portNum) && portNum > 0 && portNum <= 65535; +} + const acceptParams = async (props: ParamProps) => { submitModel.value.installId = props.id; params.value = []; @@ -297,6 +322,10 @@ const updateAppConfig = async () => { if (!webUI.domain || webUI.domain === '') { req.webUI = ''; } + if (!checkWebUI()) { + MsgError(i18n.global.t('commons.rule.host')); + return; + } await updateInstallConfig(req); MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); handleClose();