@mistriwork/mistri 1.0.0-rc.54 → 1.0.0-rc.56

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/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  The 1.0 release candidates of `@mistriwork/mistri`. Every earlier release is in the full changelog.
4
4
 
5
+ ## 1.0.0-rc.56
6
+
7
+ - **One-time codes charge each try before comparing it.** A burst of guesses typed together used to read the count before any wrote it, so more than five could be judged against one code. Every try, right or wrong, now takes its own number from one atomic count first, and a try past five is refused unjudged. A right code within the five still opens, once.
8
+ - **`mistri check` warns when a signed-out `byKey` read is keyed by a number** (`bykey-guessable`). The read is fenced to one row by its whole key, but a visitor can walk a counter's ids, so the key is the only secret: read by a UUID or a sealed reference.
9
+
10
+ ## 1.0.0-rc.55
11
+
12
+ - **A public form's submission counts the day in its tenant's zone.** Where `ui.timezone` names a column of the tenant profile (`tenant.<column>`), a submission placed with a tenant hands its handler that tenant's zone, so `today()` and `now()` agree with the tenant's members' commands and its jobs. A submission sent to the platform's triage, a tenant with no zone on its row, and a zone held on another table keep the App's zone: a visitor has no member scope to read another table under.
13
+ - **A message whose public links cannot be placed drops the sentences that held them.** Previously only the link was removed, which left sentences such as "Apply in steps at." Now the whole sentence goes, the sentences around it stay, and an empty line goes with it.
14
+ - **A command spread back into `defineCommand` keeps the reads its author declared.** Previously a registered command re-wrapped as `{ ...command, handle }`, or adopted, had every table it wrote read as declared, because the declaration lived beside the original object. The declaration now travels with the command. A spread that replaces `read` is read afresh.
15
+
5
16
  ## 1.0.0-rc.54
6
17
 
7
18
  - **`mistri migrate backstop new` writes a tenant App's row-security backstop** as the next V file (`tenant_backstop`) rather than leaving it to hand-written SQL. Everything in it comes from the App and its tenant policy: the runtime role (made `NOLOGIN`, never `BYPASSRLS`), `USAGE` on the App's schemas, reads and writes on the tables it writes, reads on its global tables, the sequences those tables own, and on each tenant table row security plus the one pinned `mistri_tenant` policy on its ownership column. The SQL is idempotent and applied by `migrate up` as the owner. Signing in as the role stays the operator's step, so no password lands in the file.
package/README.md CHANGED
@@ -30,7 +30,7 @@ App build to run on the supported Node 24 runtime; TypeScript examples also
30
30
  have an explicit typecheck (TypeScript 7 or later, the native compiler), and `mistri build` is the optional production
31
31
  step that runs it, validates the App and bundles it — see
