paths are already sanitized, removing allowed

This commit is contained in:
Dmitriy Ryajov 2022-09-19 23:01:10 -06:00
parent 309ac94f21
commit 29577b6dd7
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 0 additions and 58 deletions

View File

@ -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!"

View File

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