feat: 보안 강화 + 자동화 도구 3종 추가 (웹 크롤러·PPT·엑셀)
- 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>
This commit is contained in:
@@ -16,24 +16,50 @@ export async function GET(_req: Request, { params }: { params: Promise<{ id: str
|
||||
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: error.message }, { status: 404 });
|
||||
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;
|
||||
const body = await request.json();
|
||||
const supabase = createAdminClient();
|
||||
|
||||
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({ ...body, updated_at: new Date().toISOString() })
|
||||
.update({ ...sanitizedBody, updated_at: new Date().toISOString() })
|
||||
.eq('id', id)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
if (error) {
|
||||
console.error('[Admin Quotes] PUT error:', error.message);
|
||||
return NextResponse.json({ error: '견적서 업데이트 실패' }, { status: 500 });
|
||||
}
|
||||
return NextResponse.json({ quote: data });
|
||||
}
|
||||
|
||||
@@ -42,6 +68,9 @@ export async function DELETE(_req: Request, { params }: { params: Promise<{ id:
|
||||
const { id } = await params;
|
||||
const supabase = createAdminClient();
|
||||
const { error } = await supabase.from('quotes').delete().eq('id', id);
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
if (error) {
|
||||
console.error('[Admin Quotes] DELETE error:', error.message);
|
||||
return NextResponse.json({ error: '견적서 삭제 실패' }, { status: 500 });
|
||||
}
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user