From a3781edc6a6fbb66269100150196f9c54f95db0d Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 20 Sep 2022 09:16:56 -0600 Subject: [PATCH] remove path sanitization for now, address in upcoming pr --- datastore/fsds.nim | 32 ++++++++++---------------------- tests/datastore/testfsds.nim | 27 --------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/datastore/fsds.nim b/datastore/fsds.nim index 0324ad9..5a17833 100644 --- a/datastore/fsds.nim +++ b/datastore/fsds.nim @@ -24,14 +24,17 @@ const # can still be touched/created ProtectedPaths* = when doslikeFileSystem: - [] + [ + "\\System32", + "\\System", + "\\Start Menu\\Programs"] else: - [ - "/", - "/usr", - "/etc", - "/home", - "/Users"] + [ + "/", + "/usr", + "/etc", + "/home", + "/Users"] type FSDatastore* = ref object of Datastore @@ -53,9 +56,6 @@ template path*(self: FSDatastore, key: Key): string = self.root / segments.joinPath() -template checkProtected*(path: string): bool = - path in ProtectedPaths - template validDepth*(self: FSDatastore, key: Key): bool = key.len <= self.depth @@ -67,9 +67,6 @@ method contains*(self: FSDatastore, key: Key): Future[?!bool] {.async.} = let path = self.path(key) - if checkProtected(path): - return failure "Path is protected!" - return success fileExists(path) method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} = @@ -80,9 +77,6 @@ method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} = let path = self.path(key) - if checkProtected(path): - return failure "Path is protected!" - try: removeFile(path) return success() @@ -109,9 +103,6 @@ method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async.} = let path = self.path(key) - if checkProtected(path): - return failure "Path is protected!" - if not fileExists(path): return failure(newException(DatastoreKeyNotFound, "Key doesn't exist")) @@ -155,9 +146,6 @@ method put*( let path = self.path(key) - if checkProtected(path): - return failure "Path is protected!" - try: createDir(parentDir(path)) writeFile(path, data) diff --git a/tests/datastore/testfsds.nim b/tests/datastore/testfsds.nim index 78907e9..bf70b4e 100644 --- a/tests/datastore/testfsds.nim +++ b/tests/datastore/testfsds.nim @@ -52,33 +52,6 @@ suite "Test Misc FSDatastore": removeDir(basePathAbs) require(not dirExists(basePathAbs)) - test "Test checkProtected()": - let - fs = FSDatastore.new(root = "/").tryGet() - - for p in ProtectedPaths: - if p == "/": continue - let - key = Key.init(p).tryGet() - - check: - fs.path(key).checkProtected() - - test "Test protected paths": - let - fs = FSDatastore.new(root = "/").tryGet() - - for p in ProtectedPaths: - if p == "/": continue - let - key = Key.init(p).tryGet() - - check: - (await fs.put(key, bytes)).isErr - (await fs.get(key)).isErr - (await fs.delete(key)).isErr - (await fs.contains(key)).isErr - test "Test validDepth()": let fs = FSDatastore.new(root = "/", depth = 3).tryGet()