Do not share JWT secret with SQL
This commit is contained in:
@@ -7,7 +7,6 @@ module PostgREST.App (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Monad ((>>))
|
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import Data.IORef (IORef, readIORef)
|
import Data.IORef (IORef, readIORef)
|
||||||
import Data.List (delete, lookup)
|
import Data.List (delete, lookup)
|
||||||
@@ -98,8 +97,6 @@ transactionMode _ = HT.Write
|
|||||||
|
|
||||||
app :: DbStructure -> AppConfig -> ApiRequest -> H.Transaction Response
|
app :: DbStructure -> AppConfig -> ApiRequest -> H.Transaction Response
|
||||||
app dbStructure conf apiRequest =
|
app dbStructure conf apiRequest =
|
||||||
exposeSecretToSQL (configJwtSecret conf) >>
|
|
||||||
|
|
||||||
case (iAction apiRequest, iTarget apiRequest, iPayload apiRequest) of
|
case (iAction apiRequest, iTarget apiRequest, iPayload apiRequest) of
|
||||||
|
|
||||||
(ActionRead, TargetIdent qi, Nothing) ->
|
(ActionRead, TargetIdent qi, Nothing) ->
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import PostgREST.ApiRequest (ApiRequest(..), ContentType(..),
|
|||||||
import PostgREST.Auth (claimsToSQL, JWTAttempt(..))
|
import PostgREST.Auth (claimsToSQL, JWTAttempt(..))
|
||||||
import PostgREST.Config (AppConfig (..), corsPolicy)
|
import PostgREST.Config (AppConfig (..), corsPolicy)
|
||||||
import PostgREST.Error (errResponse)
|
import PostgREST.Error (errResponse)
|
||||||
import PostgREST.QueryBuilder (pgFmtLit)
|
|
||||||
|
|
||||||
import Protolude hiding (concat, null)
|
import Protolude hiding (concat, null)
|
||||||
|
|
||||||
@@ -46,11 +45,6 @@ runWithClaims conf eClaims app req =
|
|||||||
]
|
]
|
||||||
(toS $ "{\"message\":\""<>message<>"\"}")
|
(toS $ "{\"message\":\""<>message<>"\"}")
|
||||||
|
|
||||||
exposeSecretToSQL :: Maybe Text -> H.Transaction ()
|
|
||||||
exposeSecretToSQL mS =
|
|
||||||
for_ mS $ \s ->
|
|
||||||
H.sql $ "set local postgrest.jwt_secret = " <> toS (pgFmtLit s) <> ";"
|
|
||||||
|
|
||||||
defaultMiddle :: Application -> Application
|
defaultMiddle :: Application -> Application
|
||||||
defaultMiddle =
|
defaultMiddle =
|
||||||
gzip def
|
gzip def
|
||||||
|
|||||||
Vendored
+2
-2
@@ -194,7 +194,7 @@ CREATE FUNCTION login(id text, pass text) RETURNS public.jwt_token
|
|||||||
LANGUAGE sql SECURITY DEFINER
|
LANGUAGE sql SECURITY DEFINER
|
||||||
AS $$
|
AS $$
|
||||||
SELECT jwt.sign(
|
SELECT jwt.sign(
|
||||||
row_to_json(r), current_setting('postgrest.jwt_secret')
|
row_to_json(r), 'safe'
|
||||||
) as token
|
) as token
|
||||||
FROM (
|
FROM (
|
||||||
SELECT rolname::text, id::text
|
SELECT rolname::text, id::text
|
||||||
@@ -227,7 +227,7 @@ CREATE FUNCTION jwt_test() RETURNS public.jwt_token
|
|||||||
LANGUAGE sql SECURITY DEFINER
|
LANGUAGE sql SECURITY DEFINER
|
||||||
AS $$
|
AS $$
|
||||||
SELECT jwt.sign(
|
SELECT jwt.sign(
|
||||||
row_to_json(r), current_setting('postgrest.jwt_secret')
|
row_to_json(r), 'safe'
|
||||||
) as token
|
) as token
|
||||||
FROM (
|
FROM (
|
||||||
SELECT 'joe'::text as iss, 'fun'::text as sub, 'everyone'::text as aud,
|
SELECT 'joe'::text as iss, 'fun'::text as sub, 'everyone'::text as aud,
|
||||||
|
|||||||
Reference in New Issue
Block a user