← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / low / low effort preferred over openai / gpt-6-luna / low / low effort · clear 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

Review the tenant isolation and scanner ingestion security boundary in this [REDACTED: private project name] repository snapshot. Use the named migrations, scanner handler, and RLS tests as your evidence. Identify only concrete vulnerabilities or missing controls supported by these files. For each finding, cite the exact file and policy/function/table, describe a plausible request or actor and the resulting data access or integrity impact, state severity and preconditions, and distinguish proven behavior from assumptions. Examine tenant identity derivation, RLS enforcement, SECURITY DEFINER behavior, service-role use, scanner authentication, and cross-tenant writes where the source permits. Compare each finding with the existing assertions in test-rls.sql; do not claim any test ran. Finish with prioritized findings and minimal regression-test scenarios. Do not edit code.

openai / gpt-6.1-sol / low / low effort answer

## Prioritized findings

Independent, read-only assessment of the supplied snapshot. No tests were run.

### 1. Privileged policy-management function accepts SQL injection
**Severity: High; potentially critical if reachable by an untrusted database/API caller.**

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql:21–47`, function `app.apply_member_policies(text)`:
- Runs as `SECURITY DEFINER`.
- Interpolates caller-controlled `tbl_name` and derived `policy_name` through unquoted `%s` into executable SQL.
- Has no fixed `search_path` or explicit execution restriction in this migration.

For example, this argument makes `policy_name` become `asset` while injecting an additional statement into the table expression:

```text
app.asset; ALTER TABLE app.asset DISABLE ROW LEVEL SECURITY; -- .asset
```

The first generated command becomes a valid policy drop followed by disabling RLS on `app.asset`. Execution occurs with the function owner’s privileges.

`supabase/migrations/00015_hardening.sql:9,13` revokes function privileges from `authenticated`, but does not revoke them from `PUBLIC`. PostgreSQL ordinarily grants new functions `EXECUTE` to `PUBLIC`; an explicit role-level revoke does not remove inherited `PUBLIC` access.

**Actor and impact:** An untrusted caller able to execute this function could disable isolation or execute other owner-authorized SQL, enabling cross-tenant access or corruption where table access is available.

**Preconditions and certainty:** Unsafe SQL construction is proven. Exploit reachability depends on actual function ACLs, function ownership, schema exposure, and any default privileges established outside this packet. The snapshot does not prove a remotely exposed RPC route.

**Existing tests:** `test-rls.sql:124–131` checks that policies exist, not whether an untrusted role can modify or disable them. No function-ACL or injection assertions exist.

**Minimal control:** Remove runtime execution access from `PUBLIC` and untrusted roles; preferably eliminate this migration-only function. Otherwise allowlist tables, quote identifiers correctly, and fix `search_path`.

---

### 2. Scanner ingestion overwrites existing manifest state and repeatedly queues work
**Severity: Medium.**

**Evidence:** `supabase/functions/scanner/index.ts:76–78,85–119`:
- Uses an S3 ETag, or literal `"unknown"`, as `sha256`.
- Upserts on `(tenant_id,sha256)` with `ignoreDuplicates: false`.
- Writes `bundle_uri`, `detected_format`, and `status: "queued"` even on an existing manifest.
- Inserts a fresh parse job after every successful recognized-format upsert.

**Actor and impact:** A legitimate scheduled/manual scan repeated over unchanged objects resets an existing manifest to `queued` and queues additional jobs. An actor able to upload objects into a scanned tenant prefix can cause objects sharing an ETag to target the same manifest: later processing overwrites its URI and format. Objects without ETags all use `"unknown"`.

This undermines manifest identity and ingestion-state integrity. Duplicate jobs and downstream replay are plausible, although parser behavior and actual downstream consequences are outside the packet.

**Preconditions and certainty:** Requires successful access to the intended database tables and the expected conflict constraint. Overwrite and enqueue behavior is explicit. Malicious collision exploitation additionally requires suitable S3 upload capabilities; ordinary repeat scanning does not.

**Existing tests:** `test-rls.sql` contains no scanner, manifest-idempotency, digest-integrity, or job-deduplication assertions.

**Minimal control:** Compute a real content digest, preserve existing processing state on rediscovery, and enforce idempotent job creation.

---

### 3. Scanner authentication fails open when its service key is missing
**Severity: Medium for authentication failure; downstream data impact is conditional.**

**Evidence:** `supabase/functions/scanner/index.ts:20–27` checks:

```ts
authHeader?.includes(Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") || "")
```

When the environment value is missing or empty, every supplied Authorization string includes `""`. An arbitrary header therefore passes the handler’s authorization gate.

**Actor and impact:** A caller reaching the handler with any Authorization header can proceed into request parsing and client initialization despite not possessing a scanner credential.

**Preconditions and certainty:** Requires missing/empty service-key configuration and any upstream gateway admitting the request. The local authentication bypass is proven. Successful S3 listing or database mutation is **not** proven: `createClient` receives the same empty key at lines 40–43 and may reject initialization or fail subsequent operations.

With a configured nonempty key, substring matching is unnecessarily permissive, but it does **not** independently allow a caller who lacks that key to authenticate.

**Existing tests:** No scanner authentication assertions exist.

**Minimal control:** Fail closed on absent configuration and require an exact expected authorization value.

---

### 4. The RLS script does not actually establish tenant isolation
**Severity: Medium assurance gap.**

**Evidence:** `supabase/test-rls.sql`:
- Lines 59–61 call `app.is_member` without establishing User A’s database/JWT identity.
- Lines 140–153 manually filter by tenant, which can conceal missing isolation.
- Lines 175–185 verify membership records rather than querying as User B.
- Lines 222–231 query as service role and merely describe expected user behavior.
- Lines 237–241 query views without testing an outsider or establishing caller identity.
- No assertions fail automatically on unexpected access.

Moreover, `00015_hardening.sql:7–22` removes authenticated base-table access and grants access to **public API views**, whereas the script proposes direct `app.asset` access and tests different `app` views.

**Impact:** A deployment could satisfy the scripted metadata/data checks while unauthorized tenant access remains possible through its real API surface. Conversely, correct hardening could make the proposed direct-table user tests fail with permission errors rather than return filtered rows.

**Certainty:** Missing executable role-specific assertions are proven; an actual view leak is not.

**Minimal control:** Test the final granted API surface under explicit authenticated identities, with positive and negative tenant assertions and automated failures.

## Additional boundary observations

- **Tenant identity:** Scanner `tenant_id` comes directly from the request body (`index.ts:30,89,111`). There is no per-caller tenant binding. However, a correctly authenticated service-role holder is already globally privileged; arbitrary tenant selection alone is not a demonstrated privilege escalation.
- **S3 scope:** The scanner constructs `${tenant_id}/${prefix}` (`index.ts:56`). S3 prefixes are literal strings, not filesystem paths; `../` is not evidence of cross-tenant traversal.
- **RLS/service role:** Migration 00008 enables RLS and applies membership checks to tenant-scoped tables. The scanner uses the service key (`index.ts:40–43`), so these checks should not be treated as a scanner isolation control.
- **Tenant derivation remains unverified:** The implementation of `app.is_member` is outside the packet. Its identity source and resistance to identity spoofing cannot be assessed.
- **Conditional audit-write gap:** `audit_event_insert` (`00008:75–77`) checks only `user_id = auth.uid()`, not membership in the supplied `tenant_id`. If an untrusted caller has INSERT privileges, it can attribute its own event to another tenant, potentially polluting that tenant’s audit stream because `audit_event_select` allows tenant members to read it (`71–73`). Migration 00015 removes direct authenticated table privileges, so this is not a proven reachable authenticated-write vulnerability in the final snapshot.
- **Unproven cross-tenant relationships:** Membership checks cover each row’s `tenant_id`; they do not themselves validate referenced parent tenants. Without table constraints, no concrete cross-tenant foreign-key exploit can be established.
- **Views:** The assertion that views “inherit RLS” (`test-rls.sql:237`) is not sufficient evidence. View ownership, definitions, and security options are outside this packet.

## Minimal regression scenarios, in priority order

1. As an ordinary authenticated database role, attempt `app.apply_member_policies` with both a legitimate table and the injection argument; require denial and unchanged RLS/policies.
2. As two authenticated users belonging to different tenants, query every granted public API view **without tenant filters**; require only each user’s own rows. Verify direct base-table access is denied after hardening.
3. Invoke the scanner with missing configuration, no header, arbitrary header, and an incorrect key; require rejection before S3/database activity.
4. Scan an unchanged object twice; require preserved manifest state and no duplicate parse job.
5. Scan distinct objects sharing an ETag, and objects lacking ETags; require no unintended manifest replacement.
6. If audit insertion is intentionally exposed, attempt an own-user event targeting another tenant; require rejection.

openai / gpt-6-luna / low / low effort answer

## Prioritized findings

1. **Scanner accepts a caller-controlled tenant and prefix, then writes using service-role credentials.**  
   `supabase/functions/scanner/index.ts`, lines 20–22, checks whether the `Authorization` header *contains* the configured service-role key, rather than validating a specific credential format. Lines 29–30 take `tenant_id` and `prefix` directly from the request; lines 56–64 use them to select S3 objects. Lines 40–43 create a Supabase client with the service-role key, and lines 86–119 upsert manifests and insert jobs using the caller-supplied `tenant_id`.

   **Impact / severity:** High if an untrusted caller can invoke the function and obtain or guess a string containing the service-role key; otherwise the key check is a strong precondition and this is not evidence of an unauthenticated exploit. With that precondition, the caller can trigger cross-tenant manifest/job writes and influence which objects are ingested. The code does not verify that the caller is authorized for the requested tenant or that listed object keys belong to that tenant beyond the constructed prefix. Whether this enables access to another tenant’s objects depends on S3 bucket layout and IAM permissions, not shown here.

   **Tests:** `test-rls.sql` describes member/non-member and cross-tenant isolation checks (lines 155–231), but does not exercise the scanner endpoint, its authorization check, or service-role writes. Its stated service-role visibility of both tenants (lines 222–228) highlights that these checks do not establish isolation for this privileged path.

2. **Authorization uses substring matching rather than exact credential validation.**  
   In `supabase/functions/scanner/index.ts`, line 22, `authHeader?.includes(serviceRoleKey)` accepts any header containing the key, not just a precisely formed bearer credential. A caller who knows the key can therefore supply it in an arbitrary header string and pass this check. This is a concrete validation weakness; exploitation still requires access to the secret, and the packet does not establish that it is exposed.

   **Impact / severity:** Medium as a standalone issue; higher when combined with finding 1, because accepted requests execute cross-tenant operations with service-role credentials. The key comparison also treats an unset key as an empty string, so `includes("")` is true for any present `Authorization` header (lines 21–22); whether the environment can lack this secret is unknown.

   **Tests:** `test-rls.sql` has no scanner-authentication assertions.

## RLS and hardening evidence

- `00008_enable_rls_and_policies.sql` enables RLS on all `app` base tables found at migration time (lines 5–18). It creates member-based SELECT and all-operation policies for the listed tenant-scoped tables, including `manifest` and `job` (lines 20–66). The policy expressions call `app.is_member(tenant_id)` (lines 36–46), but the helper’s definition and execution context are outside the supplied evidence; tenant identity derivation and its SECURITY DEFINER behavior therefore cannot be verified from this packet.
- The migration’s `app.apply_member_policies` function is `SECURITY DEFINER` (lines 21–25), but it is a policy-creation helper invoked in the migration (lines 51–66). This evidence alone does not show that ordinary callers can invoke it, nor that it exposes tenant data. `00015_hardening.sql` revokes all function privileges from `authenticated` (lines 7–13), but does not show privileges for other roles or change the function’s definer status.
- `00015_hardening.sql` revokes authenticated-role access to app tables, sequences, and functions and grants authenticated users SELECT only on named public API views (lines 3–22). It does not address the scanner’s service-role client.
- The `tenant_member` policy allows users to read rows whose `user_id = auth.uid()` (00008, lines 86–91). No write policy for that table is shown. `tenant` has a membership-based read policy (lines 79–84). Broader membership-management controls cannot be determined from these files.
- `test-rls.sql` contains useful intended assertions, but explicitly notes that SQL Editor/service-role use cannot impersonate users (lines 55–61, 108–115, 170–185). Its cross-tenant conclusions are descriptions of expected behavior, not executed user-JWT tests (lines 218–231). Do not treat the script as proof that RLS works.

## Minimal regression scenarios

1. Invoke the scanner with a validly authenticated caller authorized for tenant A but request tenant B; assert rejection and no manifest/job writes for B.
2. Test malformed authorization headers containing the secret as a substring, and test behavior when the configured secret is empty; assert rejection.
3. With two tenant users’ JWTs, verify each can read and modify only their tenant’s `manifest` and `job` rows, and verify a non-member cannot access either tenant’s rows. These should be actual authenticated requests, not service-role SQL checks.
4. Verify scanner object listing is constrained to the authenticated/authorized tenant, including attempts to alter `prefix` or use tenant-like path segments.

Primary judge's stated reason

B provides a materially more actionable boundary review: it surfaces a supported privileged SQL-injection mechanism that A leaves unexplored and proposes a corresponding denial-and-policy-integrity regression scenario. Its final-surface RLS scenarios also better match the hardening migration. This supports a clear preference, not merely a forced slight preference, while actual injection reachability and downstream scanner effects remain conditional rather than proven.

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

Battle wave: 49363fb6-15bc-4be1-8f3d-fbf58b9098d4. Pair: brp1_d0e7600c16d2ed669c71f41d0a29cd76b8077e777e88c8ba61b96bf6120d82fe. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.