Skip to content

Commit 9ddbefe

Browse files
perf: Multi-domain validation in embedded systems uses semicolon delimiters
1 parent a6744dd commit 9ddbefe

File tree

6 files changed

+56
-44
lines changed

6 files changed

+56
-44
lines changed

backend/common/utils/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datetime import datetime, timedelta, timezone
77
from logging.handlers import RotatingFileHandler
88
from pathlib import Path
9+
import re
910
from urllib.parse import urlparse
1011

1112
from fastapi import Request
@@ -266,9 +267,14 @@ def get_origin_from_referer(request: Request):
266267
def origin_match_domain(origin: str, domain: str) -> bool:
267268
if not origin or not domain:
268269
return False
269-
origin_text = origin.rstrip('/')
270-
domain_list = domain.replace(" ", "").split(',')
271-
return origin_text in [d.rstrip('/') for d in domain_list]
270+
origin_normalized = origin.rstrip('/')
271+
272+
for d in re.split(r'[,;]', domain):
273+
if d.strip().rstrip('/') == origin_normalized:
274+
return True
275+
276+
return False
277+
272278

273279
def equals_ignore_case(str1: str, *args: str) -> bool:
274280
if str1 is None:

frontend/src/i18n/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@
577577
"application_name": "Application name",
578578
"application_description": "Application description",
579579
"cross_domain_settings": "Cross-domain settings",
580-
"third_party_address": "Please enter the embedded third party address",
580+
"third_party_address": "Please enter the embedded third party address,multiple items separated by semicolons",
581581
"set_to_private": "Set as private",
582582
"set_to_public": "Set as public",
583583
"public": "Public",
@@ -586,7 +586,7 @@
586586
"configure_interface": "Configure interface",
587587
"interface_url": "Interface URL",
588588
"format_is_incorrect": "format is incorrect{msg}",
589-
"domain_format_incorrect": ",start with http/https, no trailing slash (/), multiple domains separated by half-width commas (,)",
589+
"domain_format_incorrect": ", start with http:// or https://, no trailing slash (/), multiple domains separated by semicolons",
590590
"interface_url_incorrect": ",enter a relative path starting with /",
591591
"aes_enable": "Enable AES encryption",
592592
"aes_enable_tips": "The fields (host, user, password, dataBase, schema) are all encrypted using the AES-CBC-PKCS5Padding encryption method",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@
577577
"application_name": "애플리케이션 이름",
578578
"application_description": "애플리케이션 설명",
579579
"cross_domain_settings": "교차 도메인 설정",
580-
"third_party_address": "임베디드할 제3자 주소를 입력하십시오",
580+
"third_party_address": "임베디드할 제3자 주소를 입력하십시오, 여러 항목을 세미콜론으로 구분",
581581
"set_to_private": "비공개로 설정",
582582
"set_to_public": "공개로 설정",
583583
"public": "공개",
584584
"private": "비공개",
585585
"configure_interface": "인터페이스 설정",
586586
"interface_url": "인터페이스 URL",
587587
"format_is_incorrect": "형식이 올바르지 않습니다{msg}",
588-
"domain_format_incorrect": ", http/https로 시작, 슬래시(/)로 끝나지 않음, 여러 도메인은 반각 쉼표(,)로 구분",
588+
"domain_format_incorrect": ", http:// 또는 https://로 시작해야 하며, 슬래시(/)로 끝날 수 없습니다. 여러 도메인은 세미콜론으로 구분합니다",
589589
"interface_url_incorrect": ", 상대 경로를 입력해주세요. /로 시작합니다",
590590
"aes_enable": "AES 암호화 활성화",
591591
"aes_enable_tips": "암호화 필드 (host, user, password, dataBase, schema)는 모두 AES-CBC-PKCS5Padding 암호화 방식을 사용합니다",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@
577577
"application_name": "应用名称",
578578
"application_description": "应用描述",
579579
"cross_domain_settings": "跨域设置",
580-
"third_party_address": "请输入嵌入的第三方地址",
580+
"third_party_address": "请输入嵌入的第三方地址,多个以分号分割",
581581
"set_to_private": "设为私有",
582582
"set_to_public": "设为公共",
583583
"public": "公共",
584584
"private": "私有",
585585
"configure_interface": "配置接口",
586586
"interface_url": "接口 URL",
587587
"format_is_incorrect": "格式不对{msg}",
588-
"domain_format_incorrect": ",http或https开头,不能以 / 结尾,多个域名以逗号(半角)分隔",
588+
"domain_format_incorrect": ",http或https开头,不能以 / 结尾,多个域名以分号(半角)分隔",
589589
"interface_url_incorrect": ",请填写相对路径,以/开头",
590590
"aes_enable": "开启 AES 加密",
591591
"aes_enable_tips": "加密字段 (host, user, password, dataBase, schema) 均采用 AES-CBC-PKCS5Padding 加密方式",

