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.
// insecure, as helperPath variable may have been modified by user input
const badWayToRequireUploadHelpers = require(helperPath);
// secure
const uploadHelpers = require('./helpers/upload');
사용자의 입력으로 값이 변할 수 있기에 매개변수로 제공된 경로를 사용한 파일의 사용을 피해라.
일반적으로 fs.readFile()
또는 사용자가 입력한 변수가 민감한 리소스에 접근 할 수 있도록 확장될 수 있다.
/// 사용자의 입력에 의해 helperPath 변수가 수정되었을 수 있기 때문에 안전하지 않음/
const badWayToRequireUploadHelpers = require(helperPath);
/// 안전함/
const uploadHelpers = require('./helpers/upload');