@sssb/kit 0.4.0 → 0.6.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.
- package/dist/release.json +1 -1
- package/package.json +3 -1
- package/src/adapters/auth-tenancy.ts +157 -0
- package/src/adapters/configured-auth.ts +183 -0
- package/src/adapters/email-message.ts +30 -0
- package/src/adapters/fake/analytics.ts +1 -1
- package/src/adapters/fake/auth.ts +53 -3
- package/src/adapters/fake/data-dir.ts +32 -2
- package/src/adapters/fake/email.ts +2 -0
- package/src/adapters/fake/jobs.ts +5 -4
- package/src/adapters/fake/simulated-auth.ts +24 -0
- package/src/adapters/index.ts +3 -2
- package/src/adapters/real/accept-invite-form.tsx +32 -14
- package/src/adapters/real/analytics.ts +29 -2
- package/src/adapters/real/auth.ts +127 -23
- package/src/adapters/real/contract-postgres.ts +15 -11
- package/src/adapters/real/email.ts +2 -0
- package/src/adapters/real/index.ts +19 -3
- package/src/adapters/real/jobs-in-process.ts +32 -14
- package/src/adapters/real/jobs.ts +6 -3
- package/src/adapters/real/migrate-handler.ts +3 -1
- package/src/adapters/real/rds-data-codec.ts +88 -4
- package/src/adapters/real/rds-data-emulator.ts +12 -4
- package/src/adapters/real/sign-in-form.tsx +29 -13
- package/src/authz/app-exemptions.ts +79 -9
- package/src/authz/authorize.ts +4 -1
- package/src/authz/route-scan.ts +626 -55
- package/src/components/auth/accept-invite-screen.tsx +5 -1
- package/src/components/auth/people-picker.tsx +20 -2
- package/src/components/profile-screen.tsx +27 -2
- package/src/core/abilities.ts +22 -6
- package/src/core/inbound-email.ts +41 -6
- package/src/core/jobs.ts +17 -0
- package/src/core/roles.ts +17 -2
- package/src/cutover/rows.json +4 -0
- package/src/db/jobs.ts +32 -11
- package/src/db/keyset.ts +8 -6
- package/src/db/migrations/0015_app_user_grant.ts +1 -1
- package/src/db/migrations/0017_job_requester.ts +20 -0
- package/src/db/migrations/index.ts +2 -0
- package/src/db/rls-coverage.ts +51 -17
- package/src/db/schedules.ts +9 -3
- package/src/db/schema.ts +2 -0
- package/src/demo-static/actor-drivers.ts +8 -2
- package/src/demo-static/contracts.ts +9 -0
- package/src/demo-static/email-html.ts +9 -0
- package/src/demo-static/rows.ts +2 -0
- package/src/demo-static/tour/use-tours.tsx +8 -2
- package/src/demo-static/world.ts +98 -41
- package/src/email/send.ts +6 -2
- package/src/guide.md +37 -6
- package/src/i18n/messages/en.json +3 -0
- package/src/i18n/messages/es.json +3 -0
- package/src/i18n/messages.ts +3 -2
- package/src/ports/auth.ts +10 -1
- package/src/server-lib/notify.ts +51 -9
- package/src/server-lib/scheduled-tick.ts +5 -1
- package/src/server-lib/webhook-dispatch.ts +3 -0
- package/src/service-auth/mailgun.ts +19 -4
- package/src/testing/conformance/auth-provider.ts +17 -5
- package/src/testing/conformance/authz.ts +6 -2
- package/src/testing/conformance/demo-presets.ts +4 -4
- package/src/testing/conformance/i18n.ts +99 -5
- package/src/testing/conformance/suite.ts +63 -3
|
@@ -67,7 +67,13 @@ export function sqlSegments(sql: string): SqlSegment[] {
|
|
|
67
67
|
literal(blockCommentEnd(sql, i))
|
|
68
68
|
} else if (ch === "'") {
|
|
69
69
|
const escapes = (prev === 'E' || prev === 'e') && !IDENT_CHAR.test(i > 1 ? sql[i - 2]! : '')
|
|
70
|
-
|
|
70
|
+
// Two string constants separated only by whitespace holding a newline are one constant, and a
|
|
71
|
+
// continued E-string keeps its backslash escapes: `E'a'<newline>'\' $1'` is one string.
|
|
72
|
+
let end = quotedEnd(sql, i, "'", escapes)
|
|
73
|
+
for (let gap = CONTINUATION.exec(sql.slice(end)); gap; gap = CONTINUATION.exec(sql.slice(end))) {
|
|
74
|
+
end = quotedEnd(sql, end + gap[0].length - 1, "'", escapes)
|
|
75
|
+
}
|
|
76
|
+
literal(end)
|
|
71
77
|
} else if (ch === '"') {
|
|
72
78
|
literal(quotedEnd(sql, i, '"', false))
|
|
73
79
|
} else if (ch === '$' && !IDENT_CHAR.test(prev) && !/^\$\d/.test(sql.slice(i, i + 2))) {
|
|
@@ -88,6 +94,14 @@ export function sqlSegments(sql: string): SqlSegment[] {
|
|
|
88
94
|
return segments
|
|
89
95
|
}
|
|
90
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Whitespace holding at least one newline (`\n` or a bare `\r`, both newlines to Postgres's lexer), then the `'` that
|
|
99
|
+
* continues a string constant. A known limit: Postgres
|
|
100
|
+
* also allows a `-- comment` in that gap (`'a' -- note<newline>'b'`), which this does not, so such SQL is split into
|
|
101
|
+
* two literals here. Hand-written SQL only; Kysely never writes it.
|
|
102
|
+
*/
|
|
103
|
+
const CONTINUATION = /^[ \t\f]*[\r\n]\s*'/
|
|
104
|
+
|
|
91
105
|
const PLACEHOLDER = new RegExp(`(?<!${IDENT_CHAR.source})\\$(\\d+)`, 'g')
|
|
92
106
|
|
|
93
107
|
/**
|
|
@@ -311,12 +325,26 @@ function serializeScalar(value: unknown): string {
|
|
|
311
325
|
if (typeof value === 'boolean') return value ? 'true' : 'false'
|
|
312
326
|
if (value instanceof Date) {
|
|
313
327
|
if (Number.isNaN(value.getTime())) throw new TypeError('cannot send an invalid Date to the database')
|
|
314
|
-
return value
|
|
328
|
+
return postgresInstant(value)
|
|
315
329
|
}
|
|
316
330
|
if (value instanceof Uint8Array) return `\\x${Buffer.from(value).toString('hex')}`
|
|
317
331
|
return JSON.stringify(value)
|
|
318
332
|
}
|
|
319
333
|
|
|
334
|
+
/**
|
|
335
|
+
* A Date as an instant Postgres's timestamp input reads. `toISOString` writes a year outside 1-9999 in its
|
|
336
|
+
* expanded form (`-000043-…`, `+010000-…`), which Postgres refuses ("time zone displacement out of range"), where
|
|
337
|
+
* node-postgres sends such a Date and Postgres stores it. So a year before 1 is written as its BC year (JavaScript's
|
|
338
|
+
* year 0 is 1 BC, -43 is 44 BC) with Postgres's ` BC` suffix, and a year after 9999 with its digits unpadded.
|
|
339
|
+
*/
|
|
340
|
+
function postgresInstant(value: Date): string {
|
|
341
|
+
const year = value.getUTCFullYear()
|
|
342
|
+
const iso = value.toISOString()
|
|
343
|
+
if (year >= 1 && year <= 9999) return iso
|
|
344
|
+
const rest = iso.slice(iso.indexOf('-', 1))
|
|
345
|
+
return year < 1 ? `${String(1 - year).padStart(4, '0')}${rest} BC` : `${year}${rest}`
|
|
346
|
+
}
|
|
347
|
+
|
|
320
348
|
function arrayLiteral(values: readonly unknown[]): string {
|
|
321
349
|
const items = values.map((item) => {
|
|
322
350
|
if (item === null || item === undefined) return 'NULL'
|
|
@@ -334,7 +362,8 @@ function arrayLiteral(values: readonly unknown[]): string {
|
|
|
334
362
|
* One result row, keyed by column label, each value decoded to what node-postgres returns through SSSB's
|
|
335
363
|
* pg adapter (../real/db.ts): `int8`/`numeric` as strings (but `numeric[]` elements as numbers, as
|
|
336
364
|
* node-postgres has it), `json`/`jsonb` parsed, `timestamptz` as a `Date` (`±Infinity` for infinity),
|
|
337
|
-
* `date` as the wire string, `bytea` as a Buffer, arrays element by element
|
|
365
|
+
* `date` as the wire string, `bytea` as a Buffer, arrays element by element (but an array of a type node-postgres
|
|
366
|
+
* has no array parser for, an enum's say, as Postgres's text form, `{happy,sad}`). Types SSSB's migrations do
|
|
338
367
|
* not use and node-postgres parses into objects (`interval`) come back as the Data API's string.
|
|
339
368
|
*/
|
|
340
369
|
export function decodeRow(record: readonly Field[], columns: readonly ColumnMetadata[]): Record<string, unknown> {
|
|
@@ -348,11 +377,66 @@ export function decodeRow(record: readonly Field[], columns: readonly ColumnMeta
|
|
|
348
377
|
export function decodeField(field: Field | undefined, typeName: string): unknown {
|
|
349
378
|
if (!field || field.isNull) return null
|
|
350
379
|
const type = typeName.toLowerCase().replace(/^"|"$/g, '')
|
|
351
|
-
if (field.arrayValue !== undefined)
|
|
380
|
+
if (field.arrayValue !== undefined) {
|
|
381
|
+
const baseType = type.replace(/^_/, '')
|
|
382
|
+
// node-postgres returns an array of a type it has no parser for (an enum's, `bit[]`, `name[]`) as Postgres's
|
|
383
|
+
// text form, `{happy,sad}`, not as a JS array: so does this, or the two transports would disagree.
|
|
384
|
+
if (!PG_PARSED_ARRAYS.has(baseType)) return arrayText(field.arrayValue)
|
|
385
|
+
return decodeArray(field.arrayValue, baseType)
|
|
386
|
+
}
|
|
352
387
|
const raw = field.stringValue ?? field.longValue ?? field.doubleValue ?? field.booleanValue ?? field.blobValue
|
|
353
388
|
return decodeScalar(raw, type)
|
|
354
389
|
}
|
|
355
390
|
|
|
391
|
+
/**
|
|
392
|
+
* The element types whose arrays node-postgres parses into a JS array: pg-types' text parsers (pg 8), named as
|
|
393
|
+
* `pg_type.typname` names them (`bpchar` is `char(n)`; `char`, the one-byte type, has none).
|
|
394
|
+
*/
|
|
395
|
+
const PG_PARSED_ARRAYS: ReadonlySet<string> = new Set([
|
|
396
|
+
'bool',
|
|
397
|
+
'bpchar',
|
|
398
|
+
'bytea',
|
|
399
|
+
'cidr',
|
|
400
|
+
'date',
|
|
401
|
+
'float4',
|
|
402
|
+
'float8',
|
|
403
|
+
'inet',
|
|
404
|
+
'int2',
|
|
405
|
+
'int4',
|
|
406
|
+
'int8',
|
|
407
|
+
'interval',
|
|
408
|
+
'json',
|
|
409
|
+
'jsonb',
|
|
410
|
+
'macaddr',
|
|
411
|
+
'money',
|
|
412
|
+
'numeric',
|
|
413
|
+
'numrange',
|
|
414
|
+
'oid',
|
|
415
|
+
'point',
|
|
416
|
+
'regproc',
|
|
417
|
+
'text',
|
|
418
|
+
'time',
|
|
419
|
+
'timestamp',
|
|
420
|
+
'timestamptz',
|
|
421
|
+
'timetz',
|
|
422
|
+
'uuid',
|
|
423
|
+
'varchar',
|
|
424
|
+
])
|
|
425
|
+
|
|
426
|
+
/** An array as Postgres's text output writes it: `{a,"b c",NULL,{1,2}}`. */
|
|
427
|
+
function arrayText(value: ArrayValue): string {
|
|
428
|
+
if (value.arrayValues) return `{${value.arrayValues.map((inner) => (inner ? arrayText(inner) : 'NULL')).join(',')}}`
|
|
429
|
+
const items: readonly unknown[] =
|
|
430
|
+
value.stringValues ?? value.longValues ?? value.doubleValues ?? value.booleanValues ?? []
|
|
431
|
+
return `{${items.map((item) => (item === null || item === undefined ? 'NULL' : arrayTextItem(String(item)))).join(',')}}`
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** One element of Postgres's array output: quoted, with `"` and `\` escaped, when it would not read back bare. */
|
|
435
|
+
function arrayTextItem(item: string): string {
|
|
436
|
+
if (item !== '' && !/[{}",\\\s]/.test(item) && item.toUpperCase() !== 'NULL') return item
|
|
437
|
+
return `"${item.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
|
|
438
|
+
}
|
|
439
|
+
|
|
356
440
|
function decodeArray(value: ArrayValue, baseType: string): unknown[] {
|
|
357
441
|
if (value.arrayValues) return value.arrayValues.map((inner) => (inner ? decodeArray(inner, baseType) : null))
|
|
358
442
|
const items: readonly unknown[] =
|
|
@@ -150,7 +150,6 @@ export class RdsDataEmulator implements RdsDataClientLike {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
try {
|
|
153
|
-
const typeNames = await this.#types(client)
|
|
154
153
|
let result
|
|
155
154
|
try {
|
|
156
155
|
result = await client.query({ text, values, rowMode: 'array' })
|
|
@@ -158,6 +157,10 @@ export class RdsDataEmulator implements RdsDataClientLike {
|
|
|
158
157
|
// Message only, no SQLSTATE: the worst case the Data API is reported to return.
|
|
159
158
|
throw awsError('DatabaseErrorException', `ERROR: ${(error as Error).message}`, error)
|
|
160
159
|
}
|
|
160
|
+
const typeNames = await this.#types(
|
|
161
|
+
client,
|
|
162
|
+
result.fields.map((field) => field.dataTypeID),
|
|
163
|
+
)
|
|
161
164
|
const longAsString = input.resultSetOptions?.longReturnType === 'STRING'
|
|
162
165
|
const columns: ColumnMetadata[] = result.fields.map((field) => ({
|
|
163
166
|
name: field.name,
|
|
@@ -199,10 +202,15 @@ export class RdsDataEmulator implements RdsDataClientLike {
|
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* `pg_type.typname` by oid, which is what PgJDBC reports as a column's type name (`_text` for text[]). Read again
|
|
207
|
+
* when a result has an oid the cached map lacks: a type a migration created after the first read (an enum, its
|
|
208
|
+
* array) would otherwise be `unknown` for ever, and a value of it would come back in whatever shape `unknown`
|
|
209
|
+
* gets, hiding what the real Data API sends for it.
|
|
210
|
+
*/
|
|
203
211
|
// On the connection already held — with `maxConnections: 1` a second checkout would wait forever.
|
|
204
|
-
async #types(client: PoolClient): Promise<Map<number, string>> {
|
|
205
|
-
if (!this.#typeNames) {
|
|
212
|
+
async #types(client: PoolClient, oids: readonly number[]): Promise<Map<number, string>> {
|
|
213
|
+
if (!this.#typeNames || oids.some((oid) => !this.#typeNames!.has(oid))) {
|
|
206
214
|
const { rows } = await client.query<{ oid: string; typname: string }>('SELECT oid, typname FROM pg_type')
|
|
207
215
|
this.#typeNames = new Map(rows.map((row) => [Number(row.oid), row.typname]))
|
|
208
216
|
}
|
|
@@ -5,6 +5,8 @@ import { Button, PasswordInput, Stack, Text, TextInput } from '@mantine/core'
|
|
|
5
5
|
import { useForm } from '@mantine/form'
|
|
6
6
|
import { useState } from 'react'
|
|
7
7
|
|
|
8
|
+
import { sameOriginPath } from '../../core/same-origin-path'
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Clerk-headless credential form (ADR-0003) using @clerk/nextjs v7's signals API
|
|
10
12
|
* (signIn.password → status → finalize). MFA verification (status 'needs_second_factor') is a
|
|
@@ -12,6 +14,10 @@ import { useState } from 'react'
|
|
|
12
14
|
*
|
|
13
15
|
* AUTHORED — CUTOVER (`auth-dev`): never run against a real Clerk instance.
|
|
14
16
|
* Lives in packages/kit/src/adapters because it imports the vendor SDK; the SignInScreen renders it as a slot.
|
|
17
|
+
*
|
|
18
|
+
* `returnTo` usually comes from the URL, so the form goes there only when `sameOriginPath` accepts it, and to `/`
|
|
19
|
+
* otherwise: a page that forgot to check it must not turn sign-in into an open redirect (`/\evil.example` and
|
|
20
|
+
* `/<tab>/evil.example` pass a `startsWith('/')` check and leave the origin).
|
|
15
21
|
*/
|
|
16
22
|
export function RealSignInForm({ labels, returnTo }: { labels: SignInLabels; returnTo: string }) {
|
|
17
23
|
const { signIn, fetchStatus } = useSignIn()
|
|
@@ -20,18 +26,24 @@ export function RealSignInForm({ labels, returnTo }: { labels: SignInLabels; ret
|
|
|
20
26
|
|
|
21
27
|
const submit = form.onSubmit(async (values) => {
|
|
22
28
|
setFormError(null)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
// A Clerk call that throws (the network, not a refused password) is shown as the same generic error, never left
|
|
30
|
+
// as an unhandled rejection with nothing on screen.
|
|
31
|
+
try {
|
|
32
|
+
const { error } = await signIn.password({ identifier: values.email, password: values.password })
|
|
33
|
+
if (error) {
|
|
34
|
+
setFormError(labels.genericError)
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
if (signIn.status === 'complete') {
|
|
38
|
+
const finalized = await signIn.finalize()
|
|
39
|
+
if (finalized.error) setFormError(labels.genericError)
|
|
40
|
+
else window.location.assign(sameOriginPath(returnTo) ?? '/')
|
|
41
|
+
} else if (signIn.status === 'needs_second_factor') {
|
|
42
|
+
setFormError(labels.mfaNotImplemented)
|
|
43
|
+
} else {
|
|
44
|
+
setFormError(labels.genericError)
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
35
47
|
setFormError(labels.genericError)
|
|
36
48
|
}
|
|
37
49
|
})
|
|
@@ -44,7 +56,11 @@ export function RealSignInForm({ labels, returnTo }: { labels: SignInLabels; ret
|
|
|
44
56
|
<Button type="submit" loading={fetchStatus === 'fetching'}>
|
|
45
57
|
{labels.submit}
|
|
46
58
|
</Button>
|
|
47
|
-
{formError ?
|
|
59
|
+
{formError ? (
|
|
60
|
+
<Text c="red.8" role="alert">
|
|
61
|
+
{formError}
|
|
62
|
+
</Text>
|
|
63
|
+
) : null}
|
|
48
64
|
</Stack>
|
|
49
65
|
</form>
|
|
50
66
|
)
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
1
|
+
import { existsSync, statSync } from 'node:fs'
|
|
2
2
|
import { createRequire } from 'node:module'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { FRAMEWORK_POLICY, isGate } from './route-policy'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type Exemption,
|
|
7
|
+
type ScannedAction,
|
|
8
|
+
type ScannedRoute,
|
|
9
|
+
type ScanRoot,
|
|
10
|
+
type ScanPolicy,
|
|
11
|
+
judge,
|
|
12
|
+
judgeServerAction,
|
|
13
|
+
scanRoutes,
|
|
14
|
+
scanServerActions,
|
|
15
|
+
serverActionFilesOutsideSrc,
|
|
16
|
+
unreadRouteFiles,
|
|
17
|
+
} from './route-scan'
|
|
6
18
|
|
|
7
19
|
/**
|
|
8
20
|
* AN APP'S OWN AUTHORIZATION EXEMPTIONS, and the per-app authorization scan that applies them (the conformance
|
|
@@ -180,17 +192,38 @@ export interface AppScan {
|
|
|
180
192
|
root: ScanRoot
|
|
181
193
|
/** Every route file under the app's `src/app`, mutating or not. Empty when there is no `src/app`. */
|
|
182
194
|
routes: ScannedRoute[]
|
|
183
|
-
/**
|
|
195
|
+
/** Every Server Action under the app's `src`. */
|
|
196
|
+
actions: ScannedAction[]
|
|
197
|
+
/**
|
|
198
|
+
* One message per mutating handler or Server Action that fails (`<root>: <rel> <VERB> …why`), and one for each
|
|
199
|
+
* Pages Router API directory the app has, which the scan cannot read.
|
|
200
|
+
*/
|
|
184
201
|
failures: string[]
|
|
185
202
|
/** The app's exemptions file: malformed, colliding or stale entries. */
|
|
186
203
|
exemptionProblems: string[]
|
|
187
204
|
}
|
|
188
205
|
|
|
206
|
+
/** Whether `file` is a directory (through a link); false when it is missing or a file. */
|
|
207
|
+
function isDirectory(file: string): boolean {
|
|
208
|
+
try {
|
|
209
|
+
return statSync(file).isDirectory()
|
|
210
|
+
} catch {
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Where Next looks for Pages Router API routes: `pages/api` beside `src`, or inside it. */
|
|
216
|
+
const PAGES_API_DIRS = ['pages/api', 'src/pages/api']
|
|
217
|
+
|
|
189
218
|
/**
|
|
190
219
|
* The authorization scan over ONE app: every `route.*` under `<appDir>/src/app` (Next serves one from anywhere
|
|
191
|
-
* there, so not only `api
|
|
192
|
-
* measured from `<appDir>/src/app/api` (so a mutating route outside `api/` can match no
|
|
193
|
-
* `authorize(...)` itself).
|
|
220
|
+
* there, so not only `api/`, and through a symbolic link too), judged against the framework's policy plus the app's
|
|
221
|
+
* own exemptions, which are measured from `<appDir>/src/app/api` (so a mutating route outside `api/` can match no
|
|
222
|
+
* exemption and must call `authorize(...)` itself). Every Server Action under `<appDir>/src` (a `'use server'` file's
|
|
223
|
+
* exports, and each function whose body opens with `'use server'`) is judged as a POST is, and can match no
|
|
224
|
+
* exemption. A Pages Router API directory fails outright: SSSB apps are App Router, and the scan reads no
|
|
225
|
+
* `pages/api` handler. So does a root-level `app/` directory (Next serves it instead of `src/app`), and a file under
|
|
226
|
+
* `src/app` named `route.<ext>` for an extension the scan does not read (`pageExtensions` is not read). Re-exported handlers are followed with the app's `tsconfig.json` (or `jsconfig.json`).
|
|
194
227
|
*/
|
|
195
228
|
export async function scanApp(appDir: string): Promise<AppScan> {
|
|
196
229
|
const name = path.basename(appDir)
|
|
@@ -206,13 +239,50 @@ export async function scanApp(appDir: string): Promise<AppScan> {
|
|
|
206
239
|
const routes = existsSync(root.dir) ? scanRoutes([root]) : []
|
|
207
240
|
const mutating = routes.filter((route) => route.handlers.length > 0)
|
|
208
241
|
const policy = policyWithApp(exemptions)
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
)
|
|
242
|
+
const srcDir = path.join(appDir, 'src')
|
|
243
|
+
const actions = existsSync(srcDir) ? scanServerActions({ ...root, dir: srcDir, exemptDir: srcDir }) : []
|
|
244
|
+
const outsideUnreadable = new Map<string, string>()
|
|
245
|
+
const outsideActionFiles = serverActionFilesOutsideSrc(appDir, outsideUnreadable)
|
|
246
|
+
const failures = [
|
|
247
|
+
...mutating.flatMap((route) => route.handlers.flatMap((handler) => judge(route, handler, policy) ?? [])),
|
|
248
|
+
...actions.flatMap((action) => judgeServerAction(action) ?? []),
|
|
249
|
+
...(isDirectory(path.join(appDir, 'app'))
|
|
250
|
+
? [
|
|
251
|
+
`${name}: app/ is a root-level App Router directory. Next serves it and ignores src/app when both ` +
|
|
252
|
+
`exist, and the authorization scan reads only src/app, so no route in app/ is checked. Keep the ` +
|
|
253
|
+
`app's routes in src/app.`,
|
|
254
|
+
]
|
|
255
|
+
: []),
|
|
256
|
+
...(existsSync(root.dir) ? unreadRouteFiles(root.dir) : []).map(
|
|
257
|
+
(file) =>
|
|
258
|
+
`${name}: ${path.relative(appDir, file).split(path.sep).join('/')} is named like a route, but the ` +
|
|
259
|
+
`authorization scan reads only route.ts, route.tsx, route.js, route.jsx and route.mjs. If Next serves it ` +
|
|
260
|
+
`(a pageExtensions entry), nothing checked it: rename it to one of those, or rename it to something not ` +
|
|
261
|
+
`named route.`,
|
|
262
|
+
),
|
|
263
|
+
...[...outsideUnreadable].map(
|
|
264
|
+
([dir, code]) =>
|
|
265
|
+
`${name}: ${path.relative(appDir, dir).split(path.sep).join('/') || '.'} could not be read (${code}), so ` +
|
|
266
|
+
`a Server Action in it would go unchecked. Make it readable to the user running the check.`,
|
|
267
|
+
),
|
|
268
|
+
...outsideActionFiles.map(
|
|
269
|
+
(file) =>
|
|
270
|
+
`${name}: ${path.relative(appDir, file).split(path.sep).join('/')} declares Server Actions outside src, ` +
|
|
271
|
+
`where the authorization scan does not judge them. Move them under src. (Actions a workspace package ` +
|
|
272
|
+
`exports are not read either.)`,
|
|
273
|
+
),
|
|
274
|
+
...PAGES_API_DIRS.filter((dir) => existsSync(path.join(appDir, dir))).map(
|
|
275
|
+
(dir) =>
|
|
276
|
+
`${name}: ${dir} is a Pages Router API directory. SSSB apps are App Router, and the authorization scan ` +
|
|
277
|
+
`reads only route handlers under src/app and Server Actions, so nothing in ${dir} is checked. Move ` +
|
|
278
|
+
`each handler to a route.ts under src/app/api.`,
|
|
279
|
+
),
|
|
280
|
+
]
|
|
212
281
|
const label = `${name}/${APP_EXEMPTIONS_FILE}`
|
|
213
282
|
return {
|
|
214
283
|
root,
|
|
215
284
|
routes,
|
|
285
|
+
actions,
|
|
216
286
|
failures,
|
|
217
287
|
exemptionProblems: [
|
|
218
288
|
...problems,
|
package/src/authz/authorize.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type SubjectType,
|
|
11
11
|
defineAbilitiesFor,
|
|
12
12
|
} from '../core/abilities'
|
|
13
|
+
import { hasStanding } from '../core/roles'
|
|
13
14
|
import type { OrgIdentity } from '../db/org-lookup'
|
|
14
15
|
import type { AuthPort, AuthUser } from '../ports/auth'
|
|
15
16
|
import { ForbiddenError } from '../ports/errors'
|
|
@@ -48,7 +49,9 @@ export function abilityActorFromUser(user: AuthUser, activeOrgId: string): Abili
|
|
|
48
49
|
role: user.role,
|
|
49
50
|
restricted: user.restricted,
|
|
50
51
|
activeOrgId,
|
|
51
|
-
|
|
52
|
+
// Not for a person without standing (role `none`): a fixed org source places every user of the identity
|
|
53
|
+
// provider in the home org, which may be the staff org. The ability layer refuses it again (defineAbilitiesFor).
|
|
54
|
+
manageAll: user.orgSlug === staffOrgSlug && hasStanding(user.role),
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|