← Model losses

Head-to-head comparison

openai / gpt-6.1-sol / xhigh / xhigh 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 / xhigh / xhigh effort answer

## Conclusion

The strongest finding is **SQL injection in a `SECURITY DEFINER` policy-management function**, potentially allowing an authenticated caller to disable RLS and grant cross-tenant access. Its reachability depends on function privileges and API exposure.

This was an independent, read-only review of the supplied snapshot. **No tests were executed.**

## Boundary assessment and uncertainties

- Standard policies check membership for both existing and replacement rows: `USING (app.is_member(tenant_id)) WITH CHECK (app.is_member(tenant_id))` in `supabase/migrations/00008_enable_rls_and_policies.sql:36–45`. The implementation of `app.is_member` is outside the packet, so its identity derivation cannot be verified.
- `supabase/migrations/00015_hardening.sql:4–22` removes direct `authenticated` privileges on `app` tables and instead grants reads on five `public.api_*` views. Those view definitions are not supplied; **view-based RLS bypass is not proven**. The assertion that views automatically inherit RLS in `supabase/test-rls.sql:237` is insufficient—ordinary PostgreSQL views can use their owner’s privileges.
- Scanner tenant identity comes directly from request JSON, not a JWT or membership lookup: `supabase/functions/scanner/index.ts:30,56,89,111`. The database client uses the service-role key at lines 39–43, normally bypassing RLS. This is a global administrative ingestion interface, not a tenant-scoped one. **Selecting another tenant while holding that global key is not independently an authorization vulnerability**: the credential already grants broad authority.
- S3 prefixes are literal strings; `../` does not establish filesystem-style traversal. Cross-tenant relationship corruption through foreign asset/survey identifiers also cannot be established without the relevant constraints.

## Prioritized findings

### 1. Critical, conditional: injectable privileged policy helper

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql:21–46`, function `app.apply_member_policies(text)`.

The function runs as `SECURITY DEFINER` and interpolates caller-controlled text into SQL using unquoted `%s`, both as a policy-name fragment and as a relation expression.

A representative argument is:

```text
app.asset; ALTER TABLE app.asset DISABLE ROW LEVEL SECURITY; GRANT SELECT ON app.asset TO authenticated; --.asset
```

The final `.asset` makes the extracted policy-name fragment `asset`; the preceding commands remain in the relation expression. The comment suppresses the generated suffix. This permits additional commands in the function owner’s privilege context.

**Actor and impact:** An authenticated caller able to execute this function could disable RLS on `app.asset` and restore `SELECT`, exposing assets from every tenant. The injected grant also defeats the table-privilege restriction introduced by hardening.

**Preconditions and confidence:**
- PostgreSQL normally grants new functions `EXECUTE` to `PUBLIC`.
- `supabase/migrations/00015_hardening.sql:9,13` revokes privileges from `authenticated`, **not `PUBLIC`**; line 5 grants authenticated schema usage.
- Thus the shown hardening does not close default PUBLIC execution. Actual inherited ACLs and whether `app` RPCs are exposed are not supplied.
- The function owner must possess the relevant table privileges; the migration’s legitimate policy-creation calls already require substantial ownership authority.

**Confidence:** High in the injection defect; conditional in externally reachable exploitation.

**Existing tests:** `supabase/test-rls.sql:124–131` checks policy existence only. No assertion tests this helper’s execution permissions, hostile arguments, privilege changes, or RLS disabling.

**Minimal fix:** Restrict execution to a migration/admin role, revoke PUBLIC execution explicitly, and accept only allowlisted, correctly quoted identifiers.

### 2. Medium: scanner can overwrite manifest provenance and replay ingestion

**Evidence:** `supabase/functions/scanner/index.ts:76–99,106–119`, writes to `manifest` and `job`.

The scanner substitutes an S3 ETag—or the constant `"unknown"`—for `sha256`. It then performs an updating upsert on `(tenant_id,sha256)`, replacing `bundle_uri`, format and status with `"queued"`, and attempts another parse-job insertion.

**Actor and impact:** An actor who can place objects under a tenant’s scanned prefix can influence ingestion during a legitimate scheduled scan. Two objects producing the same selected value can target the same manifest and replace its source URI. Independently, rescanning an unchanged object attempts to reset its manifest to queued and enqueue parsing again.

**Preconditions and limits:**
- Database constraints must accept these values and permit the conflict update.
- Missing ETags cause deterministic `"unknown"` collisions if such responses occur.
- Distinct-content ETag collisions depend on the storage backend; no specific ETag algorithm is proven here.
- Duplicate jobs may be prevented by an unseen database constraint, but the handler unconditionally attempts insertion.
- The conflict key includes `tenant_id`; **this is not a demonstrated cross-tenant hash collision**.

**Confidence:** High in the overwrite/replay behavior attempted by the handler; conditional in database acceptance and downstream impact.

**Existing tests:** `supabase/test-rls.sql:67–102` creates asset/survey/observation fixtures. It contains no manifest, job, hash-integrity, collision or rescan assertions.

**Minimal fix:** Compute a real content hash, avoid unconditional mutation of existing manifests, and enqueue work idempotently.

### 3. Medium, latent: audit inserts do not require tenant membership

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql:71–77`, policies `audit_event_select` and `audit_event_insert` on `app.audit_event`.

