fix: do not expose files from parent folders via preview-docs server (#347)

This commit is contained in:
Ed Kelly
2021-09-14 21:13:41 +01:00
committed by GitHub
parent 4a84c4fce0
commit 69a1580bc7
3 changed files with 58 additions and 1 deletions

View File

@@ -290,4 +290,12 @@ export function slash(path: string): string {
}
return path.replace(/\\/g, '/');
}
/**
* Checks if dir is subdir of parent
*/
export function isSubdir(parent: string, dir: string): boolean {
const relative = path.relative(parent, dir);
return !!relative && !/^..($|\/)/.test(relative) && !path.isAbsolute(relative);
}