Skip to content

Commit eb60cdd

Browse files
committed
禁用常用入口
1 parent 15e6027 commit eb60cdd

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

functions/modules/api-handler.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ export async function handleSettingsGet(env) {
243243
export async function handleSettingsSave(request, env) {
244244
try {
245245
const newSettings = await request.json();
246+
247+
// 校验 customLoginPath 是否为系统保留路径
248+
if (newSettings.customLoginPath) {
249+
const reservedPaths = ['settings', 'login', 'groups', 'nodes', 'subscriptions', 'dashboard', 'api', 'explore'];
250+
const pathSegment = newSettings.customLoginPath.replace(/^\/+/, '').split('/')[0].toLowerCase();
251+
if (reservedPaths.includes(pathSegment)) {
252+
return createJsonResponse({
253+
success: false,
254+
message: `"/${pathSegment}" 是系统保留路径,不可用作自定义登录路径`
255+
}, 400);
256+
}
257+
}
258+
246259
const storageAdapter = await getStorageAdapter(env);
247260
const oldSettings = await storageAdapter.get(KV_KEY_SETTINGS) || {};
248261
const finalSettings = { ...oldSettings, ...newSettings };

src/components/settings/sections/BasicSettings.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { useToastStore } from '../../../stores/toast';
1717
1818
const { showToast } = useToastStore();
1919
20-
// 监听自定义登录路径,禁止特殊字符和空格
20+
// 系统保留路径列表,这些路径会与前端路由或后端 API 冲突
21+
const RESERVED_PATHS = ['settings', 'login', 'groups', 'nodes', 'subscriptions', 'dashboard', 'api', 'explore'];
22+
23+
// 监听自定义登录路径,禁止特殊字符、空格和保留路径
2124
watch(() => props.settings.customLoginPath, (val) => {
2225
if (!val) return;
2326
@@ -27,6 +30,14 @@ watch(() => props.settings.customLoginPath, (val) => {
2730
if (sanitized !== val) {
2831
props.settings.customLoginPath = sanitized;
2932
showToast('路径仅允许字母、数字、下划线、中划线', 'warning');
33+
return;
34+
}
35+
36+
// 检查是否为保留路径(去除前后斜杠后比较首段)
37+
const pathSegment = sanitized.replace(/^\/+/, '').split('/')[0].toLowerCase();
38+
if (RESERVED_PATHS.includes(pathSegment)) {
39+
props.settings.customLoginPath = '';
40+
showToast(`"/${pathSegment}" 是系统保留路径,不可用作自定义登录路径`, 'error');
3041
}
3142
});
3243
@@ -212,6 +223,9 @@ watch(() => props.settings.customLoginPath, (val) => {
212223
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
213224
设置后,只有访问此路径才能进入登录页面。默认路径 <code>/login</code> 将失效(除非未设置)。
214225
</p>
226+
<p class="text-xs text-amber-600 dark:text-amber-400 mt-1">
227+
⚠️ 不可使用系统保留路径:/settings, /login, /groups, /nodes, /subscriptions, /dashboard
228+
</p>
215229
</div>
216230

217231
<div v-show="disguiseConfig.enabled"

0 commit comments

Comments
 (0)