The insert policy requires only:

```sql
user_id = auth.uid()
```

It does not require membership in the supplied `tenant_id`.

**Actor and impact:** A non-bypass user with effective `INSERT` permission could submit an event attributed to themselves under another tenant’s ID. RLS would accept that row, potentially polluting the other tenant’s audit stream. Its members can read the event through `audit_event_select`.

**Preconditions and limits:** The hardening migration explicitly revokes authenticated table privileges. Consequently, **ordinary authenticated insertion is blocked by that layer as shown**. This is a concrete policy-level gap, not a proven currently accessible endpoint; exploitation requires an effective insert grant and no additional enforcing constraint.

**Confidence:** High in the missing membership check; conditional in exploitability.

**Existing tests:** No audit-event policy assertions appear in `supabase/test-rls.sql`; the policy inspection at lines 124–129 covers only asset, survey and observation.

**Minimal fix:** Require both self-attribution and tenant membership for ordinary user inserts.

### 4. Low: scanner authentication fails open when its secret is unset

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

The authorization predicate becomes `authHeader.includes("")` when `SUPABASE_SERVICE_ROLE_KEY` is absent or empty. Any present Authorization header then passes the guard.

**Actor and impact:** A caller without the service key can cross the handler’s authentication check during this configuration failure.

**Preconditions and limits:** The same empty key is passed to `createClient` at lines 40–43. Client initialization or subsequent database access may fail. **Successful unauthenticated ingestion or service-role access is not established.** With a nonempty secret, substring matching still requires possession of the entire secret; it is not a demonstrated keyless bypass.

**Confidence:** High in the guard defect; downstream impact unproven.

**Existing tests:** `supabase/test-rls.sql` does not exercise scanner authentication or configuration failures.

**Minimal fix:** Fail closed on missing configuration and validate the exact intended authorization format.

## Minimal regression-test scenarios

1. **Privileged helper:** As the real authenticated role, verify `app.apply_member_policies` cannot execute, including through PUBLIC privileges. In an isolated database, test hostile arguments and assert unchanged policies, RLS flags and grants.
2. **Actual tenant isolation:** Use distinct A/B JWTs and unfiltered queries against every granted `public.api_*` view. Assert each sees only its tenant. Verify direct `app` access is denied under the hardened privilege model.
3. **Audit policy:** Test self-attributed inserts for an owned and foreign tenant using a narrowly privileged, non-bypass test role. Foreign-tenant insertion must fail.
4. **Scanner authentication:** Test absent/empty server secrets, absent headers, invalid credentials and malformed headers. Failure must occur before storage or database work.
5. **Ingestion integrity:** Scan twice; assert stable manifest provenance and no unintended requeue. Test missing/repeated ETags across different objects and identical hashes across two tenants.

The existing script mostly checks fixtures and catalog state using privileged SQL. It explicitly acknowledges this limitation at `supabase/test-rls.sql:113–114,175–176,222–231`; its comments are not executed isolation assertions.

MATERIAL_EVIDENCE_CONFLICT: `supabase/migrations/00015_hardening.sql:7–22` removes authenticated app-table privileges and grants public API-view reads, while `supabase/test-rls.sql:170–173,276–283` expects authenticated direct `app.asset` queries to succeed with RLS-filtered results.

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 useful security review: it identifies a supported privileged injection mechanism missed by A, connects it to the hardening migration, and proposes regression checks for execution privileges and unchanged RLS state. It also avoids treating possession of a global administrative credential as an independent tenant-isolation bypass. This supports a clear preference, rather than a slight forced preference, while actual deployment exploitability remains uncertain.

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_d57f4f543497948af23bf88f8460585755ae044c890affbb79ed48d4c7a81fd6. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.