← Back to Pull requests

Owner write scope: owner sessions can only write to their own properties and jobs #529

Open
unknown opened this pull request with 304 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 10, 2026 15:43 UTC
Author

What this fixes (class C: login/permissions, needs Brett's yes before merge)


The Oct 14 identity binding stops an owner session from naming another owner's id. It did not stop an owner session from writing to another owner's records. Proven by test/owner-write-scope.test.mjs, which fails 21 of 33 checks on current main:

  • POST /workorder created a job on ANY property_id (that texts the property's tenants/owner), and accepted extra body fields (tenant ids, parent_wo_id, contact phone/name, approval_, recurring_, max_price).

  • /wo/add-note and /wo/append-description only checked ownership when the client said author_role=owner and sent owner_id. A note posted "as a tenant" also texts Brett.

  • /wo/set-tenant-visibility, /log-attachment, /create-upload-session checked nothing.

  • /wishlist/add (Brett's internal dev list) was reachable by owners.
  • The fix


    One gate, ownerWriteScopeDenied, called in the router for owner sessions only (admin secret and internal tokens never reach it):
  • WO-keyed writes must target a job the owner may see (same attachmentScopeAllows the read side uses). Otherwise 404 + failed telemetry row owner_write_scope_denied.

  • /workorder: property must be the owner's, unit must belong to that property, only the fields the owner portal form sends survive, type forced to owner.

  • Identity comes from the session: owner_id forced, author_role forced to owner on notes/descriptions.

  • /wishlist/add refused for owners.

  • Every denial is a 4xx plus a FAILED Ops_Telemetry row (no silent failures).
  • Not changed


    Admin secret behaviour (tested). Tenant and vendor write scopes (same pattern likely worth a follow-up, not touched here). owner.html already sends only the allowed fields and always includes wo_id on uploads.

    Verification


  • New test: 33/33 pass with the fix, 21 fail on main.

  • Branch worker.js byte-identical to the locally tested copy.

  • Full suite runs in CI (not run locally).

  • Not exercised live: a just-created work order's photo upload goes through the same scope check; Sheets read cache is short but could in theory make the first upload 404 (the portal already shows "not saved to the job - try again").

  • BUILD_VERSION bumped to 2026-11-10.01-owner-write-scope; verify deploy via /version.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01EsUqehZV43drizkHs3ePfy

    Diff: 304 lines (+228 / -76) across 3 files Reviewer: github-actions[bot] Review duration: 8m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 304 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.342
    Real PR Conversation Timeline
    1 comments
    "Review active on #529"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.4% · Safe to merge
    21.4%