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
|
|
@ -3,21 +3,33 @@
|
|||
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
import { createServerClient, type CookieOptions } from '@supabase/ssr'
|
||||
import { resolveAdminCallbackOrigin, safeAdminRedirectPath } from '@/lib/admin-url-safety'
|
||||
|
||||
export async function GET(request: NextRequest): Promise<NextResponse> {
|
||||
const { searchParams, origin } = new URL(request.url)
|
||||
const { searchParams } = new URL(request.url)
|
||||
const origin = resolveAdminCallbackOrigin(
|
||||
request.url,
|
||||
process.env.ADMIN_PUBLIC_ORIGIN ?? process.env.NEXT_PUBLIC_ADMIN_ORIGIN,
|
||||
)
|
||||
const code = searchParams.get('code')
|
||||
const nextPath = safeAdminRedirectPath(searchParams.get('next'))
|
||||
|
||||
if (!code) {
|
||||
return NextResponse.redirect(`${origin}/login?error=no_code`)
|
||||
}
|
||||
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL?.trim()
|
||||
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY?.trim()
|
||||
if (!supabaseUrl || !supabaseAnonKey) {
|
||||
return NextResponse.redirect(`${origin}/login?error=auth_unavailable`)
|
||||
}
|
||||
|
||||
// 쿠키를 수집할 배열
|
||||
const cookiesToSet: Array<{ name: string; value: string; options: CookieOptions }> = []
|
||||
|
||||
const supabase = createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL ?? '',
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? '',
|
||||
supabaseUrl,
|
||||
supabaseAnonKey,
|
||||
{
|
||||
cookies: {
|
||||
getAll() {
|
||||
|
|
@ -33,11 +45,11 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
|
|||
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
||||
|
||||
if (error) {
|
||||
return NextResponse.redirect(`${origin}/login?error=${encodeURIComponent(error.message)}`)
|
||||
return NextResponse.redirect(`${origin}/login?error=oauth_callback_failed`)
|
||||
}
|
||||
|
||||
// 세션 교환 성공 후 response 생성 + 수집된 쿠키 적용
|
||||
const response = NextResponse.redirect(`${origin}/`)
|
||||
const response = NextResponse.redirect(`${origin}${nextPath}`)
|
||||
for (const { name, value, options } of cookiesToSet) {
|
||||
response.cookies.set({ name, value, ...options })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ import GoogleIcon from '@mui/icons-material/Google'
|
|||
import LockOutlinedIcon from '@mui/icons-material/LockOutlined'
|
||||
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
|
||||
import { C, FONT_SANS, FONT_MONO, primaryButtonSx } from '@/lib/console-theme'
|
||||
import { safeAdminRedirectPath } from '@/lib/admin-url-safety'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
|
||||
function LoginForm(): React.ReactElement {
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const redirectPath = searchParams.get('redirect') || '/'
|
||||
const redirectPath = safeAdminRedirectPath(searchParams.get('redirect'))
|
||||
|
||||
const [usernameOrEmail, setUsernameOrEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue