@nitra/cf-security 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/jwt.js +11 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/cf-security",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "check header in serverless",
5
5
  "type": "module",
6
6
  "exports": {
package/src/jwt.js CHANGED
@@ -15,9 +15,19 @@ export default async (req, allowedRoles) => {
15
15
  if (req.headers?.authorization) {
16
16
  // ігноруючи expired
17
17
  const token = await verify(req.headers.authorization.split(' ')[1], { ignoreExpiration: true })
18
+
19
+ const intersectRoles = intersection(
20
+ token.body['https://hasura.io/jwt/claims']['x-hasura-allowed-roles'],
21
+ allowedRoles
22
+ )
23
+
24
+ if (intersectRoles.length === 0) {
25
+ throw new Error(`[verification] unallowed roles ${allowedRoles}`)
26
+ }
27
+
18
28
  return token.body
19
29
  } else {
20
- return { name: 'dev', 'https://hasura.io/jwt/claims': { 'x-hasura-allowed-roles': allowedRoles } }
30
+ return JSON.stringify({ name: 'dev', 'https://hasura.io/jwt/claims': { 'x-hasura-allowed-roles': allowedRoles } })
21
31
  }
22
32
  }
23
33