Protocol Filter: Catch and return 'invalid url' on all errors

This commit is contained in:
Scott Nonnenberg 2022-09-06 16:28:00 -07:00 committed by GitHub
parent b54c6f257d
commit 6a1b6f2e44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,18 +84,7 @@ function _createFileHandler({
try { try {
targetPath = _urlToPath(request.url, { isWindows }); targetPath = _urlToPath(request.url, { isWindows });
} catch (err) {
const errorMessage =
err && typeof err.message === 'string'
? err.message
: 'no error message';
console.log(
`Warning: denying request because of an error: ${errorMessage}`
);
callback({ error: -300 });
return;
}
// normalize() is primarily useful here for switching / to \ on windows // normalize() is primarily useful here for switching / to \ on windows
const target = normalize(targetPath); const target = normalize(targetPath);
// here we attempt to follow symlinks to the ultimate final path, reflective of what // here we attempt to follow symlinks to the ultimate final path, reflective of what
@ -126,6 +115,17 @@ function _createFileHandler({
`Warning: denying request to path '${realPath}' (allowedRoots: '${allowedRoots}')` `Warning: denying request to path '${realPath}' (allowedRoots: '${allowedRoots}')`
); );
callback({ error: -10 }); callback({ error: -10 });
} catch (err) {
const errorMessage =
err && typeof err.message === 'string'
? err.message
: 'no error message';
console.log(
`Warning: denying request because of an error: ${errorMessage}`
);
callback({ error: -300 });
}
}; };
} }