fix(nvr): 에러 로그에서 RTSP 비밀번호 마스킹

ffmpeg stderr에는 입력 주소("Input #0, rtsp, from 'rtsp://user:pass@host/...'")가 그대로 찍혀
NVR 비밀번호가 gateway.err.log에 남았다. 로그로 내보내기 전에 maskUrlCredentials()로
://사용자:비밀번호@ 의 비밀번호를 ***로 가린다. stderr 4KB 전체에 먼저 적용한 뒤 slice(-800) —
먼저 자르면 주소 중간에서 잘려 패턴이 안 맞는다.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-11-03 14:41:57 +09:00
1 parent 28767e9615
commit 9886b4bbb2
1 file changed
+7 -2
+7 -2
View File
@@ -600,6 +600,11 @@ export function registerNvrRoutes(
nvrNextStartAt = at + NVR_START_GAP_MS;
return at - now;
};
// ffmpeg stderr에는 입력 주소("Input #0, rtsp, from 'rtsp://user:pass@host/...'")가 그대로 찍혀
// 비밀번호가 에러 로그에 남는다. 로그로 내보내기 전에 가린다(2026-11-03). 자르기(slice) 전에 전체
// 문자열에 적용해야 한다 — 먼저 자르면 주소 중간에서 잘려 패턴이 안 맞는다.
const maskUrlCredentials = (s: string): string =>
s.replace(/(\b[a-z][a-z0-9+.-]*:\/\/[^\/\s:@]+:)[^@\s]*@/gi, '$1***@');
// 채널별 강제 화질(nvr.channelStream)이 있으면 요청의 ?stream= 값과 상관없이 그것을 따른다.
// 화면이 채널 목록을 불러오기 전에 격자를 시작하면 강제 화질을 모른 채 서브(?stream=1)를 요청하는데,
// 마당(Mercusys)은 서브가 NVR에서 나오지 않아 칸이 계속 검게 남았다(2026-11-03). 강제 화질이
@@ -804,9 +809,9 @@ export function registerNvrRoutes(
if (!headersSent) {
// 첫 프레임도 못 받고 종료(NVR이 EOF로 연결 끊음 등) — 일시적일 수 있으니
// 바로 502 주지 않고 재시도. 진짜 설정 오류면 cap 도달시 502.
console.error(`[nvr/stream] channel ${channelId}:${stream} ffmpeg exited ${code} before first frame (attempt ${respawnCount + 1}/${MAX_RESPAWN}). stderr tail:\n${stderrBuf.slice(-800)}`);
console.error(`[nvr/stream] channel ${channelId}:${stream} ffmpeg exited ${code} before first frame (attempt ${respawnCount + 1}/${MAX_RESPAWN}). stderr tail:\n${maskUrlCredentials(stderrBuf).slice(-800)}`);
} else {
console.error(`[nvr/stream] channel ${channelId}:${stream} mid-stream drop (attempt ${respawnCount + 1}/${MAX_RESPAWN}). stderr tail:\n${stderrBuf.slice(-800)}`);
console.error(`[nvr/stream] channel ${channelId}:${stream} mid-stream drop (attempt ${respawnCount + 1}/${MAX_RESPAWN}). stderr tail:\n${maskUrlCredentials(stderrBuf).slice(-800)}`);
}
// 스트리밍 중 끊김이든 첫 프레임 실패든 모두 재시도로 복구 시도.
scheduleRespawn();