Skip to content

feat(core)!: reads fail closed: no context reads as public, no ambient session (2c) - #30

Merged
jherr merged 1 commit into
mainfrom
cursor/access-fail-closed-a931
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/access-fail-closed-a931

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements cms-refactor-plan.md § Phase 2c (item 4, "Access context for reads"). It also covers the revision-log rulings of 2026-11-05 on the slug-read leak, the populate publicRead quirk and the preview-token redaction quirk.

Merge chain: step 15 of 24. Base: main. Merge it right after #37. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit c00ad35 (tree 5113fbb).

What

  • Reads fail closed. The 13 plain read verbs in @tanstack/cms-core/server are @deprecated and now read as publicContext(): published documents only, redacted for an anonymous visitor. Before, they read everything, drafts included. Phase 6 removes them.
  • Legacy read options are removed. session, publishedOnly and publicRead are gone from every read verb and from createCmsSearch, which takes access instead.
  • No ambient session. runWithSession and currentSession are removed.
    • runOp, cmsMcp.fetch and cmsTools require a context and throw UNAUTHORIZED without one.
    • afterChange/afterDelete hooks receive the writer's session.
  • Core internals that bypass access use named system contexts, for example 'redirect lookup' and 'revision restore', so every bypass says why it exists. The sitemap reads as public.
  • Three leaks fixed, each pinned by a test:
    • Slug reads check access on the matched document. A draft the reader can't see returns null, as a missing one would.
    • Populated relations follow the reader's context, including publicRead.
    • Preview-token documents are redacted as for an anonymous visitor.
  • search_documents takes mode (live, preview or edit) instead of publishedOnly. It can only narrow the caller's access, never widen it.
  • Codemod: pnpm codemod access-context, with 7 fixtures, rewrites deprecated reads to the …As(ctx, …) form. It warns on runWithSession/currentSession, which need rewriting by hand.
  • Migrated across the repo. I ran the codemod, then reviewed every site it flagged by hand.
    • Visitor-facing reads use publicContext(). This fixes real draft leaks in db-markdown and in several starters' public ops: searchVersionedDocs, searchDirectoryListings, addToCart, readPublicationIssue and the lesson lookup.
    • Staff ops read as the caller.
    • Server-owned records use named system contexts.
    • Docs, skills, the starters' integration notes and a new upgrade step are updated.
  • Bug the switch exposed: uploadMedia relied on the ambient session to attribute uploads. It now passes the caller's session.
  • Dialect inventory: the runWithSession/currentSession markers are retired.
  • Changeset: .changeset/access-fail-closed.md, breaking, for core, api, cli and search-cms.

Breaking changes

  • Plain read verbs read as public. Trusted callers must pass a context. Run pnpm codemod access-context, then give each systemContext it adds a real reason.
  • Removed: the session/publishedOnly/publicRead read options, runWithSession and currentSession.
  • search_documents: publishedOnly becomes mode.
  • resolveSession() without a request resolves as a request with no credentials.
  • atproto publish reports "No published document" for drafts.

Assumptions (tasks 8–12 defaults)

  • Actor shape: 2b's, since task 8 hasn't been reviewed.
  • Default modes: request contexts still default to edit. Visitors get live through publicContext() or getCmsAccessContext().
  • Preview contexts carry the unauthenticated session.

Divergence from plan

  1. All 13 read verbs stay as deprecated wrappers, not only the three Q25 names. This follows the plan's 2c text ("old verbs without a context default to public until phase 6"). The hard break applies to the options and to runWithSession/currentSession.
  2. Hooks get the writer's session, not a write context, because writes are phase 5.
  3. A few trusted paths stay system reads, each named: redirect lookup, runOp's target lookup, admin ops that check their own results, media usage and translation links.
  4. app/base keeps its postRead access hook. Its scoped-session tests depend on it.
  5. Two follow-ups aren't done here: a test that runs every starter's public routes anonymously, from the plan's risk section, and a lint rule for systemContext.

How verified

  • New core tests cover:
    • deprecated verbs reading as public;
    • slug-read access;
    • populate publicRead;
    • preview redaction;
    • runOp/cmsTools refusing a call without a context;
    • search_documents and narrowMode only narrowing.
  • Codemod: all 7 fixtures pass under pnpm test:scripts.
  • pnpm test:pr: passes on all 174 tasks except the cms-api oxlint error that main already has.
    • Core ran 576 tests. The Postgres ones were skipped because there's no Docker.
    • api ran 202, app/base 42 and app/prm 9.
  • test:dts and test:dialects: pass.

Merge chain (local verification, CI down)

This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied.

18 files conflicted, and I resolved them as on the integration rehearsal. ops.ts, review.ts and write.ts take #40's merge resolution (32d8e18), minus #40's own write-actions (3a) changes.

Three changes had no textual conflict but were still needed:

This PR's upgrading section is step 25, and the link to it is updated.

The chain tip's tree is exactly the integration rehearsal plus #46 (c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the new main; that rebase is always clean.

Open in Web Open in Cursor 

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 159 files, which is 9 over the limit of 150.

To get a review, reduce the PR to 150 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Check out review usage here.

Run configuration

  • Source mode: Auto
  • Repository: TanStack/cms
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 5c474b0
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 69a939a4-fb91-472c-86a3-6ce820f703d7
Commits

Reviewing files that changed from the base of the PR and between 5c474b0 and 62bd8c6.

Files selected for processing: 159

  • .changeset/access-fail-closed.md
  • .claude/skills/emdash-to-tanstack-cms/SKILL.md
  • .claude/skills/payload-to-tanstack-cms/SKILL.md
  • .claude/skills/voting/SKILL.md
  • .claude/skills/wordpress-to-tanstack-cms/SKILL.md
  • app/base/src/collection-runtime.ts
  • app/base/src/operations.server.ts
  • app/base/tests/base.test.ts
  • app/base/tests/chat.test.ts
  • app/base/tests/schema-registry.test.ts
  • app/base/tests/worker.test.ts
  • app/base/tests/wp-evacuation.test.ts
  • app/prm/bakeoff/README.md
  • app/prm/bakeoff/latest.json
  • app/prm/scripts/mine-summit-speakers.ts
  • app/prm/scripts/snoop-sunil.ts
  • app/prm/src/ops/import-people.ts
  • app/prm/src/search.functions.ts
  • app/prm/tests/crm.test.ts
  • docs/agents/review-queue.md
  • docs/api/cli.md
  • docs/api/cms-core-server.md
  • docs/architecture/data-layer.md
  • docs/architecture/terminology.md
  • docs/deployment/upgrading.md
  • docs/mcp/http-mcp-server.md
  • docs/mcp/operations-registry.md
  • docs/mcp/webmcp.md
  • docs/migration/from-emdash.md
  • docs/migration/from-payload.md
  • docs/migration/from-sanity.md
  • docs/migration/from-wordpress.md
  • docs/migration/overview.md
  • docs/schema/building-pages.md
  • docs/schema/collections-and-fields.md
  • examples/astro-starlight-after/src/migration.test.ts
  • examples/blog-voting/src/voting/votes.ts
  • examples/blog-voting/src/voting/voting.test.ts
  • examples/db-markdown/README.md
  • examples/db-markdown/content/posts/draft-post.md
  • examples/db-markdown/src/docs.functions.ts
  • examples/emdash-after/MIGRATION.md
  • examples/emdash-after/src/migration.test.ts
  • examples/payload-after/src/migration.test.ts
  • examples/payload-after/src/routeTree.gen.ts
  • examples/picks/src/search.functions.ts
  • examples/wordpress-after/MIGRATION.md
  • examples/wordpress-after/src/migration.test.ts
  • packages/api/src/http.ts
  • packages/api/src/mcp.ts
  • packages/api/src/media-ops.ts
  • packages/api/src/ops.ts
  • packages/api/tests/access.test.ts
  • packages/api/tests/act-on-change.test.ts
  • packages/api/tests/bulk.test.ts
  • packages/api/tests/characterization/save-paths.test.ts
  • packages/api/tests/contract/s2-propagation.test.ts
  • packages/api/tests/contract/s3-s5-contract.test.ts
  • packages/api/tests/ops.test.ts
  • packages/api/tests/readiness.test.ts
  • packages/api/tests/soft-delete.test.ts
  • packages/api/tests/workflow.test.ts
  • packages/cli/src/commands/atproto.ts
  • packages/cli/tests/cli.test.ts
  • packages/client/tests/db.test.ts
  • packages/core/bench/store.ts
  • packages/core/src/index.ts
  • packages/core/src/ops.ts
  • packages/core/src/schema.ts
  • packages/core/src/server.ts
  • packages/core/src/server/access-context.ts
  • packages/core/src/server/assets.ts
  • packages/core/src/server/auth.ts
  • packages/core/src/server/cms-ops.ts
  • packages/core/src/server/cms-tools.ts
  • packages/core/src/server/interface-schedules.ts
  • packages/core/src/server/interfaces.ts
  • packages/core/src/server/media.ts
  • packages/core/src/server/seo.ts
  • packages/core/src/server/store.ts
  • packages/core/src/server/store/collaboration.ts
  • packages/core/src/server/store/document-state.ts
  • packages/core/src/server/store/internal.ts
  • packages/core/src/server/store/query.ts
  • packages/core/src/server/store/read.ts
  • packages/core/src/server/store/review.ts
  • packages/core/src/server/store/revisions.ts
  • packages/core/src/server/store/scheduling.ts
  • packages/core/src/server/store/write.ts
  • packages/core/tests/access-context.test.ts
  • packages/core/tests/assets.test.ts
  • packages/core/tests/characterization/workflow-suite.ts
  • packages/core/tests/collaboration.test.ts
  • packages/core/tests/content-migrations.test.ts
  • packages/core/tests/document-state.test.ts
  • packages/core/tests/events.test.ts
  • packages/core/tests/field-access.test.ts
  • packages/core/tests/field-i18n.test.ts
  • packages/core/tests/fields.test.ts
  • packages/core/tests/interface-schedules.test.ts
  • packages/core/tests/interfaces.test.ts
  • packages/core/tests/plugins.test.ts
  • packages/core/tests/preview-tokens.test.ts
  • packages/core/tests/readiness.test.ts
  • packages/core/tests/references.test.ts
  • packages/core/tests/slow-hooks.test.ts
  • packages/core/tests/storage-conformance.test.ts
  • packages/core/tests/store-index.test.ts
  • packages/core/tests/store.test.ts
  • packages/core/tests/transfer.test.ts
  • packages/core/tests/where.test.ts
  • packages/search-cms/src/index.ts
  • packages/search-cms/tests/cms.test.ts
  • packages/store-postgres/tests/events.test.ts
  • packages/store-postgres/tests/invariants.test.ts
  • packages/store-postgres/tests/postgres.test.ts
  • packages/ui-react/tests/s2-blog-propagation.test.ts
  • scripts/codemods/__fixtures__/access-context/ambient.input.ts
  • scripts/codemods/__fixtures__/access-context/ambient.output.ts
  • scripts/codemods/__fixtures__/access-context/ambient.warnings.json
  • scripts/codemods/__fixtures__/access-context/calls.input.ts
  • scripts/codemods/__fixtures__/access-context/calls.output.ts
  • scripts/codemods/__fixtures__/access-context/calls.warnings.json
  • scripts/codemods/__fixtures__/access-context/docs.input.md
  • scripts/codemods/__fixtures__/access-context/docs.output.md
  • scripts/codemods/__fixtures__/access-context/dynamic.input.ts
  • scripts/codemods/__fixtures__/access-context/dynamic.output.ts
  • scripts/codemods/__fixtures__/access-context/dynamic.warnings.json
  • scripts/codemods/__fixtures__/access-context/positional.input.ts
  • scripts/codemods/__fixtures__/access-context/positional.output.ts
  • scripts/codemods/__fixtures__/access-context/store.test.input.ts
  • scripts/codemods/__fixtures__/access-context/store.test.output.ts
  • scripts/codemods/__fixtures__/access-context/untouched.input.ts
  • scripts/codemods/access-context.ts
  • scripts/codemods/index.ts
  • scripts/dialect-inventory.baseline.json
  • starters/admin-only/CMS-INTEGRATION.md
  • starters/admin-only/tests/seam.test.ts
  • starters/contact-cards/CMS-INTEGRATION.md
  • starters/contact-cards/src/cms.config.ts
  • starters/contact-cards/tests/seam.test.ts
  • starters/directory-listings/CMS-INTEGRATION.md
  • starters/directory-listings/src/cms.config.ts
  • starters/directory-listings/tests/seam.test.ts
  • starters/documentation-kb/CMS-INTEGRATION.md
  • starters/documentation-kb/src/cms.config.ts
  • starters/ecommerce-storefront/src/cms.config.ts
  • starters/ecommerce-storefront/tests/seam.test.ts
  • starters/editorial-publication/CMS-INTEGRATION.md
  • starters/editorial-publication/src/cms.config.ts
  • starters/headless-api/CMS-INTEGRATION.md
  • starters/headless-api/tests/contract.test.ts
  • starters/membership-course/CMS-INTEGRATION.md
  • starters/membership-course/src/cms.config.ts
  • starters/multi-tenant-fleet/CMS-INTEGRATION.md
  • starters/multi-tenant-fleet/src/cms.config.ts
  • starters/runtime-tables/CMS-INTEGRATION.md
  • starters/runtime-tables/src/cms.config.ts
  • starters/runtime-tables/tests/seam.test.ts

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62bd8c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/cms-core Minor
@tanstack/cms-api Minor
@tanstack/cms-cli Minor
@tanstack/search-cms Minor
@tanstack/cms-client Minor
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/cms-media-s3 Minor
@tanstack/cms-store-libsql Minor
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch
@tanstack/cms-ui-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…t session (2c) (#30)

Chain step 15 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order.

Co-authored-by: jherr <jherr@pobox.com>
@jherr
jherr force-pushed the cursor/access-fail-closed-a931 branch from c00ad35 to 62bd8c6 Compare November 6, 2026 15:08
@jherr
jherr merged commit 7013166 into main Nov 6, 2026
@jherr
jherr deleted the cursor/access-fail-closed-a931 branch November 8, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants