fix(cloud): harden edge gateways, api-server ssrf, supabase fail-closed quota, and web/admin lifecycle
This commit is contained in:
parent
2a009e421a
commit
c68e81e0aa
46 changed files with 2553 additions and 294 deletions
70
apps/admin/src/lib/admin-url-safety.ts
Normal file
70
apps/admin/src/lib/admin-url-safety.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
const STATIC_ASSET_EXT_RE =
|
||||
/\.(?:ico|png|jpg|jpeg|gif|svg|webp|woff2?|ttf|eot|css|js|map|txt|xml|webmanifest)$/i
|
||||
|
||||
function hasUnsafeControlOrBackslash(value: string): boolean {
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
const code = value.charCodeAt(i)
|
||||
if (code <= 0x1f || code === 0x7f || code === 0x5c) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 콘솔 내부 경로만 허용한다.
|
||||
* `//evil.example`, `https://evil.example`, `/\evil.example`, 제어문자는 `/`로 폴백한다.
|
||||
*/
|
||||
export function safeAdminRedirectPath(value: string | null | undefined): string {
|
||||
if (!value || !value.startsWith('/') || value.startsWith('//') || hasUnsafeControlOrBackslash(value)) {
|
||||
return '/'
|
||||
}
|
||||
try {
|
||||
const parsed = new URL(value, 'https://d3ro-admin.local')
|
||||
if (parsed.origin !== 'https://d3ro-admin.local' || parsed.pathname.startsWith('//')) {
|
||||
return '/'
|
||||
}
|
||||
} catch {
|
||||
return '/'
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/** 정적 에셋 확장자 경로만 인증 우회 정적 경로로 간주한다. `/api/*`는 절대 면제하지 않는다. */
|
||||
export function isStaticAssetPath(pathname: string): boolean {
|
||||
if (pathname.startsWith('/_next/') || pathname === '/_next') return true
|
||||
if (pathname.startsWith('/static/') || pathname === '/static') return true
|
||||
if (pathname.startsWith('/api/') || pathname === '/api') return false
|
||||
return STATIC_ASSET_EXT_RE.test(pathname)
|
||||
}
|
||||
|
||||
/** 관리자 OAuth 콜백 리다이렉트 기준 origin을 반환한다. 설정값이 유효하면 우선한다. */
|
||||
export function resolveAdminCallbackOrigin(requestUrl: string, configuredOrigin?: string): string {
|
||||
const configured = configuredOrigin?.trim()
|
||||
if (configured) {
|
||||
try {
|
||||
const parsed = new URL(configured)
|
||||
if (parsed.protocol === 'https:' || parsed.protocol === 'http:') {
|
||||
return parsed.origin
|
||||
}
|
||||
} catch {
|
||||
// 잘못된 설정값은 요청 URL origin으로 폴백한다.
|
||||
}
|
||||
}
|
||||
return new URL(requestUrl).origin
|
||||
}
|
||||
|
||||
/** 선택적 날짜 입력을 ISO-8601 문자열로 검증·변환한다. */
|
||||
export function parseOptionalIsoDate(
|
||||
raw: string,
|
||||
): { ok: true; iso: string | undefined } | { ok: false; message: string } {
|
||||
const trimmed = raw.trim()
|
||||
if (!trimmed) {
|
||||
return { ok: true, iso: undefined }
|
||||
}
|
||||
const timestamp = Date.parse(trimmed)
|
||||
if (!Number.isFinite(timestamp)) {
|
||||
return { ok: false, message: '올바른 종료일 형식이 아닙니다.' }
|
||||
}
|
||||
return { ok: true, iso: new Date(timestamp).toISOString() }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue