Skip to content

fix(analytics): scope /analytics/query + /sql to the caller (RLS) (#2852)#2854

Merged
os-zhuang merged 1 commit into
mainfrom
fix/analytics-query-rls-context
Jul 12, 2026
Merged

fix(analytics): scope /analytics/query + /sql to the caller (RLS) (#2852)#2854
os-zhuang merged 1 commit into
mainfrom
fix/analytics-query-rls-context

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Closes the reachable part of #2852. Found by the ADR-0090 D10 adversarial security review.

The hole

handleAnalytics (the /api/v1/analytics/* dispatcher) received the request context as _context (unused) and called analyticsService.query(body) with no execution context. The analytics service's per-object read-scope provider (getReadScope → security getReadFilter) therefore got undefined and applied no tenant/RLS filter — so an authenticated caller hitting POST /analytics/query received rows their row-level security would otherwise hide.

The fix

Thread context.executionContext into analyticsService.query(…) and generateSql(…) — both already accept an optional ExecutionContext. Each object in the query is now scoped by its per-object read filter (tenant + RLS), matching the /analytics/dataset/query bridge path which already threads it.

Residual (tracked in #2852)

The analytics read-scope provider (getReadFilter in plugin-security) does not yet apply the ADR-0090 D10 agent delegator intersection. This is latent today — analytics is not reachable over the OAuth /mcp surface, so no agent principal drives it — but it should be brought in lock-step with the engine middleware when analytics becomes agent-reachable.

Tests

  • Dispatcher test asserts the execution context now reaches query and generateSql.
  • runtime http-dispatcher suite 165 green.

🤖 Generated with Claude Code

)

handleAnalytics dropped the request's execution context —
analyticsService.query(body) was called with no context, so the analytics
read-scope provider (getReadScope → security getReadFilter) received
undefined and applied NO tenant/RLS filter. An authenticated caller could
query analytics datasets and receive rows their row-level security would
otherwise hide.

Thread context.executionContext into query() and generateSql() (both
already accept it) so each object is scoped by its per-object read filter.

The analytics getReadFilter does not yet apply the ADR-0090 D10 agent
delegator intersection — latent (analytics isn't reachable over /mcp),
tracked in #2852. Found by the D10 adversarial security review.

Test: dispatcher asserts the execution context now reaches query/generateSql.
runtime http-dispatcher 165 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jul 12, 2026 10:14am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/s and removed documentation Improvements or additions to documentation tests tooling labels Jul 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/runtime.

15 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/api/index.mdx (via @objectstack/runtime)
  • content/docs/api/wire-format.mdx (via @objectstack/runtime)
  • content/docs/automation/hook-bodies.mdx (via @objectstack/runtime)
  • content/docs/concepts/north-star.mdx (via packages/runtime)
  • content/docs/data-modeling/drivers.mdx (via @objectstack/runtime)
  • content/docs/deployment/index.mdx (via @objectstack/runtime)
  • content/docs/deployment/production-readiness.mdx (via @objectstack/runtime)
  • content/docs/deployment/single-project-mode.mdx (via @objectstack/runtime)
  • content/docs/deployment/vercel.mdx (via @objectstack/runtime)
  • content/docs/permissions/authentication.mdx (via @objectstack/runtime)
  • content/docs/plugins/packages.mdx (via @objectstack/runtime)
  • content/docs/protocol/objectos/http-protocol.mdx (via @objectstack/runtime)
  • content/docs/protocol/objectos/index.mdx (via @objectstack/runtime)
  • content/docs/protocol/objectos/lifecycle.mdx (via @objectstack/runtime)
  • content/docs/releases/implementation-status.mdx (via @objectstack/runtime)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@os-zhuang
os-zhuang merged commit 5f43f88 into main Jul 12, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the fix/analytics-query-rls-context branch July 12, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant