Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(access): cover member-bound OAuth clients and granted-default tokens; register Postgres lane and size bookkeeping

garrytan4a79f26f710c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4dc32c85b9..cf98891c53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,15 +12,15 @@ identifiers and attribution are available in the pre-removal Git revision
## [Unreleased]
-**A page written by a member-bound credential with no source grant is now readable only by that member.** A token or OAuth client bound with `gbrain auth rescope --member <id>` and no `--sources` has no write source of its own, so its writes land in `default`, the source every credential without a source grant reads. Its `put_page` (and every page write through the same path) used to create an ordinary page there, which another member and an unbound token read through `get_page`, `search`, `query`, `recall` and `list_pages`; its `remember` facts were already kept on the member's own page. A page such a credential creates is now written with `readable_by: [member:<id>]`, in the database row on a repo-less brain and in the file on a repo brain; rewriting it without `readable_by` keeps the stored readers, and the member widens it by naming readers. An edit to an existing page that names no readers leaves it shared, and `POST /ingest`, which cannot keep a page to a member, refuses such a credential with `permission_denied`. Credentials granted sources (the documented `--sources private-<member>,default` shape) and unbound credentials write exactly as before. Pages written before this release keep whatever readers they have: `gbrain access who-can-read <slug>` shows who reads one.
+**A page a member-bound credential creates in the `default` source is now readable only by that member.** A token bound with `gbrain auth rescope --member <id>` and no `--sources` writes to `default`, the source every credential without a source grant reads, and so does a token granted `--sources default` and an OAuth client left at its registration default. Its `put_page` (and every page write through the same path) used to create an ordinary page there, which another member and an unbound token read through `get_page`, `search`, `query`, `recall` and `list_pages`; its `remember` facts were already kept on the member's own page. A page such a credential creates is now written with `readable_by: [member:<id>]`, in the database row on a repo-less brain and in the file on a repo brain; rewriting it without `readable_by` keeps the stored readers, and the member widens it by naming readers. An edit to an existing page that names no readers leaves it shared, and `POST /ingest`, which cannot keep a page to a member, refuses such a credential with `permission_denied`. Member-bound credentials whose write source is another source (the documented `--sources private-<member>,default` shape) and unbound credentials write exactly as before. Pages written before this release keep whatever readers they have: `gbrain access who-can-read <slug>` shows who reads one.
### Itemized changes
-- `src/core/persistence/page-visibility.ts`: `ungrantedMemberWriter` reads, live from the stored principal, whether a remote write's token or OAuth client is bound to an enabled member and holds the no-grant `default` floor (never for a local, unbound, attested or audience write); `ungrantedWriterReaders` gives a page such a writer sends without `readable_by` the stored page's readers, or the writer alone when the write creates the page.
+- `src/core/persistence/page-visibility.ts`: `defaultSourceMemberWriter` reads, live from the stored principal, whether a remote write to `default` comes from a token or OAuth client bound to an enabled member (never for a local, unbound, attested or audience write); `defaultSourceWriterReaders` gives a page such a writer sends without `readable_by` the stored page's readers, or the writer alone when the write creates the page.
- `src/core/persistence/page-prepare.ts`: page preparation applies it to the frontmatter before the content hash, the rendered file and the stored row are made (restores and reverts excluded).
-- `src/commands/serve-http-webhooks.ts`: `POST /ingest` refuses a member-bound credential with no source grant before anything is queued.
+- `src/commands/serve-http-webhooks.ts`: `POST /ingest` refuses a member-bound credential whose write source is `default` before anything is queued.
- Docs: `docs/guides/multi-source-brains.md`, `docs/tutorials/company-brain.md` (Model C), `docs/mcp/ADMIN.md`.
-- Tests: `test/access-ungranted-member-writes.test.ts` (repo-less PGLite and Postgres, plus a repo brain: another member and an unbound token read nothing of a new page over `get_page`, `search`, `query`, `recall` and `list_pages`; the writer reads, rewrites and widens it; a shared page stays shared; `remember` unchanged; the documented shape unchanged and unstamped; `POST /ingest` refused with nothing queued).
+- Tests: `test/access-ungranted-member-writes.test.ts` (repo-less PGLite and Postgres, plus a repo brain: tokens with no grant and with `--sources default` and an OAuth client at its registration default; another member and an unbound token read nothing of a new page over `get_page`, `search`, `query`, `recall` and `list_pages`; the writer reads, rewrites and widens it; a shared page stays shared; `remember` unchanged; the documented shape unchanged and unstamped; `POST /ingest` refused with nothing queued).
## [0.60.620.0] - 2026-11-09
diff --git a/docs/guides/multi-source-brains.md b/docs/guides/multi-source-brains.md
index 82726016f3..fff952b2ff 100644
--- a/docs/guides/multi-source-brains.md
+++ b/docs/guides/multi-source-brains.md
@@ -246,8 +246,9 @@ who may read it, before any member's bot connects:
The first id is the token's write source, so a member's saved memories land
in their own private source.
- A credential bound to a member (`--member`) with no `--sources` has no write
- source of its own and writes to `default`, which every credential without a
+ A credential bound to a member (`--member`) whose write source is `default`
+ (a token with no `--sources` or with `--sources default`, or an OAuth client
+ left at its registration default) writes where every credential without a
source grant reads. A page such a credential creates is therefore written
with `readable_by: [member:<id>]`, readable only by that member (and the
local CLI); rewriting it without `readable_by` keeps those readers, and the
diff --git a/docs/mcp/ADMIN.md b/docs/mcp/ADMIN.md
index fb08d91532..58bd68bf8b 100644
--- a/docs/mcp/ADMIN.md
+++ b/docs/mcp/ADMIN.md
@@ -239,8 +239,9 @@ Inside one source, bind each member's credential with `gbrain auth rescope
--token <name> --member <id>` (or `--client`) and put `readable_by` on the pages
only some members may read, or keep a whole folder to them with `gbrain access
rule add --prefix <folder>/ --readers <members> --source <id>`.
-A member-bound credential with no `--sources` writes to `default`, so a page it
-creates names only that member as reader until the member names more
+A member-bound credential whose write source is `default` (no `--sources`, or an
+OAuth client at its registration default) keeps a page it creates to that
+member until the member names more readers
([details](../tutorials/company-brain.md#two-scoping-models-pick-the-one-that-matches-your-shape)).
One agent serving several people in a shared channel holds `--may-act-for
<members>` instead, and its harness names each request's audience
diff --git a/docs/tutorials/company-brain.md b/docs/tutorials/company-brain.md
index d24fcb310c..22078afe14 100644
--- a/docs/tutorials/company-brain.md
+++ b/docs/tutorials/company-brain.md
@@ -130,7 +130,7 @@ gbrain access check --token alice-laptop # what this credential can rea
gbrain access who-can-read notes/renewal-notes # the members and groups a page admits
```
-A credential bound with `--member` and no `--sources` writes to `default`, a source every credential without a source grant reads, so a page it creates is written with `readable_by: [member:<id>]` and only that member reads it; it keeps those readers when the member rewrites it without the field, and the member shares it by naming readers (`readable_by: [alice-example, group:team-a]`). An edit to an existing page that names no readers leaves it shared, `remember` facts go on the member's own page as before, and `POST /ingest` refuses such a credential. A credential granted sources (`--sources private-alice-example,default`, first id the write source) keeps writing exactly what it sends. Earlier releases wrote these pages with no readers, so other members and unbound tokens read them; run `gbrain access who-can-read <slug>` on pages your members wrote and add `readable_by` on the host where needed.
+A credential bound with `--member` whose write source is `default` (a token with no `--sources` or `--sources default`, or an OAuth client left at its registration default) writes where every credential without a source grant reads, so a page it creates is written with `readable_by: [member:<id>]` and only that member reads it; it keeps those readers when the member rewrites it without the field, and the member shares it by naming readers (`readable_by: [alice-example, group:team-a]`). An edit to an existing page that names no readers leaves it shared, `remember` facts go on the member's own page as before, and `POST /ingest` refuses such a credential. A credential whose write source is another source (`--sources private-alice-example,default`, first id the write source) keeps writing exactly what it sends. Earlier releases wrote these pages with no readers, so other members and unbound tokens read them; run `gbrain access who-can-read <slug>` on pages your members wrote and add `readable_by` on the host where needed.
A remote caller whose credential is bound to a listed member (directly or through a group) reads the page on every read path; every other remote caller, including an unbound token, an unbound stdio server, a bot with `--private-pages granted-sources` and an operator escape hatch (`GBRAIN_REMOTE_PRIVATE_PAGES=1`, `search.remote_private_pages=visible`), gets the same `not_found` as for a page that does not exist. `readable_by` only narrows: a `visibility: private` page stays private to a listed member unless the member's credential also has `--private-pages granted-sources`. A malformed `readable_by` reads as nobody. A page derived from a restricted page (an extracted atom, a synthesized concept, a chronicle event) is readable by no remote caller. The local CLI is unchanged; `--as <member>` previews one member's view. Pages that already carried `readable_by` before you upgraded read as nobody until `gbrain repair access` (preview, then `--apply`) derives their readers. This works the same on a repo-less brain: members, groups and bindings live in the database.
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index 91c4fa72d0..66bfc00a39 100644
--- a/scripts/module-size-limits.tsv
+++ b/scripts/module-size-limits.tsv
@@ -47,4 +47,4 @@ src/commands/doctor/checks/extraction-sync.ts 1500 ratchet +7 GBRA-130 A-1: link
src/core/search/evidence-delivery.ts 1759 ratchet +5 W5: EvidencePlan.rankCut resolved with the plan (logic in search/page-rank-cut.ts); +20 W5 whole_pages: wholeCost prices a block as delivery would emit it whole (needs the private Block/enrichBlock internals) and the cut is wired before allocate (cutWholePages lives in search/page-rank-cut.ts); new row: crossed the 1500 unlisted cap at the #6367 merge (master 1479, its explicit-budget cap) by the C1 date header threaded through every block path, cap included; pagePlanHits (search/page-plan-hits.ts) and the header loader (evidence-date.ts blockDateHeaders) were peeled first; peel candidate: allocateCapped; +8 at the #6396 merge: page evidence text cut through the fence-chunk trust overlay and the caller minTrust floor (re-summed: our 1504 + master +8); +119 Cat 40 next wave F2: the search.long_page_unit policy (withLongPagePolicy, selectLongPages size preflight with page/byte/deadline limits) and the long-page fetch and fallback in deliverEvidence, kept in the shared seam the plan names (gbrain-evals docs/plans/2026-10-11-cat40-next-wave, F2); +17 F2 rework to the frozen-comparison policy: search.long_page_min_chars (rendered-body characters, default 20,000) read in withLongPagePolicy, a character count in the preflight, the rendered-body confirmation in deliverEvidence, and the long-page row exemption in capDeliveredSnippets (re-summed at the 0.60.225.0 merge: master 1537 + F2 136); +39 Wave B PR 2 lane 2b: planSegmentedBlock joins the windows search/segmented-evidence.ts reads around a segmented page's hits into one run-marked document (needs the private Doc/Piece/buildDoc/locateAnchor internals), planBlock's unit cut split into blockFromDoc for both, sections bounded by their run, selectionCost counts a gap between runs, and the fetch skips the whole-body fence overlay for a segmented page; +4 segmented pages read at once before planning (segmentedReads; the read is search/segmented-evidence.ts, the statements page-body/read-range.ts); +17 GBRA-156: tail trim plan flag, DeliverOptions.query, DeliveryMeta.tail_trim, the trim call and the frozen-hit score/query library fields (logic in search/evidence-tail-trim.ts; interface fields cannot move); +7 GBRA-205: EvidencePlan.titleHeader and DeliveryMeta.title_header (interface fields cannot move) and the titles option on the header loader (logic in search/evidence-date.ts; the query budget key lives in search/evidence-packing.ts); +11 #7600: assemble_evidence quotes conversation rows and capEvidenceToBudget counts the quote fence (logic in search/transcript-quote.ts); +2 GBRA-156 /ship review: the cut-path admission and title room count the quote fence; +2 GBRA-156 /ship review pass 2: capEvidenceToBudget counts the fence only for the paths that fence (quote flag; recall counts the text as returned); +4 GST-687: page evidence and the extractive fallback quote below-owner-tier text for untrusted readers (untrusted flag; logic in search/transcript-quote.ts)
src/commands/config.ts 1526 ratchet +1 GBRA-216: recall.* config set value refusal (facts/recall-config.ts); +1 GBRA-216: config set refuses a dream.claim_conflicts.mode other than propose|off (refusal in facts/claim-conflicts.ts); new row: crossed the 1500 unlisted cap in wave 15 P7.4 #5461: set-time validation of think.pages_budget_chars / think.excerpt_ceiling_chars (range + parser live in core/think/pages-budget.ts), mirroring the cycle.consolidate.cluster_threshold hook; +1 wave 16 G5.1 (#6495): set-time refusal hook for search.keyword_statement_timeout_ms (check lives in commands/config/keyword-timeout-value.ts); +1 wave 18b lane 5 (#5012 item 6): search.contextual_retrieval prints the existing-pages hint after the write (text lives in commands/config/contextual-mode-hint.ts); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig); +1 #6865: sync.slug_conflicts.auto_remove boolean validation at set time (refusal text in repair/slug-autoheal.ts); +1 #6948: sync.origin_twins.auto_resolve boolean validation at set time (refusal text in repair/origin-twins-heal.ts); +2 #6795: config set chat_model/expansion_model help line and the model-pin import (shadow report and file-pin unset live in commands/config/model-pin-shadow.ts); +1 #6712 PR 4b: sync.admission set-time hook (value logic in commands/config/sync-admission-value.ts); +4 #7130: set-time refusal hook for sync.max_deletes / sync.max_delete_ratio (and .source.<id>) / purge.retention_hours (check lives in core/sync-reconcile.ts deleteSafetyConfigRefusal); +1 GBRA-150: sync.metafile_pages set-time route (body in config/sync-metafile-pages-value.ts); re-summed at the v0.60.330.0 merge (1520 measured); +2 #7242 minions.terminal_hook file-plane key and its set branch (logic in minions/terminal-hook.ts); +1 GBRA-161: generations.* set-time route (refusal in commands/config/generations-values.ts); +1 GBRA-207 #7630: sync.repo_path set-time refusal hook (refusal in core/sync-config-keys.ts syncRepoPathRefusal)
src/commands/mcp-expose.ts 1519 ratchet hosted_option: Session carries the gbrain.io coaching notice on the first-receipt run and Tailscale/service friction exits (copy, refs and gating live in core/onboard/hosted-option.ts); +7 GBRA-199: --surface help lines, surfaceChosen option field and the advertise pass-through (registrationAdvertise in core/mcp-registration.ts)
-src/core/behavior-change-notice.ts 1687 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row
+src/core/behavior-change-notice.ts 1688 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row; +1 GST-2051 ungranted_member_writes_gst2051 row (since TBD until the merge slot; rows are data and cannot move)
diff --git a/src/commands/serve-http-webhooks.ts b/src/commands/serve-http-webhooks.ts
index 26b3d6e67f..a3de28f821 100644
--- a/src/commands/serve-http-webhooks.ts
+++ b/src/commands/serve-http-webhooks.ts
@@ -31,7 +31,7 @@ import { NO_SOURCES } from '../core/source-id.ts';
import { noSourceGrantError } from '../core/ops/context.ts';
import { renderAction } from '../core/agent-output.ts';
import { assertWebhookWriterMayReplace } from '../core/minions/handlers/ingest-capture.ts';
-import { ungrantedMemberWriter } from '../core/persistence/page-visibility.ts';
+import { defaultSourceMemberWriter } from '../core/persistence/page-visibility.ts';
import type { WriteAuthority } from '../core/persistence/model.ts';
import { validateSlug } from '../core/utils.ts';
@@ -301,6 +301,21 @@ function verifyWebhookSig(secret: unknown, sigHeader: string, payload: Buffer):
return matches && keyed;
}
+/**
+ * GST-2051: a member-bound credential writing to default would publish where every no-grant credential reads; the capture
+ * job cannot keep the page to the member, so POST /ingest refuses it (answering res) and put_page, which does, stays open.
+ */
+async function refusedDefaultSourceMember(engine: BrainEngine, authInfo: AuthInfo, res: Response): Promise<boolean> {
+ if (!authInfo.principal || !await defaultSourceMemberWriter(engine, { remote: true, principal: authInfo.principal as WriteAuthority['principal'], sourceId: authInfo.sourceId ?? 'default' })) return false;
+ res.status(403).json({
+ error: 'permission_denied',
+ message: 'POST /ingest is unavailable to a credential bound to a member whose write source is default: its pages would land where other members ' +
+ 'and unbound credentials read. Write through the MCP put_page op, which keeps a new page to its member, ' +
+ 'or ask the brain operator to grant this credential its own write source (gbrain auth rescope --sources <private-source>,default).',
+ });
+ return true;
+}
+
/** POST /ingest (OAuth write scope) and POST /webhooks/github (per-source HMAC), in registration order. */
export function mountWebhooks(app: Express, ctx: ServeHttpContext): void {
mountIngest(app, ctx);
@@ -394,17 +409,7 @@ async function handleIngest(
fix: renderAction(refusal.fix!, { transport: 'http', isCallable: () => false, preapproved: () => false }) });
return;
}
- // GST-2051: a member-bound credential with no source grant would publish to default, which every no-grant credential
- // reads; the capture job cannot keep the page to the member, so the route refuses and put_page (which does) stays open.
- if (authInfo.principal && await ungrantedMemberWriter(engine, { remote: true, principal: authInfo.principal } as WriteAuthority)) {
- res.status(403).json({
- error: 'permission_denied',
- message: 'POST /ingest is unavailable to a credential bound to a member with no source grant: its pages would land in the default source, ' +
- 'which other members and unbound credentials read. Write through the MCP put_page op, which keeps a new page to its member, ' +
- 'or ask the brain operator to grant this credential its own write source (gbrain auth rescope --sources <private-source>,default).',
- });
- return;
- }
+ if (await refusedDefaultSourceMember(engine, authInfo, res)) return;
if (authInfo.allowedOperations != null || authInfo.grantProjectionDegraded) {
res.status(403).json({
error: 'permission_denied',
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index c1a117070d..8628aaf954 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1489,7 +1489,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.618.0', id: 'refresh_replan_own_commits_8828', text: 'A `gbrain sources refresh` whose checkout HEAD moved while it waited for writes admitted before its fence no longer refuses `refresh_source_changed` when every commit since its start is one of gbrain\'s own (in the commit ledger) and the upstream branch holds them: it takes HEAD as its start and fast-forwards to the upstream. A HEAD move that includes a commit gbrain did not make, or gbrain\'s commits the upstream does not hold yet, still refuses as before.' },
{ since: '0.60.619.0', id: 'managed_commit_push_unpublished_gst1923', text: 'On a managed checkout, `gbrain git commit-push -m <msg> -- <paths>` now reports how many commits the upstream lacks as last fetched (`unpublished` in `--json`, `null` when there is no upstream) and says nothing was pushed, instead of answering `nothing to commit; <remote>/<branch> at -` and logging `[push] ok-already-on-remote` for a commit that already existed. It writes no push-log line on a managed checkout. It still never pushes there; `gbrain git commit-push --push-only --keep-checkout --path <checkout>` publishes.' },
{ since: '0.60.620.0', id: 'refresh_publish_diverged_default_gbra386', text: 'A diverged managed checkout now publishes its local commits on `gbrain sources refresh` by default when the worktree\'s Git durability is on: `sources.refresh_publish_diverged` unset now means on there (it used to mean off), merged with the upstream in memory, never rebased or forced. The refresh publish first scans what the local commits add (messages, added lines, merge resolutions) and refuses the new `publish_secret_found` naming the file, line and rule, never the value, when one looks like a secret; `gbrain git commit-push --push-only --scan-secrets` runs the same gate. Unset with durability not on still refuses, naming `gbrain sources writer git-durability <source> --enable`; `false` turns it off.' },
- { since: 'TBD', id: 'ungranted_member_writes_gst2051', text: 'A token or OAuth client bound to a member (`gbrain auth rescope --member <id>`) with no `--sources` writes to `default`, which every credential without a source grant reads. A page it creates there is now written with `readable_by: [member:<id>]`, so other members and unbound tokens no longer read it; rewriting it without `readable_by` keeps those readers, naming readers widens it, an edit to an existing page with no readers leaves it shared, and `POST /ingest` refuses such a credential. Credentials granted sources and unbound credentials are unchanged, and pages written before the upgrade keep their readers (`gbrain access who-can-read <slug>`).' },
+ { since: 'TBD', id: 'ungranted_member_writes_gst2051', text: 'A token or OAuth client bound to a member (`gbrain auth rescope --member <id>`) whose write source is `default` (no `--sources`, `--sources default`, or an OAuth client at its registration default) writes where every credential without a source grant reads. A page it creates there is now written with `readable_by: [member:<id>]`, so other members and unbound tokens no longer read it; rewriting it without `readable_by` keeps those readers, naming readers widens it, an edit to an existing page with no readers leaves it shared, and `POST /ingest` refuses such a credential. Credentials writing to another source and unbound credentials are unchanged, and pages written before the upgrade keep their readers (`gbrain access who-can-read <slug>`).' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.ts
index b336d416f2..b1f2938e69 100644
--- a/src/core/persistence/page-prepare.ts
+++ b/src/core/persistence/page-prepare.ts
@@ -37,7 +37,7 @@ import { recordedPathFromFileUri, scannerSlugRootMode, scannerSourcePath } from
import { engineMutationPrecondition, parseMutationPrecondition } from './preconditions.ts';
import { assertPurgeParams } from './purge-params.ts';
import { authorizeWrite, slugDisclosable } from './authority.ts';
-import { remoteReadersChecked, ungrantedMemberWriter, ungrantedWriterReaders } from './page-visibility.ts';
+import { remoteReadersChecked, defaultSourceMemberWriter, defaultSourceWriterReaders } from './page-visibility.ts';
import { findLiveFileClaimants, type FileClaimant, type FileClaimTarget } from './file-claims.ts';
import { digest, sha256 } from './digest.ts';
import { replaceableFile } from '../facts/file-body-guard.ts';
@@ -976,8 +976,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri
// #5575: the page's tier, computed once before import so the write gate sees exactly it (ENG-18).
const trust = provenanceWriteTrust(row, typeof content === 'string' && !isFenceEditWrite(row) ? parseMarkdown(content, row.slug, { activePack }).frontmatter : null, snapshot?.page.frontmatter);
const gateTrust = pageGateTrust(row, trust, storedTier);
- // GST-2051: a member-bound credential with no source grant keeps the pages it creates to itself.
- const ungrantedWriter = row.operation === 'restore_page' || row.operation === 'revert_version' ? null : await ungrantedMemberWriter(engine, row.authority);
+ const defaultSourceWriter = row.operation === 'restore_page' || row.operation === 'revert_version' ? null : await defaultSourceMemberWriter(engine, row.authority);
// The apply diet: the publisher's locked read of row.slug is the import base, and one read after the
// last page write serves the read-back check, the seal, the core notice and the receipt (as sync does).
const lean = options.coordinated === true && !targetDeleted && row.operation !== 'restore_page' && !versionTags;
@@ -999,7 +998,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri
provenance = putProvenance(row, snapshot, page);
suppliedTrustMarker = page.frontmatter.trust_tier;
stampPageTrustMarker(row, page.frontmatter, trust, storedTier, snapshot?.page.frontmatter);
- ungrantedWriterReaders(ungrantedWriter, page.frontmatter, snapshot?.page);
+ defaultSourceWriterReaders(defaultSourceWriter, page.frontmatter, snapshot?.page);
if (privateRequest) assertPrivateRequestKept(row, page.frontmatter);
},
prepare: async value => { prepared = value; return value.result; },
diff --git a/src/core/persistence/page-visibility.ts b/src/core/persistence/page-visibility.ts
index 8ceadd40f0..972f0b5bf7 100644
--- a/src/core/persistence/page-visibility.ts
+++ b/src/core/persistence/page-visibility.ts
@@ -6,7 +6,6 @@ import type { AudiencePrincipal } from '../access/audience.ts';
import { parseStoredActor, storedActorIdentity } from '../access/actor.ts';
import { hasReaders, normalizePrincipal, normalizeReaders, readersAllow, NOBODY } from '../access/principals.ts';
import { catalogueError } from '../error-catalogue.ts';
-import { grantFromClient, grantFromRow, grantFromTokenRow } from '../grants/model.ts';
import type { SqlEngine, WriteAuthority } from './model.ts';
/** Publication uses fresh policy, independent of the read-side telemetry cache (read through the resolver). */
@@ -143,30 +142,24 @@ export async function remoteReadersChecked<T extends { parsedPage: { frontmatter
}
/**
- * GST-2051: the member a remote write's credential is bound to, as `member:<id>`, when that credential holds no source
- * grant (it writes to `default`, a source no operator chose for it and every no-grant credential reads); null for a
- * local, unbound, attested or audience write, or a credential an operator granted sources. Read live from the stored
- * principal, so a binding or grant changed after submission takes effect at preparation.
+ * GST-2051: the member a remote write's token or OAuth client is bound to, as `member:<id>`, when the write goes to
+ * `default`: the no-grant floor of every token without `--sources` and the registration default of every OAuth
+ * client, read by every credential without a source grant, unbound ones included. Null for a local, unbound, attested
+ * or audience write, and for any other source (the operator chose that source's audience). Re-resolved live from the
+ * stored principal, so a binding removed after submission takes effect at preparation.
*/
-export async function ungrantedMemberWriter(engine: SqlEngine, authority: WriteAuthority): Promise<string | null> {
+export async function defaultSourceMemberWriter(engine: SqlEngine, authority: Pick<WriteAuthority, 'remote' | 'actingFor' | 'principal' | 'sourceId'>): Promise<string | null> {
const { principal } = authority;
- if (!authority.remote || authority.actingFor || (principal.kind !== 'legacy_token' && principal.kind !== 'oauth_client')) return null;
- const member = (await memberIdentityFor(engine, authority)).find(p => p.startsWith('member:'));
- if (!member) return null;
- const [row] = principal.kind === 'legacy_token'
- ? await engine.executeRaw<Record<string, unknown>>('SELECT * FROM access_tokens WHERE id::text = $1 AND revoked_at IS NULL', [principal.id])
- : await engine.executeRaw<Record<string, unknown>>('SELECT * FROM oauth_clients WHERE client_id = $1 AND deleted_at IS NULL', [principal.id]);
- if (!row) return null;
- const grant = principal.kind === 'legacy_token' ? grantFromTokenRow(row) : grantFromClient(grantFromRow(row));
- return grant.sources.kind === 'default' ? member : null;
+ if (!authority.remote || authority.actingFor || authority.sourceId !== 'default' || (principal.kind !== 'legacy_token' && principal.kind !== 'oauth_client')) return null;
+ return (await memberIdentityFor(engine, { principal })).find(p => p.startsWith('member:')) ?? null;
}
/**
- * GST-2051: the readers a page written by an ungranted member writer (ungrantedMemberWriter) keeps when its content
+ * GST-2051: the readers a page written by a default-source member writer (defaultSourceMemberWriter) keeps when its content
* names none: the stored page's readers when it has them, else the writer alone for a page this write creates. An
* existing page with no readers stays as it is. Only ever narrows: a page naming readers is left to the caller.
*/
-export function ungrantedWriterReaders(writer: string | null, frontmatter: Record<string, unknown>, stored: { frontmatter?: unknown; deleted_at?: unknown } | null | undefined): void {
+export function defaultSourceWriterReaders(writer: string | null, frontmatter: Record<string, unknown>, stored: { frontmatter?: unknown; deleted_at?: unknown } | null | undefined): void {
if (!writer || hasReaders(frontmatter)) return;
const live = stored && stored.deleted_at == null ? stored : null;
if (live && hasReaders(live.frontmatter)) frontmatter.readable_by = (live.frontmatter as Record<string, unknown>).readable_by;
diff --git a/test/access-ungranted-member-writes.test.ts b/test/access-ungranted-member-writes.test.ts
index d60199b580..91896732f1 100644
--- a/test/access-ungranted-member-writes.test.ts
+++ b/test/access-ungranted-member-writes.test.ts
@@ -1,6 +1,6 @@
/**
* GST-2051 (HARN-64): a credential bound to a member with no source grant writes to the `default` source, which every
- * no-grant credential reads. Before the fix a page it created there was readable by any other member and by an unbound
+ * no-grant credential reads (so does an OAuth client at its registration default, or a token granted --sources default). Before the fix a page it created there was readable by any other member and by an unbound
* token on get_page, search, query, recall and list_pages.
* 1. Protects: a page such a credential creates names its member as its only reader (readable_by), so another member
* and an unbound token get the canonical page_not_found and no search, query, recall or list_pages hit; the writer
@@ -47,7 +47,7 @@ const note = (title: string, body: string, readers = '') =>
['---', 'type: note', 'title: ' + title, ...(readers ? ['readable_by: ' + readers] : []), '---', '# ' + title, '', body].join('\n');
for (const kind of testBackends()) {
- describe('writes from a member-bound credential with no source grant (' + kind + ', repo-less)', () => {
+ describe('writes to default from a member-bound credential (' + kind + ', repo-less)', () => {
let engine: BrainEngine;
let close: () => Promise<void>;
const tokens: Record<string, string> = {};
@@ -90,8 +90,12 @@ for (const kind of testBackends()) {
await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [PRIVATE_SRC]);
await importFromContent(engine, SHARED_PAGE, note('Team shared', 'Shared agenda.'), { sourceId: 'default', noEmbed: true });
for (const id of ['alice-example', 'bob-example']) await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', [id]);
+ // An OAuth client as registration leaves it (source_id default, federated_read {default}), bound to alice.
+ await engine.executeRaw(`INSERT INTO oauth_clients (client_id, client_secret_hash, client_name, redirect_uris, grant_types, scope, token_endpoint_auth_method,
+ client_id_issued_at, source_id, federated_read, member_id) VALUES ('alice-client', 'x', 'alice-client', '{}', '{client_credentials}', 'read write',
+ 'client_secret_post', 0, 'default', '{default}', 'alice-example')`);
for (const [name, member, sourceGrant] of [['alice', 'alice-example', undefined], ['bob', 'bob-example', undefined], ['public', null, undefined],
- ['alice-documented', 'alice-example', [PRIVATE_SRC, 'default']]] as const) {
+ ['alice-documented', 'alice-example', [PRIVATE_SRC, 'default']], ['alice-default-grant', 'alice-example', ['default']]] as const) {
const minted = await mintLegacyToken(engine, { name, scopes: ['read', 'write'], takesHolders: ['world'], ...(sourceGrant ? { sourceGrant: [...sourceGrant] } : {}) });
tokens[name] = minted.token;
if (member) await engine.executeRaw('UPDATE access_tokens SET member_id = $2 WHERE id = $1::uuid', [minted.id, member]);
@@ -111,6 +115,24 @@ for (const kind of testBackends()) {
expect((await reads('alice', slug, canary)).get_page).toBe(true);
}, 240_000);
+ test('a token granted --sources default and an OAuth client at its registration default are kept to their member too', async () => {
+ const canary = marker('grant');
+ const slug = 'notes/alice-grant-' + canary;
+ expect((await call('alice-default-grant', 'put_page', { slug, content: note('Alice grant', 'Alice grant code ' + canary + '.') })).isError).toBe(false);
+ expect((await stored(slug)).page_readers).toEqual(['member:alice-example']);
+ expect(await reads('bob', slug, canary)).toEqual(none);
+ const clientCanary = marker('client');
+ const clientSlug = 'notes/alice-client-' + clientCanary;
+ const auth = { token: '', clientId: 'alice-client', clientName: 'alice-client', principal: { kind: 'oauth_client', id: 'alice-client' }, scopes: ['read', 'write'],
+ member: { id: 'alice-example', groups: [] }, sourceId: 'default', allowedSources: ['default'] } as unknown as AuthInfo;
+ const out = await dispatchToolCall(engine, 'put_page', { slug: clientSlug, content: note('Alice client', 'Alice client code ' + clientCanary + '.'), request_id: randomUUID() },
+ { remote: true, transport: 'http', auth, sourceId: 'default', takesHoldersAllowList: ['world'] });
+ expect(out.isError === true).toBe(false);
+ expect((await stored(clientSlug)).page_readers).toEqual(['member:alice-example']);
+ expect(await reads('bob', clientSlug, clientCanary)).toEqual(none);
+ expect(await reads('public', clientSlug, clientCanary)).toEqual(none);
+ }, 240_000);
+
test('the writer rewrites its page without readable_by and the readers carry; naming readers widens it', async () => {
const canary = marker('carry');
const slug = 'notes/alice-carry-' + canary;
@@ -165,7 +187,7 @@ for (const kind of testBackends()) {
const [before] = await engine.executeRaw<{ n: number }>("SELECT count(*)::int AS n FROM minion_jobs WHERE name = 'ingest_capture'");
const refused = await ingest('alice', note('Alice ingest', 'Ingest ' + marker('ingest') + '.'));
expect(refused.status).toBe(403);
- expect(await refused.json()).toMatchObject({ error: 'permission_denied', message: expect.stringContaining('no source grant') });
+ expect(await refused.json()).toMatchObject({ error: 'permission_denied', message: expect.stringContaining('write source is default') });
const [after] = await engine.executeRaw<{ n: number }>("SELECT count(*)::int AS n FROM minion_jobs WHERE name = 'ingest_capture'");
expect(after.n).toBe(before.n);
const granted = await ingest('alice-documented', note('Alice doc ingest', 'Ingest ' + marker('ingestdoc') + '.'));
@@ -178,7 +200,7 @@ for (const kind of testBackends()) {
}
for (const kind of testBackends()) {
- describe('writes from a member-bound credential with no source grant (' + kind + ', repo brain)', () => {
+ describe('writes to default from a member-bound credential (' + kind + ', repo brain)', () => {
let engine: BrainEngine;
let close: () => Promise<void>;
const home = mkdtempSync(join(tmpdir(), 'gbrain-gst2051-' + kind + '-'));
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 72ad5657dd..a23cbc2a41 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -23,6 +23,7 @@ test/access-members.test.ts
test/access-on-behalf-of.test.ts
test/access-page-indexes-online.test.ts
test/access-qm-actor.test.ts
+test/access-ungranted-member-writes.test.ts
test/access-writes.test.ts
test/activation-unbound-rooted-6449.test.ts
test/adopt-local-edit.test.ts