Repository navigation
fix(codegen): scope vector write-sync by the shard key so .vectorize() can't cross-tenant-leak - #278
Conversation
…) can't cross-tenant-leak Vectorize indexes are account-global, so a .vectorize() table that is also .shardBy()'d had every shard's auto-synced vectors land in one shared, unpartitioned namespace — any tenant's query could see every other tenant's vectors. The hook already accepted a namespace option; the codegen emit just never passed one, so the built-in dev warning fired and was ignored while production shipped unscoped. Pass the owning DO's shard key as the namespace when the vectorized table is .shardBy()'d; map the ROOT_SHARD_NAME sentinel back to undefined so a root-mode write stays namespace-less. A schema with no sharded vector table emits the bare call, unchanged — goldens and every examples/*/_generated stay byte-identical.
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
Next review available in: 39 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
WalkthroughVector synchronization now detects vectorized tables configured with ChangesVectorize namespace generation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thank you for following the naming conventions! 🙏 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
Merging this PR will not alter performance
Comparing Footnotes
|
… inline .vectorize() hasShardedVectors only checked table.vectorIndexes, which holds inline .vectorize() (Shape A) indexes only. Standalone defineVectorIndex(...) (Shape B, incl. extension-contributed) never get hoisted onto their owning table and live only in the schema-level vectorIndexes array. A .shardBy()'d table indexed via Shape B was silently gated out, so its sync hook stayed wired but namespace-less -- every tenant's vectors landing in one unpartitioned Vectorize namespace. Gate across schema.vectorIndexes instead, keyed back to each index's owning table via VectorIndexIR.table, and discriminate the shard-mode union on its kind tag rather than a bare typeof check. Also de-brittles a test assertion that pinned the entire shared-import line instead of just the ROOT_SHARD_NAME fragment this test owns.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What
Closes a silent cross-tenant leak:
.vectorize()'s auto write-sync was emitted unscoped.emit.tscalledcreateVectorSyncHook({ schema, vectors })with nonamespace, so in a multi-tenant sharded app every tenant's vectors landed in one shared, unpartitioned Vectorize namespace — any tenant's query without a namespace filter could then read another's vectors. The only prior mitigation was a one-time devconsole.warn, which is not a security control.The fix
The hook already supported scoping (
createVectorSyncHook's optionalnamespace, whose docblock says the caller MUST pass the shard/tenant key) — the gap was purely in the emit. And the shard key is reachable at the emission site with zero plumbing:vectorsBuildis inlined in the emittedShardDOsubclass'sbuildCtx(), sothis.currentShardKey()(alreadyprotectedonShardDOBase, returningrunner.shardKey ?? ROOT_SHARD_NAME) is directly callable — noShardHost/ctx contract change needed.emit.ts now threads
namespace: this.currentShardKey() === ROOT_SHARD_NAME ? undefined : this.currentShardKey()into thecreateVectorSyncHook(...)call, gated on a new codegen-timehasShardedVectorsflag (a vector-indexed table and.shardBy()).Single-tenant stays byte-identical
An unsharded/single-tenant app emits the bare (namespace-less) call exactly as before —
define-rag.tsdocuments namespace-less single-tenant as a legitimate mode. Proven two ways: a codegen test that negative-assertsnamespace:/ROOT_SHARD_NAME/currentShardKeyfor an unsharded vectorized table, and zero golden/example delta on regeneration (the only vectorized example,examples/blog, is unsharded, so it exercises exactly the unchanged branch).Verification
@lunora/codegen975 tests, no golden drift;@lunora/bindings222.lint:types/lint:eslintclean;build:packagesgreen.examples/*/_generatedregenerated via the documented flow → zero delta everywhere (confirmed correct, not coincidental — see above).bindings/__tests__/vectors/end-to-end.test.ts): two hooks (namespaceshard-a/shard-b) against one shared namespace-partitioning Vectorize fake; asserts each shard's query returns only its own row, plus an unnamespaced query sees both (proving isolation comes from the filter, not the fake's layout) — a real cross-namespace assertion, not just "a namespace was passed.".shardBy()+.vectorize()), so it's covered by the new unit test rather than a golden.Context
This is plan 238's shippable prerequisite — a scoped
.withVectorIndex()reader (#274) over an unscoped write path buys nothing; this makes the write side agree.Merge-order note
packages/codegen/src/emit.tsis also edited by #243 (alarm codegen). My change is localized to the vector-index block (~lines 4123–4460); expect a trivial keep-both merge.Plan:
plans/251-*.md.🤖 Generated with Claude Code
Summary by CodeRabbit
.shardBy().