6.17 Avoid module loading using a variable

고준영·2021년 11월 30일
0

Nodebestpractices

목록 보기
11/16
post-thumbnail

Avoid module loading using a variable

One Paragraph Explainer

Avoid requiring/importing another file with a path that was given as parameter due to the concern that it could have originated from user input. This rule can be extended for accessing files in general (i.e. fs.readFile()) or other sensitive resources with dynamic variables originating from user input.

Code example

// insecure, as helperPath variable may have been modified by user input
const badWayToRequireUploadHelpers = require(helperPath);

// secure
const uploadHelpers = require('./helpers/upload');

6.17 변수를 사용해 모듈을 로딩하는것을 피해라

한문단 요약

사용자의 입력으로 값이 변할 수 있기에 매개변수로 제공된 경로를 사용한 파일의 사용을 피해라.
일반적으로 fs.readFile() 또는 사용자가 입력한 변수가 민감한 리소스에 접근 할 수 있도록 확장될 수 있다.

코드 예시

/// 사용자의 입력에 의해 helperPath 변수가 수정되었을 수 있기 때문에 안전하지 않음/
const badWayToRequireUploadHelpers = require(helperPath);

/// 안전함/
const uploadHelpers = require('./helpers/upload');
profile
코드짜는귤🍊 풀스택을 지향하는 주니어 개발자 입니다🧡

0개의 댓글