mirror of
https://github.com/zoriya/flood.git
synced 2026-06-01 10:35:59 +00:00
server: fileUtil: getDirectoryList: assert typeof inputPath is string
This commit is contained in:
+11
-1
@@ -10,6 +10,12 @@ export const accessDeniedError = () => {
|
||||
return error;
|
||||
};
|
||||
|
||||
export const fileNotFoundError = () => {
|
||||
const error = new Error() as NodeJS.ErrnoException;
|
||||
error.code = 'ENOENT';
|
||||
return error;
|
||||
};
|
||||
|
||||
export const isAllowedPath = (resolvedPath: string) => {
|
||||
if (config.allowedPaths == null) {
|
||||
return true;
|
||||
@@ -43,7 +49,11 @@ export const createDirectory = (directoryPath: string) => {
|
||||
};
|
||||
|
||||
export const getDirectoryList = async (inputPath: string) => {
|
||||
const sourcePath = (inputPath || '/').replace(/^~/, homedir());
|
||||
if (typeof inputPath !== 'string') {
|
||||
throw fileNotFoundError();
|
||||
}
|
||||
|
||||
const sourcePath = inputPath.replace(/^~/, homedir());
|
||||
|
||||
const resolvedPath = sanitizePath(sourcePath);
|
||||
if (!isAllowedPath(resolvedPath)) {
|
||||
|
||||
Reference in New Issue
Block a user