frontend/src/views/system/embedded/Page.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,15 @@ const search = () => {
198198
searchLoading.value = false
199199
})
200200
}
201-
201+
const splitString = (str: string) => {
202+
if (typeof str !== 'string') {
203+
return []
204+
}
205+
return str
206+
.split(/[,;]/)
207+
.map((item) => item.trim())
208+
.filter((item) => item !== '')
209+
}
202210
const termFormRef = ref()
203211
const validateUrl = (_: any, value: any, callback: any) => {
204212
if (value === '') {
@@ -209,20 +217,15 @@ const validateUrl = (_: any, value: any, callback: any) => {
209217
)
210218
} else {
211219
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
212-
value
213-
.trim()
214-
.split(',')
215-
.forEach((tempVal: string) => {
216-
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
217-
var objExp = new RegExp(Expression)
218-
if (objExp.test(tempVal) && !tempVal.endsWith('/')) {
219-
callback()
220-
} else {
221-
callback(
222-
t('embedded.format_is_incorrect', { msg: t('embedded.domain_format_incorrect') })
223-
)
224-
}
225-
})
220+
splitString(value).forEach((tempVal: string) => {
221+
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
222+
var objExp = new RegExp(Expression)
223+
if (objExp.test(tempVal) && !tempVal.endsWith('/')) {
224+
callback()
225+
} else {
226+
callback(t('embedded.format_is_incorrect', { msg: t('embedded.domain_format_incorrect') }))
227+
}
228+
})
226229
}
227230
}
228231
const rules = {
@@ -602,13 +605,10 @@ const copyCode = (row: any, key: any = 'app_secret') => {
602605
<el-form-item prop="domain" :label="t('embedded.cross_domain_settings')">
603606
<el-input
604607
v-model="pageForm.domain"
605-
:placeholder="
606-
$t('datasource.please_enter') +
607-
$t('common.empty') +
608-
$t('embedded.cross_domain_settings')
609-
"
608+
type="textarea"
609+
:autosize="{ minRows: 2 }"
610+
:placeholder="$t('embedded.third_party_address')"
610611
autocomplete="off"
611-
maxlength="50"
612612
clearable
613613
/>
614614
</el-form-item>

frontend/src/views/system/embedded/iframe.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ const setUiRef = ref()
265265
const handleSetUi = (row: any) => {
266266
setUiRef.value.open(row)
267267
}
268+
const splitString = (str: string) => {
269+
if (typeof str !== 'string') {
270+
return []
271+
}
272+
return str
273+
.split(/[,;]/)
274+
.map((item) => item.trim())
275+
.filter((item) => item !== '')
276+
}
268277
const validateUrl = (_: any, value: any, callback: any) => {
269278
if (value === '') {
270279
callback(
@@ -274,20 +283,15 @@ const validateUrl = (_: any, value: any, callback: any) => {
274283
)
275284
} else {
276285
// var Expression = /(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?/ // eslint-disable-line
277-
value
278-
.trim()
279-
.split(',')
280-
.forEach((tempVal: string) => {
281-
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
282-
var objExp = new RegExp(Expression)
283-
if (objExp.test(tempVal) && !tempVal.endsWith('/')) {
284-
callback()
285-
} else {
286-
callback(
287-
t('embedded.format_is_incorrect', { msg: t('embedded.domain_format_incorrect') })
288-
)
289-
}
290-
})
286+
splitString(value).forEach((tempVal: string) => {
287+
var Expression = /^https?:\/\/[^\s/?#]+(:\d+)?/i
288+
var objExp = new RegExp(Expression)
289+
if (objExp.test(tempVal) && !tempVal.endsWith('/')) {
290+
callback()
291+
} else {
292+
callback(t('embedded.format_is_incorrect', { msg: t('embedded.domain_format_incorrect') }))
293+
}
294+
})
291295
}
292296
}
293297
const rules = {
@@ -759,6 +763,8 @@ const saveHandler = () => {
759763
<el-form-item prop="domain" :label="t('embedded.cross_domain_settings')">
760764
<el-input
761765
v-model="currentEmbedded.domain"
766+
type="textarea"
767+
:autosize="{ minRows: 2 }"
762768
clearable
763769
:placeholder="$t('embedded.third_party_address')"
764770
autocomplete="off"

0 commit comments

Comments
 (0)