remove path sanitization for now, address in upcoming pr

This commit is contained in:
Dmitriy Ryajov 2022-09-20 09:16:56 -06:00
parent bb387650ab
commit a3781edc6a
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 10 additions and 49 deletions

View File

@ -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)

View File

@ -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()