보안 감사 결과 CRITICAL 2건, HIGH 5건 발견 → 수정 완료 + 자동화 구축. [보안 수정] - issue-view.js: 하드코딩 비밀번호 → crypto.getRandomValues() 랜덤 생성 - pushSubscriptionController.js: ntfy 비밀번호 → process.env.NTFY_SUB_PASSWORD - DEPLOY-GUIDE.md/PROGRESS.md/migration SQL: 평문 비밀번호 → placeholder - docker-compose.yml/.env.example: NTFY_SUB_PASSWORD 환경변수 추가 [보안 강제 시스템 - 신규] - scripts/security-scan.sh: 8개 규칙 (CRITICAL 2, HIGH 4, MEDIUM 2) 3모드(staged/all/diff), severity, .securityignore, MEDIUM 임계값 - .githooks/pre-commit: 로컬 빠른 피드백 - .githooks/pre-receive-server.sh: Gitea 서버 최종 차단 bypass 거버넌스([SECURITY-BYPASS: 사유] + 사용자 제한 + 로그) - SECURITY-CHECKLIST.md: 10개 카테고리 자동/수동 구분 - docs/SECURITY-GUIDE.md: 운영자 가이드 (워크플로우, bypass, FAQ) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
108 lines
3.6 KiB
JavaScript
108 lines
3.6 KiB
JavaScript
// controllers/pushSubscriptionController.js
|
|
const pushSubscriptionModel = require('../models/pushSubscriptionModel');
|
|
|
|
const pushSubscriptionController = {
|
|
// VAPID 공개키 반환 (인증 불필요)
|
|
async getVapidPublicKey(req, res) {
|
|
const vapidPublicKey = process.env.VAPID_PUBLIC_KEY;
|
|
if (!vapidPublicKey) {
|
|
return res.status(500).json({ success: false, message: 'VAPID 키가 설정되지 않았습니다.' });
|
|
}
|
|
res.json({ success: true, data: { vapidPublicKey } });
|
|
},
|
|
|
|
// Push 구독 저장
|
|
async subscribe(req, res) {
|
|
try {
|
|
const userId = req.user?.id;
|
|
const { subscription } = req.body;
|
|
|
|
if (!subscription || !subscription.endpoint || !subscription.keys) {
|
|
return res.status(400).json({ success: false, message: '유효한 구독 정보가 필요합니다.' });
|
|
}
|
|
|
|
await pushSubscriptionModel.subscribe(userId, subscription);
|
|
res.json({ success: true, message: 'Push 구독이 등록되었습니다.' });
|
|
} catch (error) {
|
|
console.error('Push 구독 오류:', error);
|
|
res.status(500).json({ success: false, message: 'Push 구독 중 오류가 발생했습니다.' });
|
|
}
|
|
},
|
|
|
|
// Push 구독 해제
|
|
async unsubscribe(req, res) {
|
|
try {
|
|
const { endpoint } = req.body;
|
|
if (!endpoint) {
|
|
return res.status(400).json({ success: false, message: 'endpoint가 필요합니다.' });
|
|
}
|
|
|
|
await pushSubscriptionModel.unsubscribe(endpoint);
|
|
res.json({ success: true, message: 'Push 구독이 해제되었습니다.' });
|
|
} catch (error) {
|
|
console.error('Push 구독 해제 오류:', error);
|
|
res.status(500).json({ success: false, message: 'Push 구독 해제 중 오류가 발생했습니다.' });
|
|
}
|
|
},
|
|
|
|
// === ntfy ===
|
|
|
|
// ntfy 구독 등록
|
|
async ntfySubscribe(req, res) {
|
|
try {
|
|
const userId = req.user?.id;
|
|
await pushSubscriptionModel.ntfySubscribe(userId);
|
|
|
|
const topic = `tkfactory-user-${userId}`;
|
|
res.json({
|
|
success: true,
|
|
message: 'ntfy 구독이 등록되었습니다.',
|
|
data: {
|
|
topic,
|
|
serverUrl: process.env.NTFY_EXTERNAL_URL || 'https://ntfy.technicalkorea.net',
|
|
username: 'subscriber',
|
|
password: process.env.NTFY_SUB_PASSWORD || ''
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('ntfy 구독 오류:', error);
|
|
res.status(500).json({ success: false, message: 'ntfy 구독 중 오류가 발생했습니다.' });
|
|
}
|
|
},
|
|
|
|
// ntfy 구독 해제
|
|
async ntfyUnsubscribe(req, res) {
|
|
try {
|
|
const userId = req.user?.id;
|
|
await pushSubscriptionModel.ntfyUnsubscribe(userId);
|
|
res.json({ success: true, message: 'ntfy 구독이 해제되었습니다.' });
|
|
} catch (error) {
|
|
console.error('ntfy 구독 해제 오류:', error);
|
|
res.status(500).json({ success: false, message: 'ntfy 구독 해제 중 오류가 발생했습니다.' });
|
|
}
|
|
},
|
|
|
|
// ntfy 구독 상태 확인
|
|
async ntfyStatus(req, res) {
|
|
try {
|
|
const userId = req.user?.id;
|
|
const subscribed = await pushSubscriptionModel.isNtfySubscribed(userId);
|
|
const topic = `tkfactory-user-${userId}`;
|
|
|
|
res.json({
|
|
success: true,
|
|
data: {
|
|
subscribed,
|
|
topic,
|
|
serverUrl: process.env.NTFY_EXTERNAL_URL || 'https://ntfy.technicalkorea.net'
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('ntfy 상태 확인 오류:', error);
|
|
res.status(500).json({ success: false, message: 'ntfy 상태 확인 중 오류가 발생했습니다.' });
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = pushSubscriptionController;
|