- lib/security.ts: escapeHtml, isValidEmail, sanitizeStr, checkRateLimit 유틸 추가 - next.config.ts: 보안 헤더 적용 (X-Frame-Options, HSTS, Permissions-Policy 등) - api/contact: XSS 방어, Rate Limit(5/min), 입력 길이 제한 - api/payment/confirm: 사용자 인증·소유권 검증, 타입 체크, 에러 메시지 정제 - api/admin/quotes: PUT 허용 필드 화이트리스트 적용 - api/saju/analyze: 로그인·결제 검증, 입력 크기 제한, gender 값 검증 - public/downloads/web_scraper_v1.0.py: requests+BS4+openpyxl 웹 크롤러 - public/downloads/ppt_automation_v1.0.py: python-pptx+openpyxl PPT 자동화 - app/services/automation/tools/scraper: 크롤러 상세 페이지 추가 - app/services/automation/tools/ppt: PPT 도구 상세 페이지 추가 - app/services/automation/page.tsx: scraper ready=true, email→PPT 교체 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { createAdminClient } from '@/lib/supabase/admin';
|
|
import { verifyAdminTokenNode } from '@/lib/admin-auth';
|
|
import { cookies } from 'next/headers';
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
async function checkAuth() {
|
|
const cookieStore = await cookies();
|
|
const token = cookieStore.get('admin_token')?.value;
|
|
return token && verifyAdminTokenNode(token);
|
|
}
|
|
|
|
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
if (!(await checkAuth())) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
const { id } = await params;
|
|
const supabase = createAdminClient();
|
|
const { data, error } = await supabase.from('quotes').select('*').eq('id', id).single();
|
|
if (error) return NextResponse.json({ error: '견적서를 찾을 수 없습니다' }, { status: 404 });
|
|
return NextResponse.json({ quote: data });
|
|
}
|
|
|
|
export async function PUT(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
if (!(await checkAuth())) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
const { id } = await params;
|
|
|
|
let body: Record<string, unknown>;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return NextResponse.json({ error: '잘못된 요청 형식' }, { status: 400 });
|
|
}
|
|
|
|
// ── 허용 필드 화이트리스트 (시스템 필드 변조 방지) ───────────
|
|
const ALLOWED_FIELDS = [
|
|
'title', 'client_name', 'client_email', 'client_phone',
|
|
'items', 'maintenance', 'notes', 'status',
|
|
'valid_until', 'discount',
|
|
] as const;
|
|
|
|
const sanitizedBody = Object.fromEntries(
|
|
ALLOWED_FIELDS
|
|
.filter((key) => key in body)
|
|
.map((key) => [key, body[key]])
|
|
);
|
|
|
|
if (Object.keys(sanitizedBody).length === 0) {
|
|
return NextResponse.json({ error: '수정할 필드가 없습니다' }, { status: 400 });
|
|
}
|
|
|
|
const supabase = createAdminClient();
|
|
const { data, error } = await supabase
|
|
.from('quotes')
|
|
.update({ ...sanitizedBody, updated_at: new Date().toISOString() })
|
|
.eq('id', id)
|
|
.select()
|
|
.single();
|
|
|
|
if (error) {
|
|
console.error('[Admin Quotes] PUT error:', error.message);
|
|
return NextResponse.json({ error: '견적서 업데이트 실패' }, { status: 500 });
|
|
}
|
|
return NextResponse.json({ quote: data });
|
|
}
|
|
|
|
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
if (!(await checkAuth())) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
const { id } = await params;
|
|
const supabase = createAdminClient();
|
|
const { error } = await supabase.from('quotes').delete().eq('id', id);
|
|
if (error) {
|
|
console.error('[Admin Quotes] DELETE error:', error.message);
|
|
return NextResponse.json({ error: '견적서 삭제 실패' }, { status: 500 });
|
|
}
|
|
return NextResponse.json({ success: true });
|
|
}
|