```
feat: 增强URL基础地址验证功能 - 在app-instance/frontend/lib/api.ts中实现更严格的URL验证逻辑, 包括检查是否以斜杠开头、包含空格字符,以及使用URL构造函数进行验证 - 在app-instance/frontend/lib/auth-portal.ts中应用相同的URL验证改进, 提升认证门户的基础地址处理安全性 - 在auth-portal/src/lib/auth-client.ts中增强前端跳转URL构建功能, 添加错误处理机制并在URL构造失败时抛出相应异常 - 统一三个文件中的normalizeBaseUrl函数实现,确保一致的输入验证行为 ```
This commit is contained in:
@ -19,7 +19,15 @@ export interface ProviderOnboardingPayload {
|
||||
function normalizeBaseUrl(value?: string | null): string | null {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) return null;
|
||||
return trimmed.replace(/\/+$/, '');
|
||||
if (trimmed.startsWith('/') || /\s/.test(trimmed)) return null;
|
||||
const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed);
|
||||
const candidate = hasScheme ? trimmed : `http://${trimmed}`;
|
||||
try {
|
||||
const url = new URL(candidate);
|
||||
return url.toString().replace(/\/+$/, '');
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getFrontendBaseUrl(response: TokenResponse): string | null {
|
||||
@ -110,7 +118,12 @@ export function buildFrontendHandoffUrl(response: TokenResponse, nextPath: strin
|
||||
throw new Error(pickPortalText(locale, '后端未返回 handoff code', 'Backend did not return a handoff code'));
|
||||
}
|
||||
|
||||
const url = new URL('/handoff', frontendBaseUrl);
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL('/handoff', frontendBaseUrl);
|
||||
} catch {
|
||||
throw new Error(pickPortalText(locale, '目标前端地址格式无效', 'Target frontend URL is invalid'));
|
||||
}
|
||||
url.searchParams.set('code', handoffCode);
|
||||
if (nextPath) {
|
||||
url.searchParams.set('next', nextPath);
|
||||
|
||||
Reference in New Issue
Block a user