From e270e477f362dd68249bb4a013c66eab293bba82 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 7 Aug 2025 05:04:39 +0000 Subject: (최겸) PQ요청+기본계약 로직 수정(한글화 미적용) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/api/pdftron/createBasicContractPdf.ts | 359 ++++++++++++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 pages/api/pdftron/createBasicContractPdf.ts (limited to 'pages/api/pdftron') diff --git a/pages/api/pdftron/createBasicContractPdf.ts b/pages/api/pdftron/createBasicContractPdf.ts new file mode 100644 index 00000000..1122c022 --- /dev/null +++ b/pages/api/pdftron/createBasicContractPdf.ts @@ -0,0 +1,359 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import type { File as FormidableFile } from "formidable"; +import formidable from "formidable"; +import fs from "fs/promises"; +import path from "path"; +import { createBasicContractPdf } from "@/lib/pdftron/serverSDK/createBasicContractPdf"; + +export const config = { + api: { + bodyParser: false, + }, +}; + +// 보안 설정 +const SECURITY_CONFIG = { + ALLOWED_EXTENSIONS: new Set(['docx', 'doc']), + FORBIDDEN_EXTENSIONS: new Set([ + 'exe', 'bat', 'cmd', 'scr', 'vbs', 'js', 'jar', 'com', 'pif', + 'msi', 'reg', 'ps1', 'sh', 'php', 'asp', 'jsp', 'py', 'pl', + 'html', 'htm', 'xhtml', 'xml', 'svg' + ]), + MAX_FILE_SIZE: 50 * 1024 * 1024, // 50MB + MAX_FILENAME_LENGTH: 255, +}; + +// 간단한 보안 검증 함수들 +function validateExtension(fileName: string): { valid: boolean; error?: string } { + const extension = path.extname(fileName).toLowerCase().substring(1); + + if (!extension) { + return { valid: false, error: "파일 확장자가 없습니다" }; + } + + if (SECURITY_CONFIG.FORBIDDEN_EXTENSIONS.has(extension)) { + return { valid: false, error: `금지된 파일 형식입니다: .${extension}` }; + } + + if (!SECURITY_CONFIG.ALLOWED_EXTENSIONS.has(extension)) { + return { valid: false, error: `허용되지 않은 파일 형식입니다: .${extension}` }; + } + + return { valid: true }; +} + +function validateFileName(fileName: string): { valid: boolean; error?: string } { + if (fileName.length > SECURITY_CONFIG.MAX_FILENAME_LENGTH) { + return { valid: false, error: "파일명이 너무 깁니다" }; + } + + // 위험한 문자 체크 + const dangerousPatterns = [ + /[<>:"'|?*]/, + /[\x00-\x1f]/, + /^\./, + /\.\./, + /\/|\\$/, + /javascript:/i, + /data:/i, + /vbscript:/i, + /on\w+=/i, + /