Commit 587fc91
The analytics→engine bridge now forwards the request's ExecutionContext to
`engine.aggregate`, so the engine's own middleware chain scopes analytics
reads independently of the analytics layer's `getReadScope`.
`BaseEngineOptions.context` has always been `.optional()`, so nothing forced
the bridge to pass it — and it did not. An authenticated aggregate reached the
engine with no principal, plugin-security's principal-less fall-open skipped
its RLS injection, and the only thing left scoping the query was the strategy
remembering to call `getReadScope`. #3597 was a strategy that did not, and both
belts were off at once.
`getReadScope` stays: the two resolve scope through different paths (engine
middleware vs `security.getReadFilter`), and a deployment without
plugin-security has only the analytics layer. Depth, not a replacement.
- `StrategyContext` gains `context?: ExecutionContext`, bound per call by
`AnalyticsService.callCtx` — unconditionally, including when no read-scope
provider is configured, since that deployment needs the engine belt most.
- `StrategyContext.executeAggregate` and the plugin/service `executeAggregate`
config options gain `context?: ExecutionContext`. Additive: a custom bridge
that ignores it behaves exactly as before.
- `fetchRecordLabels` — the dimension display-label lookup — is row-granular
(one row per record, real display names) and ran with neither read scope nor
context. Its ids come from a scoped aggregate today, so it leaked nothing,
but that was the caller's invariant, not the bridge's. Now ANDs the target
object's read scope in (`$and`, never a key merge) and forwards the context.
- `ObjectQLStrategy.generateSql` emitted no WHERE at all, so `/analytics/sql`
read as an unscoped table scan while the real aggregate was scoped. Now
renders the caller's filters and the read scope, and runs the same
joined-scope guard `execute()` does. Never executed, so this was misleading
output rather than a leak.
- `BootOptions.analytics` lets a gate boot with the analytics belt off; the new
dogfood case asserts the engine belt alone still scopes a member to their own
rows. Verified to bite: reverting the context forwarding makes it count 5
instead of 2.
Deliberately not fixed here: `ObjectQLStrategy.execute()` ignores
`timeDimensions[].dateRange` entirely, so `generateSql` does not render a
BETWEEN either. Filed as #3650.
Claude-Session: https://claude.ai/code/session_013st2KArjmLQSuVzpDS91jj
Co-authored-by: Claude <noreply@anthropic.com>
1 parent c2ecfda commit 587fc91
11 files changed
Lines changed: 702 additions & 38 deletions
File tree
- .changeset
- packages
- qa/dogfood
- test
- services/service-analytics/src
- __tests__
- strategies
- spec/src/contracts
- verify/src
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
0 commit comments