X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fmisc.ts;h=3ef38fce1d0b135625647e24dfbbd3671d86595a;hb=7cd4d2ba10106c10602c86f74f55743ded588896;hp=3a3deab0c8f7b152ac56d08348d003b84286c247;hpb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 3a3deab0c..3ef38fce1 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -1,10 +1,18 @@ import 'multer' import * as validator from 'validator' +import { sep } from 'path' function exists (value: any) { return value !== undefined && value !== null } +function isSafePath (p: string) { + return exists(p) && + (p + '').split(sep).every(part => { + return [ '..' ].includes(part) === false + }) +} + function isArray (value: any) { return Array.isArray(value) } @@ -97,6 +105,7 @@ export { isNotEmptyIntArray, isArray, isIdValid, + isSafePath, isUUIDValid, isIdOrUUIDValid, isDateValid,