32
32
  [Build and deploy an App](https://mistriwork.dev/docs/build-and-deploy/).
33
- These App features ship in mistri 1.0.0-rc.54; the
33
+ These App features ship in mistri 1.0.0-rc.56; the
34
34
  [status page](https://mistriwork.dev/docs/status/) says what is stable
35
35
  and what comes next. Start with the sample catalog (`examples/apps/README.md`),
36
36
  written for people and coding agents, then the [App DSL reference](https://mistriwork.dev/docs/app-dsl/) (the same pages read offline with `npx @mistriwork/mistri docs`).
package/dist/docs/cli.md CHANGED
@@ -144,6 +144,7 @@ step runs; the errors print first, and warnings are advisory (unless
144
144
  lists them in full. On PostgreSQL an indexes step names each foreign key, default
145
145
  sort, fixed filter, ownership column and search the App reads by that no index
146
146
  leads (index-missing), with the CREATE INDEX that adds it; --no-index-check skips it.
147
+ A signed-out byKey read keyed by a number is a bykey-guessable warning: a visitor can walk ids.
147
148
  A queries step has the database EXPLAIN each read the App's pages would make
148
149
  (lists, related and grouped lists, timelines, breakdowns, figures, rollups, and its own list tabs, dashboard figures and segments): one a
149
150
  statement, never run, in a READ ONLY transaction on PostgreSQL. A read it refuses
@@ -76,7 +76,7 @@ tenant App refuses one at startup ([Tenant Apps](/docs/tenant-apps/)).
76
76
  | Key | Type | Status | What it does |
77
77
  | --- | --- | --- | --- |
78
78
  | `auth.public` | object | Stable | What a signed-out visitor reads: each resource named, read-only, optionally narrowed by fields; the rest of the App still needs a session. Needs roles, and rows 'all'. Used in `examples/apps/lintel/app.ts`. |
79
- | `auth.public.byKey` | array | Stable | Of read, the resources a visitor opens one record at a time by its key and never lists, counts or searches: a link's page, not a directory. |
79
+ | `auth.public.byKey` | array | Stable | Of read, the resources a visitor opens one record at a time by its key and never lists, counts or searches: a link's page, not a directory. Its key must be unguessable (a UUID or a sealed reference); `check` warns on a numeric key. |
80
80
  | `auth.public.fields` | object | Stable | Used in `examples/apps/lintel/app.ts`. |
81
81
  | `auth.public.fields.*.read` | array | Stable | Used in `examples/apps/lintel/app.ts`. |
82
82
  | `auth.public.read` | array | Stable | Used in `examples/apps/lintel/app.ts`. |
@@ -181,6 +181,10 @@ read of another table that reaches it is refused, whichever route asked. `check`
181
181
  refuses a list or dashboard over it that names no `roles` (it would be served
182
182
  to visitors) and a public page that reads it.
183
183
 
184
+ The key is the only secret, so it must be unguessable: a UUID or a sealed
185
+ reference, never a counter a visitor can walk. `check` warns
186
+ (`bykey-guessable`) when a `byKey` resource's key is a number.
187
+
184
188
  Anything else a visitor asks for (a list, a record, a dashboard section over a
185
189
  table `auth.public` does not name) is answered `401` with the sign-in card, the
186
190
  same answer for a private table and for a name that is no table.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Status & roadmap
3
- description: The 1.0.0-rc.54 scope, stable and preview features, current limitations and planned work.
3
+ description: The 1.0.0-rc.56 scope, stable and preview features, current limitations and planned work.
4
4
  ---
5
5
 
6
6
  The scope of this release, stable and preview features, current limitations and planned work.
@@ -10,7 +10,7 @@ npx @mistriwork/mistri check --app .
10
10
  # preview: This App uses Preview features (…). They work as documented and may change in any 1.x release.
11
11
  ```
12
12
 
13
- This site describes **mistri 1.0.0-rc.54**, a release candidate. Since rc.2, the first release under the mistri name,
13
+ This site describes **mistri 1.0.0-rc.56**, a release candidate. Since rc.2, the first release under the mistri name,
14
14
  the App framework is split out of tablewalk, which stays the standalone database browser. A save is a fixed number of
15
15
  database round trips, the runtime forgets what it wrote about an App after the App's own retention windows, and on
16
16
  PostgreSQL the runtime lives in one schema named `mistri`. There is no upgrade from a tablewalk 0.9 App database.
@@ -171,7 +171,7 @@ entry points above:
171
171
  "version": "1.0.0",
172
172
  "type": "module",
173
173
  "exports": { ".": "./src/index.ts" },
174
- "peerDependencies": { "@mistriwork/mistri": "^1.0.0-rc.54" }
174
+ "peerDependencies": { "@mistriwork/mistri": "^1.0.0-rc.56" }
175
175
  }
176
176
  ```
177
177
 
@@ -4302,7 +4302,7 @@ async function ci(e, t, n, r, i) {
4302
4302
  if (!o.ok) throw Error(s?.error ?? `The surface "${r}" could not be opened (${o.status}).`);
4303
4303
  return s?.signedIn && s.surface ? s.surface : void 0;
4304
4304
  }
4305
- var li = "1.0.0-rc.54";
4305
+ var li = "1.0.0-rc.56";
4306
4306
  function ui({ endpoint: e, auth: t, app: n, surface: r, basePath: c, navigator: d, version: f = li, fallback: m, children: h }) {
4307
4307
  let g = e.replace(/\/+$/, ""), _ = o(t);
4308
4308
  _.current = t;
@@ -4,7 +4,7 @@ import { n as s, r as c, t as l } from "./chunks/router-CAJxIEw4.js";
4
4
  import { createContext as u, useContext as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
5
5
  import { jsx as g } from "react/jsx-runtime";
6
6
  // packages/mistri/src/embed/index.tsx
7
- var _ = "1.0.0-rc.54", v = u(null), y;
7
+ var _ = "1.0.0-rc.56", v = u(null), y;
8
8
  async function b(n, i, a) {
9
9
  let o = i?.authorization(), s = a ? `?${new URLSearchParams({
10
10
  app: a.app,
@@ -44,7 +44,7 @@ import { appComputedRules } from '../../shared/appComputed.js';
44
44
  import { formLinesProblems } from '../../shared/formLines.js';
45
45
  import { composeFeatures } from '../../shared/appFeatures.js';
46
46
  import { locateProblem, withProvenance } from '../../shared/appProvenance.js';
47
- import { appLiteralWarnings, appMenuWarnings, appReachWarnings, appRestatedWarnings } from '../../shared/appWarnings.js';
47
+ import { appLiteralWarnings, appMenuWarnings, appReachWarnings, appRestatedWarnings, publicKeyWarnings } from '../../shared/appWarnings.js';
48
48
  import { deprecatedOf } from '../../shared/deprecations.js';
49
49
  import { AUTHORITY_CHANGED, AUTHORITY_LOCK, assertAuthorityLock, authorityChange, readAuthority, } from './authorityLock.js';
50
50
  import { lockedTriggers } from '../commands/triggerLock.js';
@@ -1237,6 +1237,7 @@ export function appAdvisories(loaded, schema) {
1237
1237
  ...appLiteralWarnings(loaded.app, loaded.pages, schema),
1238
1238
  ...appReachWarnings(loaded.app, schema),
1239
1239
  ...appMenuWarnings(loaded.app),
1240
+ ...publicKeyWarnings(loaded.app, schema),
1240
1241
  ...appRestatedWarnings(loaded.app, schema).filter((warning) => !saidByMessage(loaded, warning)),
1241
1242
  ...messageAdvice(loaded),
1242
1243
  ...deprecatedOf(loaded.app),
@@ -349,6 +349,7 @@ Checking an App while authoring it — the one command of the loop:
349
349
  lists them in full. On PostgreSQL an indexes step names each foreign key, default
350
350
  sort, fixed filter, ownership column and search the App reads by that no index
351
351
  leads (index-missing), with the CREATE INDEX that adds it; --no-index-check skips it.
352
+ A signed-out byKey read keyed by a number is a bykey-guessable warning: a visitor can walk ids.
352
353
  A queries step has the database EXPLAIN each read the App's pages would make
353
354
  (lists, related and grouped lists, timelines, breakdowns, figures, rollups, and its own list tabs, dashboard figures and segments): one a
354
355
  statement, never run, in a READ ONLY transaction on PostgreSQL. A read it refuses
@@ -54,8 +54,16 @@ const commandEvents = new WeakMap();
54
54
  const commandSlots = new WeakMap();
55
55
  const commandEffects = new WeakMap();
56
56
  /* The tables its author named in `read` and in `write` both. `read` is the whole footprint, written tables
57
- included, so without this a table said twice reads as one only written (callerMustRead). */
58
- const declaredReads = new WeakMap();
57
+ included, so without this a table said twice reads as one only written (callerMustRead). It rides on the command
58
+ itself, enumerable, so a registered command spread back into defineCommand (adoptCommand, or an author's
59
+ `{ ...command, handle }`) keeps what its author said: from the spread `read` alone every written table would
60
+ read as declared. It names the `read` it was said beside, so a spread that replaces `read` is read afresh.
61
+ Symbol.for, so a second copy of this module reads the first's. */
62
+ const DECLARED_READS = Symbol.for('mistri.command.declaredReads');
63
+ const carriedReads = (command) => {
64
+ const carried = command[DECLARED_READS];
65
+ return carried && Array.isArray(carried.tables) ? carried : undefined;
66
+ };
59
67
  /* The callbacks as registration captured them: replacing one on the
60
68
  caller's object afterwards changes nothing that runs. */
61
69
  const commandRules = new WeakMap();
@@ -217,16 +225,18 @@ export function callerRead(command) {
217
225
  * named in `read` is a read the caller must hold.
218
226
  */
219
227
  export function callerMustRead(command) {
220
- const declared = declaredReads.get(command) ?? [];
228
+ const declared = carriedReads(command)?.tables ?? [];
221
229
  return callerRead(command).filter((table) => table === command.target || !command.write.includes(table) || declared.includes(table));
222
230
  }
223
- function plainRecord(value, where) {
231
+ function plainRecord(value, where, carried) {
224
232
  if (!value || typeof value !== 'object' || Array.isArray(value))
225
233
  return fail(`${where} must be a plain object.`);
226
234
  const prototype = Object.getPrototypeOf(value);
227
235
  if (prototype !== null && prototype !== Object.prototype)
228
236
  return fail(`${where} must not inherit configuration.`);
229
237
  for (const key of Reflect.ownKeys(value)) {
238
+ if (key === carried && carried !== undefined)
239
+ continue;
230
240
  if (typeof key !== 'string' || reserved.has(key))
231
241
  return fail(`${where} has an unsafe property.`);
232
242
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
@@ -402,7 +412,7 @@ const freezeDeep = (value) => {
402
412
  * The input type is the declaration's (CommandInputOf), or what `validate` returns.
403
413
  */
404
414
  export function defineCommand(definition) {
405
- const value = plainRecord(definition, 'Command');
415
+ const value = plainRecord(definition, 'Command', DECLARED_READS);
406
416
  for (const key of Object.keys(value)) {
407
417
  if (!definitionKeys.has(key))
408
418
  fail(`Command has an unknown option: ${key}.`);
@@ -420,7 +430,10 @@ export function defineCommand(definition) {
420
430
  const writes = resources(value.write, 'Command write footprint').filter((table) => table !== target);
421
431
  const named = resources(value.read, 'Command read footprint');
422
432
  const reads = named.filter((table) => table !== target && !writes.includes(table));
423
- const alsoWritten = named.filter((table) => table !== target && writes.includes(table));
433
+ /* A registered command spread back with its own `read` says what its author declared; that `read` holds every written table. */
434
+ const carried = carriedReads(value);
435
+ const declared = carried && carried.beside === value.read ? carried.tables : named;
436
+ const alsoWritten = declared.filter((table) => table !== target && writes.includes(table));
424
437
  const read = Object.freeze([target, ...reads, ...writes]), write = Object.freeze([target, ...writes]);
425
438
  const elevate = Object.hasOwn(value, 'elevate') ? elevateOption(value.elevate, target, reads, writes) : undefined;
426
439
  if (elevate && value.public === true)
@@ -683,6 +696,10 @@ export function defineCommand(definition) {
683
696
  };
684
697
  // Derived, so not spread: a registered command spreads back into defineCommand as its definition.
685
698
  Object.defineProperty(result, 'fields', { value: fields, enumerable: false });
699
+ Object.defineProperty(result, DECLARED_READS, {
700
+ value: Object.freeze({ beside: read, tables: Object.freeze(alsoWritten) }),
701
+ enumerable: true,
702
+ });
686
703
  Object.freeze(result);
687
704
  registered.add(result);
688
705
  if (capturedEvents)
@@ -691,8 +708,6 @@ export function defineCommand(definition) {
691
708
  commandSlots.set(result, slots);
692
709
  if (effects)
693
710
  commandEffects.set(result, effects.targets);
694
- if (alsoWritten.length)
695
- declaredReads.set(result, Object.freeze(alsoWritten));
696
711
  const stated = [];
697
712
  if (value.public === true && value.targets === 'none')
698
713
  stated.push("targets: 'none' is implied by public: true. Delete it.");
@@ -895,7 +910,7 @@ function recommand(id, command, changes) {
895
910
  Object.defineProperty(copy, 'fields', { value: changes.fields ?? command.fields, enumerable: false });
896
911
  Object.freeze(copy);
897
912
  registered.add(copy);
898
- for (const map of [commandEvents, commandSlots, commandEffects, commandRules, restatements, declaredReads]) {
913
+ for (const map of [commandEvents, commandSlots, commandEffects, commandRules, restatements]) {
899
914
  if (map.has(command))
900
915
  map.set(copy, map.get(command));
901
916
  }
@@ -22,7 +22,7 @@ interface OneTimeCodes {
22
22
  } | {
23
23
  limited: true;
24
24
  }>;
25
- /** Whether `typed` is the live code for `subject`. Right, it is spent; wrong five times, it is burned. */
25
+ /** Whether `typed` is the live code for `subject`. Each try, right or wrong, counts against five; right within them, it is spent; the fifth try burns it. */
26
26
  spend(subject: string, typed: unknown, now?: number, bound?: string): Promise<boolean>;
27
27
  }
28
28
  /** Codes kept in `state`; the platform's are kept in its sign-in state. */
@@ -78,15 +78,18 @@ export function oneTimeCodes(state = signInState) {
78
78
  }
79
79
  const tries = `otp:${key}:${held.gen}`;
80
80
  const window = Math.max(1, held.until - now);
81
+ // Every attempt is charged before it is judged, by the store's one atomic increment: guesses typed together each
82
+ // get their own number, so no more than CODE_TRIES are ever judged against a code, on this instance or another.
83
+ // Counting only the wrong ones afterwards let a burst all read the count before any write landed.
84
+ const charged = await state.fail(tries, window);
85
+ if (charged > CODE_TRIES)
86
+ return false;
81
87
  if (!matches || !shaped) {
82
- if ((await state.fail(tries, window)) >= CODE_TRIES)
88
+ if (charged >= CODE_TRIES)
83
89
  await state.remove('otp', key);
84
90
  return false;
85
91
  }
86
- // Wrong tries counted on another instance burn the code here too; and of two instances given the right code at
87
- // once, the one whose claim counts first opens.
88
- if ((await state.failures(tries)) >= CODE_TRIES)
89
- return false;
92
+ // Of two instances given the right code at once, the one whose claim counts first opens.
90
93
  if (!(await state.consume(`otp-spent:${key}:${held.gen}`, { window: Math.ceil(window / 1000), max: 1 })).allowed)
91
94
  return false;
92
95
  await state.remove('otp', key);
@@ -43,8 +43,10 @@ export declare const publicRefCount: (text: string) => number;
43
43
  */
44
44
  export declare function renderPublicRefs(text: string, appId: string, render: (view: string) => Promise<string | undefined>, keep?: boolean): Promise<string | undefined>;
45
45
  /**
46
- * `text` with each reference the App made removed, and the space or punctuation it leaves behind tidied: for a message
47
- * whose links cannot be said (no address places them), where the reference is dropped and the words around it kept.
46
+ * `text` without each sentence that held a reference the App made: for a message whose links cannot be said (no
47
+ * address places them). A sentence whose point was the link means nothing without it ("Apply in steps at"), so it
48
+ * goes whole and the sentences around it stay; a line left empty goes with it. A sentence ends at `.`, `!` or `?`
49
+ * before a space, or at a line's end. A message that is only such sentences is said as nothing at all.
48
50
  */
49
51
  export declare function withoutPublicRefs(text: string, appId: string): string;
50
52
  /** A public view's URL as an effect is delivered: for the effect's tenant, in a tenant App; undefined where none is known. */
@@ -82,19 +82,35 @@ export async function renderPublicRefs(text, appId, render, keep = false) {
82
82
  }
83
83
  return text.replace(REF, (whole) => urls.get(whole) ?? whole);
84
84
  }
85
+ /* Where a reference the App made stood while its sentences are read: one character, so a seal's dot never ends one. */
86
+ const GONE = '\u0000';
85
87
  /**
86
- * `text` with each reference the App made removed, and the space or punctuation it leaves behind tidied: for a message
87
- * whose links cannot be said (no address places them), where the reference is dropped and the words around it kept.
88
+ * `text` without each sentence that held a reference the App made: for a message whose links cannot be said (no
89
+ * address places them). A sentence whose point was the link means nothing without it ("Apply in steps at"), so it
90
+ * goes whole and the sentences around it stay; a line left empty goes with it. A sentence ends at `.`, `!` or `?`
91
+ * before a space, or at a line's end. A message that is only such sentences is said as nothing at all.
88
92
  */
89
93
  export function withoutPublicRefs(text, appId) {
90
94
  const refs = sealedRefs(text, appId);
91
95
  if (refs.size === 0)
92
96
  return text;
93
- return text
94
- .replace(REF, (whole) => (refs.has(whole) ? '' : whole))
95
- .replace(/\(\s*\)|\[\s*\]/g, '')
96
- .replace(/[ \t]+([.,;:!?)\]])/g, '$1')
97
- .replace(/[ \t]{2,}/g, ' ')
97
+ const marked = text.replace(REF, (whole) => (refs.has(whole) ? GONE : whole));
98
+ const lines = [];
99
+ for (const line of marked.split('\n')) {
100
+ if (!line.includes(GONE)) {
101
+ lines.push(line);
102
+ continue;
103
+ }
104
+ const kept = line
105
+ .split(/(?<=[.!?])[ \t]+/)
106
+ .filter((sentence) => !sentence.includes(GONE))
107
+ .join(' ');
108
+ if (kept.trim())
109
+ lines.push(kept);
110
+ }
111
+ return lines
112
+ .join('\n')
113
+ .replace(/\n{3,}/g, '\n\n')
98
114
  .trim();
99
115
  }
100
116
  /* The rooms' segments, as the shell's book says them (client/publicAddress.ts): a view's segment depends only on the
@@ -67,6 +67,8 @@ import { captureTenantData, denyTenant, tenantIdentifier, tenantOptions, refusal
67
67
  import { assertIntakeColumn, captureIntakeEvidence, intakeAddress, intakeAddressProblem, intakePlace, tenantPublicForms, } from './tenantIntakeModel.js';
68
68
  import { observerMounted } from '../observe/mount.js';
69
69
  import { captureTenantReadSource, readSharedProfile } from './tenantReadSource.js';
70
+ import { commandZone } from '../app/readerZone.js';
71
+ import { zoneColumn } from '../../shared/appZone.js';
70
72
  import { scopedLookupReader } from '../commands/commandLookup.js';
71
73
  import { intakeVisitor } from './tenantPublicRead.js';
72
74
  import { tenantRuntimeClock } from './tenantRuntimeClock.js';
@@ -328,6 +330,10 @@ export function bindTenantIntake(options) {
328
330
  only where the submission landed with a tenant. The platform's triage is no one tenant's, so it reads none. */
329
331
  const tenant = place === 'tenant' ? await readSharedProfile(reader, app, evidence.tenantId) : undefined;
330
332
  admitted.active();
333
+ /* That tenant's zone for `today()` and `now()`, where `ui.timezone` names a profile column, as its members' commands
334
+ and its jobs count the day (readerZone.ts). Another table's column is read under a member's scope, which a visitor
335
+ has none of: the App's zone stands, as it does for a job. */
336
+ const zone = tenant && zoneColumn(app.ui)?.resource === 'tenant' ? await commandZone(app.ui, deny, tenant) : undefined;
331
337
  let run;
332
338
  if (draft) {
333
339
  const saved = form, where = drafts.get(request.form) ?? denyTenant();
@@ -363,6 +369,7 @@ export function bindTenantIntake(options) {
363
369
  }
364
370
  : {}),
365
371
  ...(tenant ? { tenant } : {}),
372
+ ...(zone === undefined ? {} : { timezone: zone }),
366
373
  ...(place === 'tenant'
367
374
  ? { receiptOwner: captureTenantData({ storeId: identity.storeId, sourceId: identity.source.id, tenantId: evidence.tenantId }) }
368
375
  : {}),
@@ -35,7 +35,7 @@ export function isTenantPublicPath(path) {
35
35
  }
36
36
  export function createTenantPublicHttp(options) {
37
37
  /** The handler's message as its visitor reads it: a public link in it said as the placing tenant's URL. Where one
38
- cannot be said (no tenant is placed), the message is kept and each reference is said as nothing, as a person is
38
+ cannot be said (no tenant is placed), the sentence that held each reference goes and the rest is kept, as a person is
39
39
  never shown `mistri-public:<view>.<seal>` and no URL is made up at the root origin. */
40
40
  const sayMessage = async (said, address, form) => {
41
41
  if (said.message === undefined)
@@ -520,7 +520,8 @@ const ROLE_RENAMED = {
520
520
  * `auth.public`: the resources a signed-out visitor reads, each one named —
521
521
  * never `true`, so nothing is public by accident — and none written. One
522
522
  * that `byKey` names is read a record at a time by its key and never listed,
523
- * counted or searched (server/app/publicByKey.ts): a link's page, not a directory.
523
+ * counted or searched (server/app/publicByKey.ts): a link's page, not a directory. The key is the only secret, so it
524
+ * must be unguessable (a UUID, a sealed reference); `check` warns on a numeric one (`bykey-guessable`).
524
525
  *
525
526
  * With `rows: 'policy'` the two answer different readers and do not meet: a
526
527
  * visitor is scoped by this grant, which names its resources and narrows
@@ -16,6 +16,12 @@ export declare function appLiteralWarnings(app: AppDef, pages: readonly PageDef[
16
16
  * hidden from everyone is dead UI that `mistri check` used to call ok.
17
17
  */
18
18
  export declare function appReachWarnings(app: AppDef, schema: DatabaseSchema): string[];
19
+ /**
20
+ * A table a signed-out visitor reads by its key (`auth.public.byKey`) whose key is a number. The fence is sound — one
21
+ * row, by its whole key, never a list — but a visitor who may try any key can walk a serial's ids, so the key is
22
+ * the only secret and a counter is not one.
23
+ */
24
+ export declare function publicKeyWarnings(app: AppDef, schema: DatabaseSchema): string[];
19
25
  /**
20
26
  * A settings record named like an item the account menu already holds: the
21
27
  * menu showed "Your profile" twice — the borrower's record and the sign-in's
@@ -10,7 +10,7 @@
10
10
  * say a column's values (`allowed` absent) is never guessed at.
11
11
  */
12
12
  import { expandSegments } from '@mistriwork/engine/shared/query.js';
13
- import { columnKind, tableNamed } from '@mistriwork/engine/shared/schema.js';
13
+ import { columnKind, primaryKey, tableNamed, } from '@mistriwork/engine/shared/schema.js';
14
14
  import { parseViewQuery, tryResolvePath } from '@mistriwork/engine/shared/view.js';
15
15
  import { checkedPerson } from './appMe.js';
16
16
  import { grantsByRole, isFormView, restatedOf } from './appModel.js';
@@ -251,6 +251,30 @@ export function appReachWarnings(app, schema) {
251
251
  }
252
252
  return warnings;
253
253
  }
254
+ /**
255
+ * A table a signed-out visitor reads by its key (`auth.public.byKey`) whose key is a number. The fence is sound — one
256
+ * row, by its whole key, never a list — but a visitor who may try any key can walk a serial's ids, so the key is
257
+ * the only secret and a counter is not one.
258
+ */
259
+ export function publicKeyWarnings(app, schema) {
260
+ const warnings = [];
261
+ for (const name of app.auth?.public?.byKey ?? []) {
262
+ const table = tableOf(schema, name);
263
+ if (!table)
264
+ continue;
265
+ const key = primaryKey(table);
266
+ // A composite key with one unguessable part is not walked by counting.
267
+ const numeric = (column) => {
268
+ const type = table.columns.find((candidate) => candidate.name === column)?.type ?? '';
269
+ return columnKind(type) === 'number' && /int|serial/i.test(type) && !/interval|point/i.test(type);
270
+ };
271
+ if (!key.length || !key.every(numeric))
272
+ continue;
273
+ warnings.push(`auth "public", byKey "${name}" [bykey-guessable]: a signed-out visitor reads ${name} by its key, and its key ${key.join(', ')} ` +
274
+ `is a number, so ids can be walked. Read by an unguessable key (a UUID, or a sealed reference) instead.`);
275
+ }
276
+ return warnings;
277
+ }
254
278
  /** The account menu's own items, by what they say (client AccountControl). */
255
279
  const ACCOUNT_MENU_ITEMS = ['Your profile', 'Manage accounts', 'Manage tenants', 'Manage invitations', 'Accept invitation', 'Sign out'];
256
280
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/mistri",
3
- "version": "1.0.0-rc.54",
3
+ "version": "1.0.0-rc.56",
4
4
  "description": "The App framework: a few lines of TypeScript, a complete App, served from your own database.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -110,9 +110,9 @@
110
110
  "./package.json": "./package.json"
111
111
  },
112
112
  "dependencies": {
113
- "@mistriwork/engine": "1.0.0-rc.54",
114
- "@mistriwork/kit": "1.0.0-rc.54",
115
- "@mistriwork/ui": "1.0.0-rc.54",
113
+ "@mistriwork/engine": "1.0.0-rc.56",
114
+ "@mistriwork/kit": "1.0.0-rc.56",
115
+ "@mistriwork/ui": "1.0.0-rc.56",
116
116
  "intl-messageformat": "12.1.2",
117
117
  "marked": "^18.1.0",
118
118
  "sanitize-html": "^2.18.0",
@@ -2870,7 +2870,7 @@
2870
2870
  "type": "string",
2871
2871
  "minLength": 1
2872
2872
  },
2873
- "description": "Of read, the resources a visitor opens one record at a time by its key and never lists, counts or searches: a link's page, not a directory."
2873
+ "description": "Of read, the resources a visitor opens one record at a time by its key and never lists, counts or searches: a link's page, not a directory. Its key must be unguessable (a UUID or a sealed reference); `check` warns on a numeric key."
2874
2874
  },
2875
2875
  "fields": {
2876
2876
  "type": "object",