🇰🇷 한글 설명
Node.js 라이브러리 tmp 0.2.6 버전에서 경로 검증 로직의 결함으로 인해 디렉토리 트래버설 공격이 가능합니다. 비문자열 입력값이 문자열로 변환될 때 '../' 패턴이 감지되지 않아 공격자가 임의의 위치에 파일을 생성할 수 있습니다.
💡 쉬운 설명
임시 파일 생성 라이브러리에서 잘못된 입력값을 통해 시스템의 다른 폴더로 탈출할 수 있는 구멍이 있습니다. 공격자는 이를 이용해 서버의 권한으로 원하지 않는 파일을 만들 수 있습니다.
🇺🇸 원문 (English)
tmp is a temporary file and directory creator for node.js. In version 0.2.6, the _assertPath guard added to tmp rejects only string values that contain the substring ... It is bypassed when prefix, postfix, or template is supplied as a non-string value (Array, Buffer, or any object) whose includes('..') returns falsy but whose stringification still contains ../. The value flows through Array.prototype.join/String coercion inside _generateTmpName and path.join(tmpDir, opts.dir, name), producing a final path that escapes tmpdir and creates a file or directory at an attacker-controlled location with the host process's privileges. This affects any application that forwards untrusted request data (a common pattern is JSON body fields or qs-parsed bracket-array query strings such as ?prefix[]=...) into tmp.file, tmp.fileSync, tmp.dir, tmp.dirSync, tmp.tmpName, or tmp.tmpNameSync without explicit type coercion. This vulnerability is fixed in 0.2.7.
📍 영향받는 시스템
tmp npm package version < 0.2.7
⚔️ 공격 벡터
비문자열 타입의 prefix, postfix, template 인자를 통해 경로 검증 우회 및 디렉토리 트래버설
🛡️ 대응 방법
tmp 패키지를 0.2.7 이상으로 업그레이드하고, 외부 입력값 사용 전 명시적인 타입 검증을 수행하십시오.
🔧 검증 코드
출력된 버전이 0.2.7 미만인 경우 취약한 것으로 판단하며, 0.2.7 이상이면 패치된 버전입니다.
npm list tmp 2>/dev/null | grep -E 'tmp@'