Protocol Filter: Catch and return 'invalid url' on all errors
This commit is contained in:
parent
b54c6f257d
commit
6a1b6f2e44
1 changed files with 31 additions and 31 deletions
|
@ -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 });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue