do not modify hostPath variable

This commit is contained in:
Girish Ramakrishnan
2025-01-02 11:22:09 +01:00
parent 9d890e1c21
commit f7ea847336
+4 -6
View File
@@ -56,13 +56,11 @@ function validateHostPath(hostPath, mountType) {
if (hostPath === '/') return new BoxError(BoxError.BAD_FIELD, 'hostPath cannot be /');
if (!hostPath.endsWith('/')) hostPath = hostPath + '/'; // ensure trailing slash for the prefix matching to work
const allowedPaths = [ '/mnt', '/media', '/srv', '/opt' ];
if (!allowedPaths.some(p => hostPath === p || hostPath.startsWith(p + '/'))) return new BoxError(BoxError.BAD_FIELD, 'hostPath must be under /mnt, /media, /opt or /srv');
const allowedPaths = [ '/mnt/', '/media/', '/srv/', '/opt/' ];
if (!allowedPaths.some(p => hostPath.startsWith(p))) return new BoxError(BoxError.BAD_FIELD, 'hostPath must be under /mnt, /media, /opt or /srv');
const reservedPaths = [ `${paths.VOLUMES_MOUNT_DIR}/` ];
if (reservedPaths.some(p => hostPath.startsWith(p))) return new BoxError(BoxError.BAD_FIELD, 'hostPath is reserved');
const reservedPaths = [ `${paths.VOLUMES_MOUNT_DIR}` ];
if (reservedPaths.some(p => hostPath === p || hostPath.startsWith(p + '/'))) return new BoxError(BoxError.BAD_FIELD, 'hostPath is reserved');
if (!constants.TEST) { // we expect user to have already mounted this
const stat = safe.fs.lstatSync(hostPath);