fix: 보안 취약점 수정 및 XSS 방지 적용

## 백엔드 보안 수정
- 하드코딩된 비밀번호 및 JWT 시크릿 폴백 제거
- SQL Injection 방지를 위한 화이트리스트 검증 추가
- 인증 미적용 API 라우트에 requireAuth 미들웨어 적용
- CSRF 보호 미들웨어 구현 (csrf.js)
- 파일 업로드 보안 유틸리티 추가 (fileUploadSecurity.js)
- 비밀번호 정책 검증 유틸리티 추가 (passwordValidator.js)

## 프론트엔드 XSS 방지
- api-base.js에 전역 escapeHtml() 함수 추가
- 17개 주요 JS 파일에 escapeHtml 적용:
  - tbm.js, daily-patrol.js, daily-work-report.js
  - task-management.js, workplace-status.js
  - equipment-detail.js, equipment-management.js
  - issue-detail.js, issue-report.js
  - vacation-common.js, worker-management.js
  - safety-report-list.js, nonconformity-list.js
  - project-management.js, workplace-management.js

## 정리
- 백업 폴더 및 빈 파일 삭제
- SECURITY_GUIDE.md 문서 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-02-05 06:33:10 +09:00
parent 7c38c555f5
commit 36f110c90a
97 changed files with 2523 additions and 24267 deletions

View File

@@ -4,31 +4,37 @@ const router = express.Router();
const multer = require('multer');
const path = require('path');
const workplaceController = require('../controllers/workplaceController');
const {
generateSafeFilename,
createFileFilter,
ALLOWED_IMAGE_EXTENSIONS
} = require('../utils/fileUploadSecurity');
// Multer 설정 - 작업장 레이아웃 이미지 업로드
// Multer 설정 - 작업장 레이아웃 이미지 업로드 (보안 강화)
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, path.join(__dirname, '../uploads'));
},
filename: (req, file, cb) => {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
cb(null, 'workplace-layout-' + uniqueSuffix + path.extname(file.originalname));
// 안전한 랜덤 파일명 생성 (원본 파일명 노출 방지)
const safeName = generateSafeFilename(file.originalname);
cb(null, `workplace-layout-${safeName}`);
}
});
// 보안 강화된 파일 필터
const imageFileFilter = createFileFilter({
allowedExtensions: ALLOWED_IMAGE_EXTENSIONS,
allowedMimes: ['image/jpeg', 'image/png', 'image/gif', 'image/webp']
});
const upload = multer({
storage,
fileFilter: (req, file, cb) => {
const allowedTypes = /jpeg|jpg|png|gif/;
const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase());
const mimetype = allowedTypes.test(file.mimetype);
if (mimetype && extname) {
return cb(null, true);
} else {
cb(new Error('이미지 파일만 업로드 가능합니다 (jpeg, jpg, png, gif)'));
}
},
limits: { fileSize: 5 * 1024 * 1024 } // 5MB 제한
fileFilter: imageFileFilter,
limits: {
fileSize: 5 * 1024 * 1024, // 5MB 제한
files: 1 // 단일 파일만 허용
}
});
// ==================== 카테고리(공장) 관리 ====================