fix: nvr_snapshot 오류 상세에서 RTSP 자격증명 제거 + ffmpeg 배너 잡음 제거

ffmpeg가 stderr에 rtsp://user:pass@host 를 통째로 찍어 도구 결과·모델 컨텍스트로
비밀번호가 샜다. user:pass@ → ***@ 로 가리고, 실패 원인 줄만 남긴다.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rfme1WVEPkpNwnf5oVNXXc
This commit is contained in:
kimandClaude Sonnet 5 committed 2026-09-07 11:20:03 +09:00
1 parent 2e2a689b32
commit cf331a7440
1 file changed
+9 -2
+9 -2
View File
@@ -74,13 +74,20 @@ function grabFrame(rtspUrl: string, outPath: string, timeoutMs: number): Promise
outPath,
], { stdio: ['ignore', 'ignore', 'pipe'] });
let stderr = '';
proc.stderr?.on('data', (d: Buffer) => { stderr += d.toString('utf8'); if (stderr.length > 4000) stderr = stderr.slice(-4000); });
// ffmpeg는 stderr에 RTSP URL을 통째로 찍는다 — 자격증명이 도구 결과·모델 컨텍스트로
// 새지 않도록 user:pass@ 부분을 가린다.
const redact = (s: string) => s.replace(/rtsp:\/\/[^@\s]*@/gi, 'rtsp://***@');
proc.stderr?.on('data', (d: Buffer) => { stderr += redact(d.toString('utf8')); if (stderr.length > 4000) stderr = stderr.slice(-4000); });
const killTimer = setTimeout(() => { try { proc.kill('SIGKILL'); } catch {} }, timeoutMs);
proc.on('error', (e) => { clearTimeout(killTimer); resolve({ ok: false, detail: String(e.message || e) }); });
proc.on('close', (code) => {
clearTimeout(killTimer);
if (code === 0 && fs.existsSync(outPath) && fs.statSync(outPath).size > 1000) resolve({ ok: true });
else resolve({ ok: false, detail: `ffmpeg exit ${code}. ${stderr.slice(-500)}` });
else {
// ffmpeg 버전 배너 등 잡음은 빼고 실패 원인 줄만.
const reason = stderr.split('\n').filter((l) => /error|failed|no route|refused|timed?\s*out|unauthorized|401|not found/i.test(l)).slice(-3).join(' ').trim();
resolve({ ok: false, detail: reason || `ffmpeg exit ${code}` });
}
});
});
}