Platform independent path validation
All checks were successful
/ Misc Linters (push) Successful in 27s
/ Misc Linters (pull_request) Successful in 20s
/ Build App (pull_request) Successful in 58s
/ Build App (push) Successful in 47s

This commit is contained in:
Valentin Brandl 2024-08-17 14:59:55 +02:00
parent 1f846bd5fe
commit 6615e2788a
Signed by: vbrandl
GPG Key ID: CAD4DA1A789125F9

View File

@ -7,9 +7,9 @@ function safePath(basePath: string, name: string): boolean {
return ( return (
!!relative && !!relative &&
// does move out of `basePath` // does move out of `basePath`
!relative.startsWith('..') && !relative.startsWith(`..${path.sep}`) &&
// exactly one layer deep, e.g. no `./uplodas/foo/bar` // exactly one layer deep, e.g. no `./uplodas/foo/bar`
!relative.includes('/') && !relative.includes(path.sep) &&
// result is not an absolute path // result is not an absolute path
!path.isAbsolute(relative) !path.isAbsolute(relative)
); );