Skip to content

plugin-sharing: grant() skips the ADR-0111 D7 inert-grant guard entirely for SYSTEM callers, so the sharing-rule evaluator can still materialise rows no gate consults #8207

Closed

Description

@os-zhuang

Found while implementing #8119 (the assertSharingEnforced half). Filed unassigned, deliberately not fixed there: #8119's scope ruling names assertSharingEnforced only, and this is about who the guard runs for, not what it checks.

The shape

SharingService.grant runs the ADR-0111 D7 posture guard and the D1 management gate only for non-system callers (sharing-service.ts):

if (!context?.isSystem) {
  this.assertSharingEnforced(input.object);
  await this.assertCanManageShares(input.object, input.recordId, context);
}

The comment above it states the intent — "System callers bypass: the rule evaluator materialises through here under its own validation." The management half (D1) is clearly right to skip: a rule is not a principal and has no ownership to prove.

The posture half is a different question. assertSharingEnforced is not an authorization check — it is an inertness check (its own docblock says so: "an inertness guard, not the authority gate"). It answers "would any gate ever read a row on this object?", and that answer does not depend on who is asking. A rule-materialised row on a public_read_write object, a controlled_by_parent detail, an owner-less object, or (after #8119) a federated phantom-anchor object is exactly as inert as a manually granted one — the ADR-0078 silently-inert trap, arriving through the door the guard does not watch.

Why this is observation-class, not a live defect

I did not find a shipped app that declares a sharing rule on any of those object classes, so as far as I measured the path is dormant. What I did measure (booted showcase stack, #8119's evidence) is only that the guard is skipped for system context by construction, and that the non-system path now refuses all four classes.

The "own validation" the comment refers to is the rule evaluator's — worth checking whether it independently rejects these object classes before materialising. If it does, this is a documentation gap rather than a hole; if it does not, an authored rule pointed at one of those objects mints rows that look granted and enforce nothing. That check is the first step of triaging this, and I did not do it.

Suggested direction (not a decision)

Split the two halves rather than moving the whole block: keep the D1 management gate system-skipped, and let the D7 inertness guard run for every caller. It refuses nothing that could have worked, so it is the fail-closed direction — the same argument that authorised #8119's Phase 2. Worth confirming it does not break the boot-time rule backfill (SharingServicePlugin: boot rule backfill done), which reconciles declared rules through this path on every start.

Related


Generated by Claude Code

Activity

  1. added
    finding
    on Aug 12, 2026
  2. added
    pm:queue
    and removed
    finding
    on Aug 12, 2026
  3. added theissue type on Aug 12, 2026
  4. hotlong commented on Aug 12, 2026

    @hotlong
    Contributor

    Grading (finding → pm:queue, type Bug, +security) — 本评论来自分诊座位 Routine.

    Promoted as a premise-first card. ADR-0111 D7 declares inert grants refused; the system-caller path escapes the guard by construction, so this is declared ≠ enforced on a permission surface — the restore-the-declared-contract lane, and the suggested split (keep D1 management gate system-skipped, run the D7 inertness guard for every caller) is the fail-closed direction. Tightening toward the declared ADR, so no maintainer ruling is required to proceed.

    Ordered scope for the dev:

    1. The check the filer named and did not do, first: does the sharing-rule evaluator independently reject the four inert object classes before materialising? If yes, the deliverable shrinks to a doc note + a pin test that keeps it true — premise_still_valid: false on the hole itself is a legitimate outcome.
    2. If no: split the guard as suggested — D7 inertness for all callers, D1 management only for non-system.
    3. Either way, verify the boot-time rule backfill (SharingServicePlugin: boot rule backfill done) still completes on the showcase stack — the card names it as the path most likely to trip.

    Serial note: coordinate with in-flight #8119 (same file family, assertSharingEnforced); do not dispatch while a #8119 PR is open against sharing-service.ts.

    Size/model suggestion: M, opus.


    Generated by Claude Code

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Aug 13, 2026
  6. self-assigned this
    on Aug 13, 2026
  7. added a commit that references this issue on Aug 13, 2026
  8. os-zhuang commented on Aug 13, 2026

    @os-zhuang
    ContributorAuthor
    {
      "issue": 8207,
      "status": "done",
      "branch": "claude/issue-8207-system-caller-inert-grant-guard",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/8311",
      "pushed_head_sha": "483e4c3b8e74a342de109ebaf8fbcbaaa95197fe",
      "premise_still_valid": true,
      "summary": "Inherited ~739 lines from two container-killed runs; pushed FIRST (branch + draft PR #8311) before verifying anything, then merged the 1 outstanding origin/main commit and pushed again. Judged both inherited commits on the merits: both hold up. The D7 inertness verdict is now computed caller-free and refused for every caller; the D1 management gate stays system-skipped; the EXISTENCE check correctly stays non-system-only. Fixed the check:engine-double-contract failure the PM relayed by pinning the fake engine's update() to assertEngineUpdateDispatch from metadata-core - NO baseline entry added. All 26 CI checks green at head, including the ESLint job that carried the gate.",
      "merits_judgement": {
        "0c5b42afc": "SOUND. The assertSharingEnforced split is behaviour-preserving on the non-system path: old order was bypass-throws-first, then getSchema-missing-returns, then !schema is NOT_FOUND; the new NOT_FOUND probe is guarded by !bypassObjects.has(object) so a bypass object still yields SHARING_NOT_ENABLED rather than NOT_FOUND. Same verdicts, same precedence. assertSharingEnforced has exactly one caller (the non-system grant path), so nothing else moved. Its central factual claim - that every system caller treats a per-rule throw as best-effort - is real: backfillRuleGrants wraps each evaluateRule in try/catch, warns, continues, and the 'done' line sits outside that loop. Two consequences noted, neither a defect: getSchema is now called twice on the non-system path; and a rule on an inert object aborts reconcile at the first grant so that rule's revoke-stale phase no longer runs (rows an older build minted stay until deleteRule or a deactivated-rule evaluation purges them - no access consequence, those rows are inert by definition, and both withdrawal paths are pinned by the WITHDRAWAL test).",
        "1018d75fb": "SOUND, and its measurement claim is verbatim true (see ratchet_claim_verification). One framing correction made in the PR body rather than the code: the gate is an exact-equality check so it reddens in BOTH directions; 'ticks down only' is the policy for lowering the declared number, not the gate's behaviour. That does not weaken the commit's argument - it strengthens the reason not to convert the siblings here, since banking that progress requires a maintainer editing the declared number."
      },
      "ablation": {
        "method": "Prediction written to disk per-test (not per-total) BEFORE touching production code; restored via git checkout branch -- path, never git stash.",
        "A_revert_sharing_service_to_main": {
          "baseline": "24/24 pass",
          "predicted": "17 FAIL / 7 PASS",
          "actual": "17 FAIL / 7 PASS - failing set matched test-for-test",
          "rows": [
            "refuses a SYSTEM grant on %s (x5 inert classes) | FAIL x5 | FAIL x5",
            "the SYSTEM refusal on %s is the SAME verdict the user path gives (x5) | FAIL x5 | FAIL x5",
            "an engine with NO schema access still cannot answer, for either caller | FAIL | FAIL",
            "evaluating a rule on %s mints NOTHING (x5) | FAIL x5 | FAIL x5",
            "the boot backfill still COMPLETES | FAIL, reconciled 6 not 1 | FAIL: 'expected 6 to be 1'",
            "the code is one the package DECLARES in the ADR-0112 ledger | PASS | PASS",
            "ANTI-VACUITY: a SYSTEM grant on an ordinary private object still succeeds | PASS | PASS",
            "ANTI-VACUITY: the row that system grant wrote is LIVE | PASS | PASS",
            "the D1 MANAGEMENT gate stays system-skipped | PASS | PASS",
            "an UNRESOLVABLE object stays a user-only NOT_FOUND | PASS | PASS",
            "ANTI-VACUITY: the same rule shape on an ordinary object still materialises | PASS | PASS",
            "WITHDRAWAL still works on an inert object | PASS | PASS"
          ],
          "note": "The non-obvious prediction was 'an engine with NO schema access', which fails on its SECOND assertion only, because main's whole-block system skip also bypasses the bypass-object check that needs no schema. Predicted as such, observed as such."
        },
        "B_delete_422_arm_from_rest_server": {
          "baseline": "5/5 pass",
          "predicted": "2 FAIL / 3 PASS",
          "actual": "2 FAIL / 3 PASS",
          "rows": [
            "answers 422 SHARING_NOT_ENABLED | FAIL, falls through to 500 | 'expected 500 to be 422' with body code RULE_EVALUATE_FAILED",
            "the message names the object and survives minus the internal prefix | FAIL on the 2nd assertion ONLY (prefix startsWith flips true); 1st still passes since the 500 body carries the whole message | 'expected true to be false' - the 2nd assertion, exactly as predicted",
            "the code is one the platform DECLARES | PASS | PASS",
            "ANTI-VACUITY: a successful evaluation still answers 200 | PASS | PASS",
            "ANTI-VACUITY: the sibling arms still map to their own statuses | PASS | PASS"
          ]
        }
      },
      "boot_backfill_measurement": {
        "how": "NOT the fake-engine unit test. Re-measured on a real ObjectQL engine + real SqlDriver on sqlite :memory: + real DDL via syncSchemas() + the REAL SysRecordShare/SysSharingRule platform object definitions, driving the real backfillRuleGrants with two real rules (one ordinary, one inert). Scratch harness, run then deleted; not in the diff.",
        "actual_log": [
          "WARN  boot rule backfill failed for rule {rule: share_whiteboard_gold, error: SHARING_NOT_ENABLED: 'whiteboard' is not under record-sharing enforcement (public sharing model or no 'owner_id' field); a share row on it would never be consulted}",
          "INFO  boot rule backfill done {rules: 2, reconciled: 1, ms: 8}",
          "rows minted: [{o: account, r: r1}]"
        ],
        "verdict": "The boot backfill COMPLETES. The inert rule is refused with a reason naming the object, reaches the operator by rule name, and does not stop its sibling; the ordinary rule still materialises its grant.",
        "side_finding": "No shipped example app declares a sharing rule at all, so booting app-showcase cannot reach this log line (backfillRuleGrants only logs when rules.length is above 0). Consistent with the issue's own 'dormant as far as I measured' framing."
      },
      "ratchet_claim_verification": {
        "exists": "YES - scripts/check-route-envelope.mjs, wired as check:route-envelope, declaring siblingCode 69 for packages/rest/src/rest-server.ts.",
        "flat_arm_would_be_new_debt": "CONFIRMED VERBATIM - reverting the arm to the flat dialect reproduces the commit's quoted line exactly: 'siblingCode: found 70, declared 69 - a NEW non-conforming body.'",
        "siblings_genuinely_counted": "CONFIRMED - converting one sibling arm (RULE_NOT_FOUND) onto the shared envelope gives 'siblingCode: found 68, declared 69 - 1 fewer than pinned', proving those arms are inside the 69.",
        "correction_made": "The comment's 'only ticks DOWN' describes the ledger policy, not the gate, which is exact-equality and reddens both ways. Stated in the PR body; the code comment's substance is correct and was left as-is."
      },
      "gates_run": {
        "local": [
          "plugin-sharing full suite: 21 files, 569 passed",
          "rest full suite: 110 files, 1814 passed",
          "typecheck plugin-sharing + rest: pass, both",
          "check:engine-double-contract: pass - 186 pinned, 133 DEBT, 2 exempt",
          "check:route-envelope: pass - stringError 44, siblingCode 69",
          "check:nul-bytes: pass",
          "check:error-code-casing: pass"
        ],
        "ci_at_head_483e4c3b8": "26 check runs, ALL success (Build Docs + Console Pin Gate correctly skipped). ESLint = success (the job that carried the engine-double-contract failure), TypeScript Type Check = success, Check Changeset = success.",
        "skipped_locally": "The remainder of the lint-workflow gate farm (~55 check targets) and the full-workspace build/test - run once by CI, which is now green on all of them at this head."
      },
      "could_not_verify": [
        "A real end-to-end app boot producing the log line: no shipped example app declares a sharing rule, so the line is unreachable from app-showcase. Substituted the real-engine harness above, which is strictly stronger than the committed fake-engine test but is still not a full kernel boot through the kernel:bootstrapped hook.",
        "The write hooks' and the bu-tree re-grant queue's best-effort catch: verified by reading the code (rule-hooks.ts, bu-tree-recompute.ts) and covered by the package's existing 569-test suite, but not independently ablated here. Only the boot backfill path was measured directly.",
        "One pre-existing eslint finding at rest-server.ts:4595 (ban-ts-comment rule not found) reproduces unchanged on origin/main and is an artifact of invoking npx eslint on single files outside the repo lint entrypoint. CI's real ESLint job is green."
      ],
      "notes_for_pm": [
        "GROUND-RULE-2 SURPRISE, not corrected: the platform rewrote/appended the attribution footer on the PR body PATCH - my session-URL footer survived and a bare-form footer was appended after it, so the body now ends with two footers. I did not touch it. Also flagging a standing conflict: the dispatch brief mandates the bare footer form, while my dispatch contract mandates the session-URL form for PR bodies because the bare form is stripped on every later edit. I used the session-URL form in the PR body and the bare form in this comment (where it survives).",
        "Labels on the PR are bot-applied (documentation, size/l, tests, tooling). skip-changeset is NOT applicable - this PR ships a real changeset and is user-visible.",
        "PR is still DRAFT and not armed. I did not flip ready, did not enable auto-merge, did not touch domain labels, and raised no ratchet, ledger or baseline."
      ],
      "tests": "Baselines: plugin-sharing 24/24 on the new file, 569/569 package-wide; rest 5/5 on the new file, 1814/1814 package-wide; typecheck clean on both. Ablation A (revert sharing-service.ts to origin/main): predicted 17 FAIL / 7 PASS, actual 'Tests 17 failed | 7 passed (24)' with the failing set matching test-for-test, e.g. 'AssertionError: expected 6 to be 1' on the boot-backfill case. Ablation B (delete the 422 arm): predicted 2 FAIL / 3 PASS, actual 'Tests 2 failed | 3 passed (5)' with 'expected 422, got 500' and 'expected true to be false'. Both restored via git checkout, tree verified clean. Gates: check:engine-double-contract 'OK - 186 pinned, 133 in the DEBT ledger, 2 exempt'; check:route-envelope 'stringError 44, siblingCode 69'; check:nul-bytes and check:error-code-casing pass. CI at head 483e4c3b8: 26/26 checks success.",
      "open_questions": [],
      "out_of_scope_findings": []
    }

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pm:dispatchedsecurity

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions