← Model losses

Head-to-head comparison

deepseek / deepseek-flash / none / unknown effort preferred over cursor / composer-2.5 / Composer 2.5 default / unknown effort · close win.

Primary judge: Sol 6.1, requested Low. Effective provider effort and internal attempts were not verified. A close win is still a scored preference; it does not establish a material defect.

Reviewed public evidence

Task goal

Perform a source-grounded authorization and tenant-isolation review of review-pack access and worker-job token boundaries. Identify only a concrete cross-tenant, unauthorized-read/write, or token-confusion path supported by the code; give required preconditions, affected data/action, minimal mitigation, and regression coverage. Do not infer exploitability from names alone.

deepseek / deepseek-flash / none / unknown effort answer

I'll analyze the three files for concrete cross-tenant, unauthorized read/write, or token-confusion paths.

## Analysis

### Scope and trust boundaries in the packet

The worker-job token fence (`worker_job_tokens.py`) is defense-in-depth layered: token `type`, `scp` allowlist, path/method allowlist, live job-state check, immutable resource-binding snapshot comparison, and per-request tenant/resource pinning via `request.state`. The `review_pack.py` router uses `get_media_user`/`require_role`/`require_scope`/`TenantScope` and `_get_inspection(...)` which scopes by `Asset.municipality_id == scope.own_org_id`. I cannot see `deps.py`, `jwt.py`, `scopes.py`, `roles.py`, or the `TenantScope`/`get_media_tenant_scope` implementations, so I cannot verify that the worker-token state pinning is actually *consumed* by tenant resolution — that is a named missing dependency, and it is the central question this packet alone cannot close.

I checked each candidate path:

**1. Worker-token shape vs. `enforce_worker_job_municipality` guards (token-confusion / cross-tenant)**
`validate_worker_job_request` pins `request.state.worker_job_municipality_id` (line 301), and `enforce_worker_job_municipality` (309-321) and `enforce_worker_job_resource` (324-364) exist to reject cross-tenant/cross-resource access. **However, none of the allowlisted routes in `_ALLOWED_ROUTES` (78-94) exist in `review_pack.py`** — they are `/api/v1/observations`, `/api/v1/inspections/{id}`, and `/api/v1/profile-bank/*`, none of which are in this file. So within this snapshot I cannot observe whether the call sites actually invoke `enforce_worker_job_municipality`/`enforce_worker_job_resource`/`enforce_worker_job_baseline`. Those functions are exported (`__all__`, 403-410) but the enforcement is conditional on callers in files *outside the packet*. **This is the highest-value unverifiable path and a named dependency gap**, not an established defect.

**2. `review_pack.py` tenant scoping — no defect established in-packet**
Every data-touching handler calls `_get_inspection(...)` first (e.g. 1923, 2039, 2696, 2738, 2841, 2914, 3066, 3297, 3331, 3452, 3788, 3997, 4054), which filters `Asset.municipality_id == scope.own_org_id`. Media/observation child queries are additionally filtered by `scope.own_org_id` or `inspection.municipality_id` (1926-1932, 2972-2976, 3072-3081, 3344-3351, 3397-3407, 3456-3465). Write endpoints additionally require `require_role(*WRITE_ROLES)` and `require_scope("inspections:write")`. `backfill_prescan_scores` is gated by `require_role(*DELETE_ROLES)` and scopes by `scope.own_org_id` (3650-3662). I found no endpoint that reaches tenant data without a prior scoped `_get_inspection`.

**3. Cross-inspection (same-tenant) path injection — mitigated by pack confinement**
`serve_review_pack_file` (4036) builds `f"{pack_key}/{file_path}"` from the *inspection's own* `review_pack_path`; `_validate_path` blocks absolute/`..`; `_is_[REDACTED: private constant]` blocks `certification/*`. `_confine_to_pack_tenant` (1194-1208) constrains manifest-authored `video_path` to the same `pack_parts[:2]` tenant root before storage access (2660-2666). The `_confine_to_pack_tenant` prefix check is string-based: a sibling key sharing the first two segments (e.g. `review-packs/7/…` vs a key under another inspection of the same municipality that also starts with `review-packs/7/`) would pass. This is a *same-tenant* concern, not cross-tenant, and requires an attacker-controlled manifest — precondition not established in-packet. Not a cross-tenant path.

**4. `review_boot.py`**
`stamp_review_boot` / `persist_review_boot_*` operate only on `Inspection.id` by primary key and write derived fields (`review_boot_json`, `review_boot_pack_sha256`). No tenant check is performed *here*, but this is an internal service taking an explicit `inspection_id` from its caller (the ingest path), not a request-authenticated boundary. `_BOOT_OMIT_CARD_KEYS` and the docstring (4-6) show the payload deliberately omits certification/imagery/observation fields. No cross-tenant path is demonstrable from this file alone, since it has no auth surface and no tenant parameter to confuse. Its safety depends on the caller passing the correct `inspection_id`, which is outside the packet.

**5. `_resolve_nearest_fps_frame_key` / in-progress fallbacks**
In-progress handlers (2317, 2396) select jobs by `MediaFile.inspection_id == inspection_id` and `status in (pending/running/completed)` with no explicit `municipality_id` on the job query (2353-2374, 2446-2466), but the inspection was already scoped, and the job is joined transitively through the scoped media file. `output_path` is used only as a storage prefix under the pack the user can already read. No cross-tenant read is established.

### Conclusion

Within the supplied snapshot I **cannot establish a concrete cross-tenant, unauthorized-read/write, or token-confusion path**. The worker-token fence is comprehensive and fails closed at each observed step (203, 205, 213, 260, 274, 276, 282, 289-295). The strongest residual risks are structural, not demonstrated:

- **Unverified consumer enforcement (highest uncertainty).** The three `enforce_worker_job_*` helpers are defined and exported but have no observable call sites inside the packet. If a worker-allowlisted consumer endpoint (all outside the packet) omits `enforce_worker_job_municipality`/`enforce_worker_job_resource` for a body/query tenant or resource identifier, a `worker_job` token whose `sub` is a real uploader could reach data beyond its job's tenant/resource. This is a *dependency gap*, not a proven bug.
- **`enforce_worker_job_baseline` string comparison (394-396)** compares `str()` of municipality/inspection/pipe/video-hash; `None` vs `"None"`-style collisions or `"1"` vs `"1"` across numeric/string types are conceivable but not demonstrable with the packet.
- **`_confine_to_pack_tenant` (1204-1208)** shares the first two path segments as the tenant root; only same-tenant sibling access, and only with manifest control.

### Minimal mitigation (if consumer enforcement is confirmed absent)
Ensure every worker-allowlisted route that accepts a tenant, inspection, media, pipe, video-hash, or baseline identifier calls the matching `enforce_worker_job_*` before touching tenant-owned data, and that `deps._resolve_jwt_user` sets `request.state` for `type == "worker_job"` while *replacing* (not merging) any uploader role/view-as/`X-Active-Org-Id`-derived scope.

### Regression coverage
1. A `worker_job` token for job J in municipality A calling an allowlisted consumer endpoint naming municipality/inspection B must return 403 (exercises `enforce_worker_job_municipality`).
2. Same token supplying a `media_file_id`/`pipe_id`/`video_hash` outside J's binding snapshot must return 403 (`enforce_worker_job_resource`).
3. A baseline/pipe id from another inspection/tenant must return 403 (`enforce_worker_job_baseline`).
4. A `worker_job` token against a non-allowlisted route (e.g. `GET /api/v1/inspections` list) must return 403 before user resolution.
5. A `worker_job` token after the job is `completed`/`failed`/`cancelled`, or after `media_file_id`/`inspection_id` changes, must return 401/403.
6. An ordinary `access` token with uploader role must not inherit worker-job resource pinning (confirm `enforce_worker_job_*` no-ops when `request.state.worker_job_id` is unset), and a `worker_job` token must not gain uploader/admin scope.

**Discarded hypotheses / likely false positives:** (a) cross-tenant read via `/{inspection_id}/...` routes — falsified by scoped `_get_inspection`; (b) `file_path` traversal — falsified by `_validate_path` + private-path block; (c) cross-tenant via manifest `video_path` — falsified cross-tenant by `_confine_to_pack_tenant`; (d) `review_boot.py` as a boundary — it has no request auth surface, so no token confusion is possible in this file.

**Missing evidence / dependencies and consequence:** `app/deps.py`, `app/auth/jwt.py`, `app/auth/scopes.py`, and the worker-allowlisted consumer routers are outside the packet. *Consequence:* I can confirm the fence is correctly *constructed* but cannot confirm it is *enforced* at the consumer call sites — that is precisely where a token-confusion/cross-tenant defect would have to live.

**Next useful action:** Obtain and read the allowlisted consumer endpoints (`/api/v1/observations`, `/api/v1/inspections/{id}`, `/api/v1/profile-bank/*`) plus `deps._resolve_jwt_user` and `get_tenant_scope`/`get_media_tenant_scope`, then verify each tenant/resource-taking call site invokes the corresponding `enforce_worker_job_*` helper and that worker-token state overrides (rather than merges with) uploader/view-as scope.

MATERIAL_EVIDENCE_CONFLICT: `worker_job_tokens.py` exports and documents tenant/resource enforcement helpers intended to run on every worker request (309-364, 397-400), yet none of the `_ALLOWED_ROUTES` they protect (78-94) appear in `review_pack.py`, so within the packet the helpers have no observable enforcement call sites.

cursor / composer-2.5 / Composer 2.5 default / unknown effort answer

## Evidence packet: review-pack access and worker-job token boundaries

### 1. Conclusion (primary finding)

**Finding:** Progressive / in-progress review-pack reads use `ProcessingJob.output_path` as the storage root **without** tying that path to the request tenant (or to the inspection’s municipality), unlike manifest `video_path` handling which uses `_confine_to_pack_tenant`.

**Confidence:** High that the authorization gap exists in the admitted snapshot; medium that it becomes **cross-tenant** in production (depends on who can set `output_path`).

**Locations (packet):**

- `serve_in_progress_file`: resolves `pack_key` from `job.output_path`, then `file_key = f"{job.output_path}/{file_path}"` and serves via storage (approx. lines 2445–2475 in `review_pack.py`).
- `serve_review_pack_file`: when `inspection.review_pack_path` is empty, selects a `ProcessingJob` by `media_file_id` only (no `ProcessingJob.municipality_id` / path check), sets `pack_key = job.output_path`, then serves `f"{pack_key}/{file_path}"` (approx. 4073–4121, 4094–4096).
- Same pattern in `get_in_progress_fps_count` (`fps_prefix = f"{job.output_path}/fps"`, approx. 2378).
- Contrast: `serve_review_pack_video` confines manifest `video_path` with `_confine_to_pack_tenant(video_path_str, pack_key)` before `storage.get_response` (approx. 2656–2666).
- `_confine_to_pack_tenant` itself only checks shared **first two** path segments with `pack_key` (approx. 1194–1208); it is **not** applied to `job.output_path`.

**Preconditions:**

1. Caller passes normal review-pack auth: `get_media_user` + `get_media_tenant_scope` and `_get_inspection(inspection_id, …, scope)` (tenant-scoped inspection).
2. Pack is read through the in-progress path (`review_pack_path` empty or in-progress route), and a `ProcessingJob` row is selected for the inspection’s video `media_file_id`.
3. That job’s `output_path` points at storage under another tenant’s prefix (e.g. `review-packs/{other_municipality_id}/…` or another org’s `media/{slug}/…`). The packet does not show how `output_path` is written; any path that can set it (worker, job completion, ops/DB) satisfies this.

**Affected data / action:**

- **Unauthorized read** of arbitrary objects under `{output_path}/{file_path}` for allowed relative paths (in-progress: `fps/`, `modules/observations/`; generic catch-all route allows broader `file_path` once `pack_key` is set), including pack JSON, frames, and observation module assets—potentially **another municipality’s** review-pack tree if `output_path` is cross-tenant.

**Minimal mitigation:**

- Before using `job.output_path` as `pack_key`, enforce tenant ownership, e.g.:
  - `ProcessingJob.municipality_id == scope.own_org_id` (and/or match inspection’s municipality), **and**
  - `output_path` matches an expected namespace for that municipality (extend `_confine_to_pack_tenant` or a dedicated `review-packs/{municipality_id}/` / org storage root check), **or**
  - reject if `output_path` does not share the tenant root derived from `scope.own_org_id` / org storage config.
- Mirror the manifest `video_path` pattern (2656–2660) for all job-derived pack roots.

**Regression coverage:**

- Fixture: tenant A inspection + media + active `review_pack` job whose `output_path` is tenant B’s pack prefix; object exists only under B.
- Assert `GET /review-pack/{inspection_id}/in-progress/fps/...` and `GET /review-pack/{inspection_id}/{file}` (with empty `review_pack_path`) return **403 or 404**, not B’s bytes.
- Control: same job with `output_path` under A’s prefix succeeds.
- Optional: assert `ProcessingJob.municipality_id` mismatch fails even if path string looks valid.

---

### 2. Alternatives / discarded hypotheses

| Hypothesis | Verdict in packet |
|------------|-------------------|
| Worker `worker_job` JWT can call `/review-pack/*` | **Rejected:** `validate_worker_job_request` allowlist has no `/review-pack` routes (worker_job_tokens.py 78–93); non-matching path → 403 before DB job binding. |
| Manifest `video_path` cross-tenant via `serve_review_pack_video` | **Mitigated in packet:** `_confine_to_pack_tenant` before direct `video_path` storage read (2656–2660). |
| `review_boot` cross-tenant write | **Uncertain:** `stamp_review_boot` / `persist_review_boot_from_bytes` load `Inspection` by `inspection_id` only (review_boot.py 170–171, 196–197); no `municipality_id` check in this file—exploitability depends on callers (not in packet). |
| Worker token cross-inspection IDOR on `GET /api/v1/inspections/{id}` | **Uncertain:** Token pins `worker_job_inspection_id` on `request.state` (worker_job_tokens.py 303–304); whether the inspections router enforces `enforce_worker_job_resource(..., inspection_id=…)` is **outside** the packet (`app/routers` not admitted). Same-tenant unauthorized read possible if missing; not proven here. |
| Legacy pre-D8 `access` tokens in `processing_config["api_token"]` | **Documented risk** (worker_job_tokens.py 44–47): full user impersonation until expiry—not cross-tenant by itself; token-type confusion with new `worker_job` fence. |

---

### 3. Missing evidence / consequences

- **`deps._resolve_jwt_user`**, inspections/observations/profile-bank routers: whether `enforce_worker_job_resource` / `enforce_worker_job_municipality` cover every allowlisted worker route (consequence: same-tenant IDOR or org-id confusion on `GET .../organizations/{id}/profile-bank/stats`).
- **Job claim / complete** (`worker_queue.py`): how `output_path` and `_worker_job_resource_binding_v1` are set (consequence: how easily precondition #3 is met).
- **RLS / `get_media_tenant_scope`**: whether DB alone prevents cross-tenant `ProcessingJob` rows on media (consequence: whether path confinement is defense-in-depth vs primary control).

---

### 4. Next useful action

Add tenant + storage-root validation on every use of `ProcessingJob.output_path` in `review_pack.py` (in-progress file, fps-count, progressive `serve_review_pack_file` fallback), aligned with `_confine_to_pack_tenant` / `municipality_id`, and land the regression tests above.

**Worker-job fence (in packet):** Path allowlist, job/tenant/resource snapshot checks, and `request.state` pinning (worker_job_tokens.py 181–305) are coherent for admitted worker routes; the clearest **review-pack + tenant** gap in this snapshot is **unconfined `job.output_path`**, not worker JWT access to `/review-pack/*`.

Primary judge's stated reason

Forced, weak preference for A because its ultimate no-established-exploit conclusion better matches the task's evidence threshold. B offers the stronger actionable investigation of output_path, while A's dismissal and conflict marker weaken its assurance. This is not an established material quality gap; an independent review could reasonably prefer B's explicitly conditional analysis.

This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.

Battle wave: 527c366a-0a3f-41a8-8ff5-f886f8eadb49. Pair: brp1_c0881db166c3aea4feb90b12e4569de4279cc94fd838d478a580681f364d0d60. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.