Skip to content

feat(objectql): enforce per-option visibleWhen server-side (objectui#2284)#2637

Merged
os-zhuang merged 1 commit into
mainfrom
claude/select-option-server-enforcement
Jul 5, 2026
Merged

feat(objectql): enforce per-option visibleWhen server-side (objectui#2284)#2637
os-zhuang merged 1 commit into
mainfrom
claude/select-option-server-enforcement

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Follow-up to the spec + renderer work for cascading/role-gated select options (objectstack-ai/objectui#2284, spec #2635, renderer objectui#2289). This closes the security leg: server-side enforcement of per-option visibleWhen.

Why

SelectOption.visibleWhen hides an option in the UI, but hiding is not a security boundary — a caller can submit a hidden value directly (curl, script, replayed request). For a role-gated option ('admin' in current_user.roles) that is an authorization bypass; for a cascade (record.country == 'cn') it is a data-integrity hole (the "China + California" pair). The write path must re-check.

What

  • rule-validatorevaluateOptionVisibility: for each written select/multiselect/radio field, find the picked option(s) and re-evaluate their visibleWhen against the merged record + current_user. A clean FALSEinvalid_option validation error (same ValidationError envelope → 400 VALIDATION_FAILED). Multi-select is checked element-wise. Unchanged persisted values are not re-checked (only what the patch writes).
  • Fail-open on unevaluable predicates (missing referenced field, or unbound current_user on a system write) — consistent with every other field rule here, so a broken cascade predicate never bricks a write. Authorization gating therefore depends on current_user being bound.
  • engine: binds current_user (ADR-0068 EvalUser{id, roles, organizationId}) from the execution context at the insert/update validation call sites (buildEvalUser).
  • needsPriorRecord now accounts for option visibleWhen, so on update a cascade predicate referencing an unchanged sibling reads it from the prior record.

Semantics

Predicate result Outcome
clean FALSE reject (invalid_option)
clean TRUE allow
errors (missing field / unbound current_user) allow (fail-open, logged)

This single pass enforces both authorization gating and cascade integrity without needing to distinguish the two intents — reject-on-clean-false is correct for both, provided current_user is bound (which the engine now does).

Tests

  • 15 new unit tests (rule-validator.option-visibility.test.ts): cascade insert, cascade update via prior record, "only written fields checked", role gating (admin vs non-admin), fail-open when current_user unbound, multi-select element-wise, needsPriorRecord.
  • Existing rule-validator + engine suites unchanged (61 validation + 141 engine/validation tests green). @objectstack/objectql builds (tsc/DTS) clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_019aYFm77ddLp6tzuJjt9hK2


Generated by Claude Code

…2284)

A select/multiselect/radio option may gate itself with a `visibleWhen` CEL
predicate. Client-side hiding is UX, not a security boundary, so on write the
engine now re-evaluates the picked value's predicate against the merged record +
`current_user` and rejects a clean FALSE (`invalid_option`). Enforces both
role/context gating (`'admin' in current_user.roles`) and cascade integrity
(`record.country == 'cn'`) that a caller could bypass by submitting a hidden
value directly.

- rule-validator: `evaluateOptionVisibility` checks only WRITTEN choice fields
  (multi-select element-wise); fail-open on an unevaluable predicate (missing
  field / unbound current_user) so cascade predicates never brick a write.
  `needsPriorRecord` now accounts for option visibleWhen so a cascade predicate
  can read an unchanged sibling from the prior record on update.
- engine: bind `current_user` (ADR-0068 EvalUser) from the execution context at
  the insert/update validation call sites.
- 15 new unit tests (cascade insert/update, role gating, fail-open, multiselect).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019aYFm77ddLp6tzuJjt9hK2
@vercel

vercel Bot commented Jul 5, 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 5, 2026 1:35pm

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/m labels Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

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

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

  • content/docs/concepts/metadata-lifecycle.mdx (via @objectstack/objectql)
  • content/docs/data-modeling/formulas.mdx (via packages/objectql)
  • content/docs/deployment/migration-from-objectql.mdx (via @objectstack/objectql)
  • content/docs/deployment/vercel.mdx (via @objectstack/objectql)
  • content/docs/kernel/services-checklist.mdx (via @objectstack/objectql)
  • content/docs/kernel/services.mdx (via @objectstack/objectql)
  • content/docs/permissions/authentication.mdx (via @objectstack/objectql)
  • content/docs/plugins/index.mdx (via @objectstack/objectql)
  • content/docs/plugins/packages.mdx (via @objectstack/objectql)
  • content/docs/protocol/objectos/index.mdx (via @objectstack/objectql)
  • content/docs/protocol/objectql/state-machine.mdx (via @objectstack/objectql)
  • content/docs/releases/implementation-status.mdx (via @objectstack/objectql)
  • content/docs/releases/v9.mdx (via @objectstack/objectql)

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 marked this pull request as ready for review July 5, 2026 14:13
@os-zhuang
os-zhuang merged commit 5a0da03 into main Jul 5, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the claude/select-option-server-enforcement branch July 5, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants