Skip to content

Commit

Permalink
fix(archive): dburl check (#2071)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ivansete-status authored Sep 26, 2023
1 parent 1763b1e commit a27d005
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
12 changes: 0 additions & 12 deletions apps/wakunode2/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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].} =
Expand Down
4 changes: 2 additions & 2 deletions waku/common/databases/dburl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a27d005

Please sign in to comment.