Security: page tokens come only from iterator keys (C1Z-SEC-010) #1169
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.76) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.76 · 532 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.376
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.076
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1169"
general
weight: 0.35
c1-squire-dev[bot]
Summary
C1Z-SEC-010. The Pebble paginators mint each next-page cursor from the iterator key of the last row they return, and the next page starts strictly after it (
rangeAfterappends0x00). Five list RPCs overrode that cursor whenever they filled a page mid-scan, rebuilding it from the last record's value fields instead:ListResources(primary keyspace and by_parent index)ListGrantsForEntitlement(reader v2 and v3)ListGrantsForEntitlements(reader v2 and v3)In a hostile
.c1za record's value need not match its key. A row whose value names an id that sorts before its key, landing at a page boundary, mints a cursor that sorts before rows already served. The next page re-serves them, forever. Every exhaustive pager over a foreign file loops and grows until OOM: the syncer's external-resource ingestion,baton resources/csv/diff, and the explorer.Change
The RPCs no longer mint cursors; they return the engine's.
ListResourceswithResourceTypeIdbounds the iterator to that type's prefix instead of scanning every resource and discarding other types. Each listing reads only rows of the requested type.iteratePrimaryPageWithKeytakes akeep func(T) bool(nil keeps every record). A page holdslimitkept records, and its cursor is the iterator key of the last one. The grant RPCs pass their principal-type filter askeep.PaginateGrantsByPrincipalResourceTypealready filtered this way.cursorFor, the refill loop,brokeEarly, and the 4× over-fetch heuristic.ListGrantsForEntitlement(s)bodies were line-for-line copies. Each pair now shareslistGrantsForEntitlement/listGrantsForEntitlements, which return[]*v3.GrantRecord; v2 converts the result.- The batch RPC requests exactly as many rows as are left, so a full page always ends on the engine page's last row, and the engine's cursor already marks it.
- When an entitlement is exhausted on a full page, the existing next-entitlement branch runs, so the next call no longer starts with an empty page.
iterateGrantPrimaryPagewas a copy of the generic iterator forGrantRecord; it now uses the generic one.PaginateResources,PaginateResourcesByParentandPaginateGrantsByEntitlementkeep their signatures and wrap unexported versions that take the type filter orkeep.With this, pagination terminates for any stored bytes. Pebble pages start strictly after the last returned key. SQLite tokens are
lastRowid+1, minted only when a later row exists. The earlier revision'snext == pageTokenguards in 11 caller loops (syncer, explorer,cmd/baton) are therefore removed. They checked the engine's contract from outside, caught only an exact repeat (not an A→B→A cycle), and covered some loops but not others.Tests
TestSecurity_PageTokensAdvancePastHostileRowsplants, in each keyspace, a row whose value names an id sorting before every key, as the last row of the first page. It then pages exhaustively and requires every row exactly once:ListResources, by resource type, by parent, and by parent and type;ListGrantsForEntitlement, and filtered by principal resource type;ListGrantsForEntitlements.On
main, every subtest re-serves the first page until the page bound (r1 r2 r0 r1 r2 r0 …).TestListResourcesTypeFilterPaginationpagesListResourcesby type, with and without a parent, overuser/us/groupchildren of one parent. It must return exactly the requested type, which covers the scan prefixes' trailing separator (usis a name prefix ofuser). It replacesTestPostFilterPaginationDoesNotSkip.The grant post-filter no-skip tests, pagination tests, v3 record-preservation tests and cross-engine parity test pass unchanged.
golangci-lintv2.13.2: 0 issues.go test -short -tags=baton_lambda_support ./...: passes.go test -race ./pkg/dotc1z/engine/pebble: passes.