Skip to content

Commit 4165185

Browse files
committed
Use file name whitelist to prevent RCE
Use a whitelist to validate user-provided file names. This doesn't cover the entire range of valid filenames but should cover almost all of them in practice. Allows letters, numbers, periods, dashes, and underscores. Opting to use a whitelist instead of a blacklist because getting this wrong leaves us vulnerable to a RCE attack.
1 parent 69c3d4b commit 4165185

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: packages/react-dev-utils/launchEditor.js

+9
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ function printInstructions(fileName, errorMessage) {
266266

267267
let _childProcess = null;
268268
function launchEditor(fileName, lineNumber, colNumber) {
269+
// Use a whitelist to validate user-provided file names. This doesn't cover
270+
// the entire range of valid filenames but should cover almost all of them in
271+
// practice. Allows letters, numbers, periods, dashes, slashes, and
272+
// underscores. Opting to use a whitelist instead of a blacklist because
273+
// getting this wrong leaves us vulnerable to a RCE attack.
274+
if (!/^[a-zA-Z0-9/.-\\_]+$/.test(fileName.trim())) {
275+
return;
276+
}
277+
269278
if (!fs.existsSync(fileName)) {
270279
return;
271280
}

0 commit comments

Comments
 (0)