add: log error when db-schemas config contain restricted schemas
We don't allow accessing schemas "pg_catalog" and "information_schema". Instead of silently failing requests on these schemas, this now adds logging an error on startup when these schemas are found in `db-schemas` config. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
Steve Chavez
parent
c232e97f80
commit
abad47ff1b
+13
-2
@@ -274,8 +274,7 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
|
||||
<*> (fromMaybe True <$> optBool "db-prepared-statements")
|
||||
<*> (fmap toQi <$> optWithAlias (optString "db-root-spec")
|
||||
(optString "root-spec"))
|
||||
<*> (fromList . maybe ["public"] splitOnCommas <$> optWithAlias (optString "db-schemas")
|
||||
(optString "db-schema"))
|
||||
<*> parseDbSchemas "db-schemas" "db-schema"
|
||||
<*> (fromMaybe True <$> optBool "db-config")
|
||||
<*> (fmap toQi <$> optString "db-pre-config")
|
||||
<*> parseTxEnd "db-tx-end" snd
|
||||
@@ -329,6 +328,18 @@ parser optPath env dbSettings roleSettings roleIsolationLvl =
|
||||
Just asp | asp == serverPort -> fail "admin-server-port cannot be the same as server-port"
|
||||
| otherwise -> pure $ Just asp
|
||||
|
||||
parseDbSchemas :: C.Key -> C.Key -> C.Parser C.Config (NonEmpty Text)
|
||||
parseDbSchemas k al =
|
||||
optWithAlias (optString k) (optString al) >>= \case
|
||||
Nothing -> pure $ fromList ["public"]
|
||||
Just s
|
||||
| "pg_catalog" `elem` schemas -> fail (errMsg "pg_catalog")
|
||||
| "information_schema" `elem` schemas -> fail (errMsg "information_schema")
|
||||
| otherwise -> pure $ fromList schemas
|
||||
where
|
||||
schemas = splitOnCommas s
|
||||
errMsg x = ("db-schemas does not allow schema: '" <> x <> "'")
|
||||
|
||||
parseSocketFileMode :: C.Key -> C.Parser C.Config FileMode
|
||||
parseSocketFileMode k =
|
||||
optString k >>= \case
|
||||
|
||||
Reference in New Issue
Block a user