From 29577b6dd7f94d28e89960a55ff72c1a4c86b9b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 19 Sep 2022 23:01:10 -0600 Subject: [PATCH] paths are already sanitized, removing `allowed` --- datastore/fsds.nim | 29 ----------------------------- tests/datastore/testfsds.nim | 29 ----------------------------- 2 files changed, 58 deletions(-) diff --git a/datastore/fsds.nim b/datastore/fsds.nim index 22c73a2..aa91e9f 100644 --- a/datastore/fsds.nim +++ b/datastore/fsds.nim @@ -29,13 +29,6 @@ const "/home", "/Users"] - Allowed* = { - 'a'..'z', - 'A'..'Z', - '0'..'9', - DirSep, AltSep, - '_', '-', '.'} - type FSDatastore* = ref object of Datastore root*: string @@ -59,16 +52,6 @@ template path*(self: FSDatastore, key: Key): string = template checkProtected*(path: string): bool = path in ProtectedPaths -template allowed*(path: string): bool = - var notfound = true - for s in path: - if s.char notin Allowed: - echo "INVALID CHAR ", s - notfound = false - break - - notfound - template validDepth*(self: FSDatastore, key: Key): bool = key.len <= self.depth @@ -80,9 +63,6 @@ method contains*(self: FSDatastore, key: Key): Future[?!bool] {.async.} = let path = self.path(key) - if not path.allowed: - return failure "Path is contains invalid characters!" - if checkProtected(path): return failure "Path is protected!" @@ -96,9 +76,6 @@ method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} = let path = self.path(key) - if not path.allowed: - return failure "Path is contains invalid characters!" - if checkProtected(path): return failure "Path is protected!" @@ -128,9 +105,6 @@ method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async.} = let path = self.path(key) - if not path.allowed: - return failure "Path is contains invalid characters!" - if checkProtected(path): return failure "Path is protected!" @@ -177,9 +151,6 @@ method put*( let path = self.path(key) - if not path.allowed: - return failure "Path is contains invalid characters!" - if checkProtected(path): return failure "Path is protected!" diff --git a/tests/datastore/testfsds.nim b/tests/datastore/testfsds.nim index f9b3e94..78907e9 100644 --- a/tests/datastore/testfsds.nim +++ b/tests/datastore/testfsds.nim @@ -79,35 +79,6 @@ suite "Test Misc FSDatastore": (await fs.delete(key)).isErr (await fs.contains(key)).isErr - test "Test allowed()": - let - chars = [ - "/a*", "/a/b*", "/a/b$", "/a/b()", - "/a/b+", "/a/b$", "/d%", "/A/b@", - "/A!", "/b#/##"] - - for c in chars: - check not c.allowed - - test "Test valid key (path) names": - let - fs = FSDatastore.new(root = basePathAbs).tryGet() - bytes = "some bytes".toBytes - chars = - ["/a*", "/a/b*", "/a/b$", "/a/b()", - "/a/b+", "/a/b$", "/d%", "/A/b@", - "/A!", "/b#/##"] - - for c in chars: - let - key = Key.init(c).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()