fix(archive): dburl check (#2071)

* dburl.nim: simpler regex that can support db_urls with . and - in hostname
* dbrul.nim: accepting any non-empty sequence for user and password
* dburl.nim: skipping validation for 'sqlite' db paths
This commit is contained in:
Ivan Folgueira Bande 2023-09-26 13:59:54 +02:00 committed by GitHub
parent 1763b1efa1
commit a27d005ffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 14 deletions

View File

@ -509,18 +509,6 @@ proc parseCmdArg*(T: type Option[uint], p: string): T =
except CatchableError:
raise newException(ValueError, "Invalid unsigned integer")
## Configuration validation
let DbUrlRegex = re"^[\w\+]+:\/\/[\w\/\\\.\:\@]+$"
proc validateDbUrl*(val: string): ConfResult[string] =
let val = val.strip()
if val == "" or val == "none" or val.match(DbUrlRegex):
ok(val)
else:
err("invalid 'db url' option format: " & val)
## Load
proc readValue*(r: var TomlReader, value: var crypto.PrivateKey) {.raises: [SerializationError].} =

View File

@ -7,9 +7,9 @@ import
proc validateDbUrl*(dbUrl: string): Result[string, string] =
## dbUrl mimics SQLAlchemy Database URL schema
## See: https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls
let regex = re"^[\w\+]+:\/\/[\w\/\\\.\:\@]+$"
let regex = re"^\w+:\/\/.+:.+@[\w*-.]+:[0-9]+\/[\w*-.]+$"
let dbUrl = dbUrl.strip()
if dbUrl == "" or dbUrl == "none" or dbUrl.match(regex):
if "sqlite" in dbUrl or dbUrl == "" or dbUrl == "none" or dbUrl.match(regex):
return ok(dbUrl)
else:
return err("invalid 'db url' option format: " & dbUrl)