Prevent paste in within ancestor folder

pull/2195/head
David Disu 3 years ago committed by yann300
parent 67993f5019
commit 5f2bc31d2c
  1. 8
      apps/remix-ide/src/app/files/fileManager.ts
  2. 9
      apps/remix-ide/src/app/files/remixDProvider.js

@ -272,7 +272,13 @@ class FileManager extends Plugin {
await this._handleIsDir(src, `Cannot copy from ${src}. Path is not a directory.`)
await this._handleExists(dest, `Cannot paste content into ${dest}. Path does not exist.`)
await this._handleIsDir(dest, `Cannot paste content into ${dest}. Path is not directory.`)
await this.inDepthCopy(src, dest)
const provider = this.fileProviderOf(src)
if (provider.isSubDirectory(src, dest)) {
this.call('notification', 'toast', 'File(s) to paste is an ancestor of the destination folder')
} else {
await this.inDepthCopy(src, dest)
}
} catch (e) {
throw new Error(e)
}

@ -1,5 +1,6 @@
'use strict'
const FileProvider = require('./fileProvider')
const pathModule = require('path')
module.exports = class RemixDProvider extends FileProvider {
constructor (appManager) {
@ -207,4 +208,12 @@ module.exports = class RemixDProvider extends FileProvider {
if (!this._isReady) throw new Error('provider not ready')
return await this._appManager.call('remixd', 'isFile', { path: unprefixedpath })
}
isSubDirectory (parent, child) {
if (!parent) return false
if (parent === child) return true
const relative = pathModule.relative(parent, child)
return !!relative && relative.split(pathModule.sep)[0] !== '..'
}
}

Loading…
Cancel
Save