Repository navigation
fix(analytics): an empty or blank where key answers 400 INVALID_FIELD on all three analytics doors - #38218
Conversation
…IELD / 400 Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8
… add changeset Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8
📓 Docs Drift CheckThis PR changes 1 package(s): 42 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 80534dfa60f59ebb54b1e5d5f64cf8c2a26c8f7e && git checkout 80534dfa60f59ebb54b1e5d5f64cf8c2a26c8f7e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e42520c67bcef027552f8db83655ff9b54d32cef 45e72db154ae37b129ff86c423780a8477bb128f && git checkout -B drift-repro e42520c67bcef027552f8db83655ff9b54d32cef && git merge --no-ff 45e72db154ae37b129ff86c423780a8477bb128f
node scripts/docs-audit/affected-docs.mjs --json e42520c67bcef027552f8db83655ff9b54d32cef
|
The changeset claimed every key that names no field (`foo bar` included) now answers 400, and stated an identifier rule for every key. The tree refuses only empty and whitespace-only keys; non-identifier text keeps the #21156 403. Prose only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xRBcVgQPLb4gAUQrngR45
|
repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8 L1: ACCEPT · head Seat checks
Landing: non-governed, ≤3000 lines. The seat lands it through the ordinary queue. |
Fixes #35543
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
An empty filter key (
{"": "z"}) onPOST /api/v1/analytics/query, as the datasetruntimeFilteronPOST /api/v1/analytics/dataset/query, and through MCPquery_datasetreached SQLite asWHERE = ?and answered500 DATABASE_ERROR. A blank key (" ") answered403 PERMISSION_DENIEDfrom the field-read gate. Both now answer400 INVALID_FIELD(field,param: 'where'), as/dataanswers the same body. The engine is never reached.The mechanism: every analytics gate passes the empty key by.
namedQueryFieldsskipsmember === ''outright, andresolveMemberSourceanswerssource: null(a stand-down) for any spelling that is not a bare identifier. So nothing judged it before the strategy compiled it. The fix is one check,assertWhereMemberIsFieldName, at the top of thewheresource-field gate (assertWhereFields, #5669). That gate runs on every path out ofensureCubeand on the dataset draft-preview path, so all three doors share it. The check needs no field probe. It runs before the gate's three probe stand-downs, because no object has a field with an empty name./data's validator (assertFilterFieldsExist,@objectstack/metadata-protocol) is not reused. It answers "is this a field of the object". The analytics question is "does this member resolve to a column", and the existingwheregate already asks it in the analytics vocabulary (cube members, the cube qualifier, relationship paths). Taking a dependency on the protocol package for an emptiness check would add a second reader of the filter tree.Deliberately narrow: only whitespace-only keys. A key that is text but no column reference (
amount + 1,foo bar) keeps the #21156 member-shape gate'sPERMISSION_DENIED/ 403. That verdict is pinned "in every tier" bycaller-member-column-reference-gate.test.ts, which this PR's first, wider draft turned red (8 cases). Changing that verdict is a contract question and is out of scope here.Tests
src/__tests__/where-member-field-name-35543.test.tsuses the plugin-wired service (AnalyticsServicePluginover an engine double), with all three doors called as their callers call them:service.query,service.queryDatasetanddatasetTools().queryDataset.code: 'INVALID_FIELD',status: 400,field,param: 'where'. The engine saw no statement.$or: refused the same way.amount + 1keepsPERMISSION_DENIED/ 403. This is the [security] An analytics query path can carry caller-supplied member text into the native statement in a tier the field gate does not judge — detail withheld pending maintainer #21156 boundary.{status: 'paid'}answers on all three doors.Ablation through
scripts/ablation-replace.mjs, which deleted the gate's call line (anchor 1 to 0, restored blob == HEAD,git diff HEADempty). 10 failed, 1 passed (the control). The red set was every refusal case on all three doors.Live re-measure on the stock showcase (
--fresh, admin), before at7605e0c9cand after atc79abcb26:/analytics/querywhere {"": "z"}/analytics/dataset/queryruntimeFilter {"": "z"}query_datasetruntimeFilter {"": "z"}{" ": "z"}{"status": "paid"}on all three/data/showcase_invoice/querywhere {"": "z"}Package run at c79abcb
pnpm --filter @objectstack/service-analytics typecheck && … build && … testunder the verify lock:VERDICT command-exit 0,Test Files 228 passed (228),Tests 5914 passed | 345 skipped (6259).tsc --listFilesincludes the new test file.Acceptance notes
where {"account.a.b.c.d": "z"}still answers403 PERMISSION_DENIEDnaming the synthesized aliasaccount__a. The two-hopaccount.nopeanswers400 INVALID_FIELDnamingshowcase_account. It is a relationship-path resolution question, not an empty key, and is reported for the seat to file.foo bar) still answers 403 under [security] An analytics query path can carry caller-supplied member text into the native statement in a tier the field gate does not judge — detail withheld pending maintainer #21156, where/dataanswers 400. See the narrowing above./data's empty-key envelope omitsfield, where its blank-key envelope carriesfield: " ". This is an observation only.Verification
Read first:
assertWhereMemberIsFieldNameand its call at the top ofassertWhereFields(packages/services/service-analytics/src/analytics-service.ts). The risk hunk is the move of the three probe stand-downs below the member collection. The second file is the new test.Two-minute check:
pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/where-member-field-name-35543.test.ts. Expect 12 passed.Gates at
c79abcb26:dispatch-gates --ranaccounts for 71 derived families. 69 ran with exit 0. 2 are NOT MEASURED (exit 3, prerequisite not met):check:dual-build-cjs-loadsneeds a full workspace build, andcheck:type-check-debtcould not get a turn on the verify lock. CI runs both.Generated by Claude Code