@fabrika/auth 0.5.5 → 0.7.0

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 +3 -3
  2. package/src/app-schema.ts +24 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/auth",
3
- "version": "0.5.5",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "zod": "^3.25.76",
30
- "@fabrika/auth-core": "0.5.5",
31
- "@fabrika/jwks": "0.5.5",
30
+ "@fabrika/auth-core": "0.7.0",
31
+ "@fabrika/jwks": "0.7.0",
32
32
  "jose": "^5.9.0"
33
33
  }
34
34
  }
package/src/app-schema.ts CHANGED
@@ -3,9 +3,11 @@ import {
3
3
  BUILTIN_ROLE_KEYS,
4
4
  displayNameProblem,
5
5
  isActionAllowed,
6
+ isOwnWorkloadName,
6
7
  LOCALES,
7
8
  mailTemplateProblems,
8
9
  type MessageKind,
10
+ WORKLOAD_NAME,
9
11
  } from '@fabrika/auth-core'
10
12
  import { z } from 'zod'
11
13
 
@@ -46,8 +48,10 @@ const delegationSchema = z.object({
46
48
  purpose: z.enum(['members', 'creates']),
47
49
  })
48
50
 
49
- /** A job or webhook name of a contract; an `app` workload is named by the consuming application's id. */
50
- const WORKLOAD_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/
51
+ /**
52
+ * A job or webhook name of a contract; a public procedure is named by its endpoint id, an `app` workload by the
53
+ * consuming application's id.
54
+ */
51
55
  const APP_ID = /^[a-z0-9][a-z0-9-]{0,63}$/
52
56
  const workloadSchema = z.discriminatedUnion('kind', [
53
57
  z.object({
@@ -57,6 +61,11 @@ const workloadSchema = z.discriminatedUnion('kind', [
57
61
  issues: z.string().min(1).optional(),
58
62
  }),
59
63
  z.object({ kind: z.literal('webhook'), name: z.string().regex(WORKLOAD_NAME), actions: z.array(z.string().min(1)) }),
64
+ z.object({
65
+ kind: z.literal('public'),
66
+ name: z.string().refine((name) => isOwnWorkloadName('public', name), 'a public procedure is named by its endpoint id'),
67
+ actions: z.array(z.string().min(1)).min(1),
68
+ }),
60
69
  z.object({ kind: z.literal('app'), name: z.string().regex(APP_ID), actions: z.array(z.string().min(1)) }),
61
70
  ])
62
71
 
@@ -168,6 +177,19 @@ function membershipIssues(schema: z.infer<typeof appSchemaShape>): Issue[] {
168
177
  }
169
178
  }
170
179
  }
180
+ // A role change would otherwise widen what anyone may reach through a public procedure, unseen by its approval.
181
+ const granted = new Set(Object.values(schema.roles).flatMap((role) => role.permissions))
182
+ for (const [index, workload] of (schema.workloads ?? []).entries()) {
183
+ if (workload.kind !== 'public') continue
184
+ for (const [position, action] of workload.actions.entries()) {
185
+ if (granted.has(action)) {
186
+ issues.push({
187
+ path: ['workloads', index, 'actions', position],
188
+ message: `public procedure ${quote(workload.name)} holds ${quote(action)}, which a role grants; a public action is held by no role`,
189
+ })
190
+ }
191
+ }
192
+ }
171
193
  for (const [endpoint, delegation] of Object.entries(schema.delegations ?? {})) {
172
194
  const dimension = dimensions.get(delegation.dimension)
173
195
  exactAction(['delegations', endpoint, 'action'], delegation.action)