fix(deploy): SSH env값 제어문자 sanitize + 포트 검증

- NAS_SSH_TARGET/PORT/PATH에서 \r\n\t 제거 (잘못된 export·copy-paste 대비)
- NAS_SSH_PORT는 숫자만 허용, 잘못된 값이면 명확한 오류 메시지 출력
- SSH deploy 실행 시 cleanTarget/sshCmd 값 콘솔에 출력 (디버그용)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 09:27:11 +09:00
parent f6d95264c3
commit b11d1c421d

View File

@@ -40,10 +40,26 @@ if (isWin) {
// SSH 경로: NAS_SSH_TARGET이 설정된 경우 항상 우선
if (sshTarget) {
console.log(`Deploying via SSH → ${sshTarget}:${sshPath}`);
const sshCmd = sshPort ? `ssh -p ${sshPort}` : "ssh";
// 제어문자·줄바꿈 제거 (잘못된 export/copy-paste 대비)
const cleanTarget = sshTarget.replace(/[\r\n\t]/g, "").trim();
const cleanPath = sshPath.replace(/[\r\n\t]/g, "").trim();
const cleanPort = sshPort ? sshPort.replace(/\D/g, "").trim() : "";
if (!cleanTarget) {
console.error("NAS_SSH_TARGET 값이 비어있습니다. .env.local 또는 환경변수를 확인하세요.");
printSshHint();
process.exit(1);
}
if (cleanPort && !/^\d{1,5}$/.test(cleanPort)) {
console.error(`NAS_SSH_PORT 값이 잘못됐습니다: "${sshPort}" → 숫자만 입력하세요.`);
process.exit(1);
}
const sshCmd = cleanPort ? `ssh -p ${cleanPort}` : "ssh";
console.log(`Deploying via SSH → ${cleanTarget}:${cleanPath}`);
console.log(`SSH command: ${sshCmd}`);
execSync(
`rsync -r --delete --delete-delay -e "${sshCmd}" ${src}/ ${sshTarget}:${sshPath}`,
`rsync -r --delete --delete-delay -e "${sshCmd}" ${src}/ ${cleanTarget}:${cleanPath}`,
{ stdio: "inherit" }
);
process.exit(0);