Skip to content

Commit b7ebb24

Browse files
committed
change: Set jwt-aud default value to \`\' (accepting only empty string)
Fixes #4134 (JWT with aud claim should be rejected if jwt-aud is not set) Updated default jwt-aud value in Config module. Updated spec tests.
1 parent edf86e4 commit b7ebb24

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docs/references/auth.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ It works this way:
203203
Examples:
204204
- To make PostgREST accept ``aud`` claim value from a set ``audience1``, ``audience2``, ``otheraudience``, :ref:`jwt-aud` claim should be set to ``audience1|audience2|otheraudience``.
205205
- To make PostgREST accept ``aud`` claim value matching any ``https`` URI pointing to a host in ``example.com`` domain, :ref:`jwt-aud` claim should be set to ``https://[a-zA-Z0-9_]*\.example\.com``.
206-
- To make PostgREST accept any ``aud`` claim value , :ref:`jwt-aud` claim should be set to ``.*`` (which is the default).
206+
- To make PostgREST accept any ``aud`` claim value , :ref:`jwt-aud` claim should be set to ``.*``.
207207

208208
.. _jwt_caching:
209209

src/PostgREST/Config.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ parseCfgAud = fmap CfgAud . (fmap . ParsedValue . Just <*> parseRegex)
9090
bounded = ("\\`(" <>) . (<> "\\')")
9191

9292
defaultCfgAud :: CfgAud
93-
defaultCfgAud = CfgAud $ ParsedValue Nothing $ R.makeRegex (".*"::Text)
93+
defaultCfgAud = CfgAud $ ParsedValue Nothing $ R.makeRegex ("\\`\\'"::Text)
9494

9595
audMatchesCfg :: AppConfig -> Text -> Bool
9696
audMatchesCfg = R.matchTest . parsedValue . unCfgAud . configJwtAudience

test/spec/Feature/Auth/AudienceJwtSecretSpec.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ disabledSpec :: SpecWith ((), Application)
151151
disabledSpec = describe "test handling of aud claims in JWT when the jwt-aud config is not set" $ do
152152

153153
context "when the audience claim is a string" $ do
154-
it "ignores the audience claim and suceeds" $ do
154+
it "fails when it is not empty" $ do
155155
let jwtPayload =
156156
[json|{
157157
"exp": 9999999999,
@@ -161,7 +161,7 @@ disabledSpec = describe "test handling of aud claims in JWT when the jwt-aud con
161161
}|]
162162
auth = authHeaderJWT $ generateJWT jwtPayload
163163
request methodGet "/authors_only" [auth] ""
164-
`shouldRespondWith` 200
164+
`shouldRespondWith` 401
165165

166166
it "ignores the audience claim and suceeds when it's empty" $ do
167167
let jwtPayload =
@@ -176,7 +176,7 @@ disabledSpec = describe "test handling of aud claims in JWT when the jwt-aud con
176176
`shouldRespondWith` 200
177177

178178
context "when the audience is an array of strings" $ do
179-
it "ignores the audience claim and suceeds when it has 1 element" $ do
179+
it "fails it has 1 element" $ do
180180
let jwtPayload = [json|
181181
{
182182
"exp": 9999999999,
@@ -186,9 +186,9 @@ disabledSpec = describe "test handling of aud claims in JWT when the jwt-aud con
186186
}|]
187187
auth = authHeaderJWT $ generateJWT jwtPayload
188188
request methodGet "/authors_only" [auth] ""
189-
`shouldRespondWith` 200
189+
`shouldRespondWith` 401
190190

191-
it "ignores the audience claim and suceeds when it has more than 1 element" $ do
191+
it "fails when it has more than 1 element" $ do
192192
let jwtPayload = [json|
193193
{
194194
"exp": 9999999999,
@@ -198,7 +198,7 @@ disabledSpec = describe "test handling of aud claims in JWT when the jwt-aud con
198198
}|]
199199
auth = authHeaderJWT $ generateJWT jwtPayload
200200
request methodGet "/authors_only" [auth] ""
201-
`shouldRespondWith` 200
201+
`shouldRespondWith` 401
202202

203203
it "ignores the audience claim and suceeds when it's empty" $ do
204204
let jwtPayload = [json|

0 commit comments

Comments
 (0)