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
1 changed files with 31 additions and 31 deletions

View File

@ -84,18 +84,7 @@ function _createFileHandler({
try {
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
const target = normalize(targetPath);
// 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}')`
);
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 });
}
};
}