diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 2f8d213a5..2c2271fd9 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -27,6 +27,7 @@ exports = module.exports = { const assert = require('node:assert'), BoxError = require('../boxerror.js'), + crypto = require('crypto'), debug = require('debug')('box:storage/filesystem'), df = require('../df.js'), fs = require('node:fs'), @@ -210,7 +211,7 @@ async function copyInternal(config, fromPath, toPath, options, progressCallback) if (config._provider === mounts.MOUNT_TYPE_SSHFS) { // we use a temporary key file instead of passing it as stdin - const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`; + const identityFilePath = `/tmp/identity_file_${crypto.randomUUID()}`; // have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it safe.fs.unlinkSync(identityFilePath); if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`); @@ -273,7 +274,7 @@ async function removeDir(config, limits, remotePathPrefix, progressCallback) { if (config._provider === mounts.MOUNT_TYPE_SSHFS) { // we use a temporary key file instead of passing it as stdin - const identityFilePath = `/tmp/identity_file${config._managedMountPath.replaceAll('/', '-')}`; + const identityFilePath = `/tmp/identity_file_${crypto.randomUUID()}`; // have to unlink first, in case a previous run crash before cleanup. With mode 0c600 we cannot overwrite it safe.fs.unlinkSync(identityFilePath); if (!safe.fs.writeFileSync(identityFilePath, `${config.mountOptions.privateKey}\n`, { mode: 0o600 })) throw new BoxError(BoxError.FS_ERROR, `Could not write temporary private key: ${safe.error.message}`);