← Model losses

Head-to-head comparison

openai / gpt-6-astra / high / high 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-astra / high / high effort answer

## Conclusion

Independent static review of the supplied snapshot; no tests were run. The highest-priority issue is a potentially callable `SECURITY DEFINER` function that interpolates attacker-controlled SQL. Other supported findings concern audit-event tenant checks, scanner ingestion integrity, and fail-open authentication under missing configuration.

### 1. High — SQL injection in privileged policy-management function

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql`, `app.apply_member_policies(text)`, lines 21–46; `supabase/migrations/00015_hardening.sql`, lines 4–13.

The function runs as `SECURITY DEFINER` and interpolates both its argument and a derived policy name using unquoted `%s`. A caller able to execute it can supply additional SQL.

For example, this argument preserves a simple derived policy name, `x`, while injecting additional statements:

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

The first generated command becomes:

```sql
drop policy if exists r_x_select on app.asset;
ALTER TABLE app.asset DISABLE ROW LEVEL SECURITY;
GRANT SELECT ON app.asset TO authenticated;
-- ...
```

**Actor and impact:** An authenticated actor with a route to invoke the function could execute SQL with its owner’s privileges, disable asset RLS, and restore table access, exposing other tenants’ assets. Broader modification depends on the function owner’s privileges.

**Preconditions and confidence:** High confidence in the injection mechanism. Invocation requires effective `EXECUTE` permission and a reachable SQL/RPC interface. PostgreSQL normally grants new functions `EXECUTE` to `PUBLIC`; migration 00015 revokes privileges from `authenticated`, **not `PUBLIC`**, and explicitly retains authenticated schema usage. Consequently, the displayed hardening does not remove that default execution path. Earlier default-privilege changes, actual ACLs, API schema exposure, and function ownership are not established by this packet.

**Existing tests:** `test-rls.sql:116–131` checks RLS flags and policy existence, not helper execution permissions or injection. The service-role query at lines 222–231 cannot demonstrate resistance to this attack.

**Minimal correction:** Remove runtime access to this administrative helper, including `PUBLIC` execution. If retained, allowlist target tables and safely quote identifiers.

### 2. Medium, conditional — Audit inserts do not require membership in the destination tenant

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql`, `app.audit_event` policies, lines 71–77.

`audit_event_insert` checks only:

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

It does not check membership in `tenant_id`. Meanwhile, `audit_event_select` lets destination-tenant members read the inserted event.

**Actor and impact:** A user with effective `INSERT` access could submit an event using their own user ID and another tenant’s ID. If accepted by table constraints, this contaminates that tenant’s audit history with an outsider-generated event. It does not prove impersonation of another user.

**Preconditions and confidence:** The policy omission is proven. Exploitation requires effective table privileges and compatible constraints. Migration 00015 revokes authenticated table privileges, so this is a **latent policy defect**, not a demonstrated ordinary-authenticated write path after hardening. Other grants and audit-table constraints are outside the packet.

**Existing tests:** `test-rls.sql` contains no audit-event insertion or visibility checks. Its cross-tenant section tests only asset fixtures and a privileged read.

**Minimal correction:** Require destination-tenant membership for user-submitted events, or restrict audit creation to a trusted producer that derives tenant identity.

### 3. Medium — Scanner does not preserve content-hash integrity or ingestion idempotency

**Evidence:** `supabase/functions/scanner/index.ts`, lines 74–78, 85–119.

Two concrete behaviors undermine ingestion integrity:

- The value stored as `sha256` is an S3 ETag, or the shared fallback `"unknown"`. The handler never downloads or hashes the object.
- Every successful upsert sets `status: "queued"` and every recognized-format result causes a new parse-job insertion, including existing manifests.

**Actor and impact:**

- A repeated authorized scan of the same object can reset an existing manifest to queued and create additional parse jobs.
- A producer able to place objects under a scanned tenant prefix can cause distinct object URIs sharing an ETag to target the same `(tenant_id, sha256)` manifest. Identical bytes at different keys are sufficient to encounter this conflict; no cryptographic attack is required. A successful upsert replaces the manifest URI, potentially leaving earlier queued jobs carrying a different URI for the same manifest ID.
- If the storage provider omits ETags, all such objects within a tenant receive `"unknown"` and share the conflict key.

**Preconditions and confidence:** These are explicit handler behaviors, conditional on successful database operations and the expected conflict constraint. Actual parser outcomes, additional database controls, and whether downstream code treats the field as verified SHA-256 are unknown. This supports ingestion-integrity and duplicate-work findings, not a proven cross-tenant read.

**Existing tests:** `test-rls.sql:67–102` creates asset/survey/observation fixtures; it does not exercise scanner-created manifests, jobs, hashes, or repeated scans.

**Minimal correction:** Compute the advertised digest, define explicit handling for multiple URIs with identical content, and enqueue work only through an idempotent state transition.

### 4. Low — Scanner authentication fails open when the configured secret is empty

**Evidence:** `supabase/functions/scanner/index.ts`, lines 20–27 and 39–43.

The authorization condition uses:

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

When the environment variable is missing or empty, any present Authorization header passes because every string contains `""`.

**Actor and impact:** A requester sending an arbitrary Authorization header passes this handler’s authentication gate under that configuration.

**Preconditions and confidence:** The gate bypass is proven; successful unauthorized ingestion is **not**. The same absent secret is supplied to `createClient`, so client initialization or database authorization may subsequently fail. Upstream gateway authentication is also unspecified. With a nonempty secret, substring matching is unnecessarily permissive but does not demonstrate that an attacker can authenticate without knowing the secret.

**Existing tests:** `test-rls.sql` contains no scanner authentication tests.

**Minimal correction:** Reject missing configuration before handling requests and compare against the exact expected authorization value.

## Tenant-boundary conclusions and limits

- **Tenant identity:** The RLS policies delegate membership to `app.is_member(tenant_id)`. Its implementation is not supplied, so its identity derivation, membership lookup, and execution context cannot be verified. Audit and membership-read policies explicitly use `auth.uid()`.
- **Scanner authority:** The scanner derives `tenant_id` from the request body and uses the service-role key (`index.ts:30,39–43,89,111`). It therefore performs privileged, caller-selected tenant writes rather than relying on end-user RLS. With the required secret correctly configured, this is a global administrative interface; arbitrary tenant selection by its authorized caller is not independently a tenant-isolation exploit.
- **S3 prefix:** `${tenant_id}/${prefix}` supplies a literal S3 key prefix (`index.ts:56–61`). These files do not support a filesystem-style `../` traversal claim.
- **Cross-tenant references:** Standard member policies check each row’s `tenant_id`, not referenced rows’ tenants (`00008:38–45`). Without foreign-key and table definitions, inconsistent survey/asset or observation/survey tenant links cannot be established as accepted writes.
- **Views:** Migration 00015 grants access to five `public.api_*` views. Their security behavior is not established here. The comment that views “should inherit RLS” in `test-rls.sql:237` is not proof; view ownership and security options matter.

## Prioritized regression scenarios

The existing script is a manual checklist, not executable proof of isolation. It does not switch database roles or JWT identities; its outsider check evaluates membership, and its two-tenant asset query explicitly runs privileged (`test-rls.sql:156–231`). After migration 00015, direct authenticated base-table queries may correctly fail for lack of privileges rather than return filtered rows.

1. **Privileged helper:** Verify effective execution permissions for `PUBLIC`, `anon`, and `authenticated`; ensure untrusted invocation and injected arguments are rejected without policy, ACL, or data changes.
2. **Actual tenant identities:** Under real non-bypass identities for two tenants, verify permitted API-view reads and forbidden cross-tenant access. Verify direct base-table access matches the hardened privilege model.
3. **Audit writes:** Attempt an own-user-ID/victim-tenant-ID insert through every intended write route; require rejection and no victim-visible event.
4. **Scanner integrity:** Scan one object twice; require stable completed state and at most one active parse job. Exercise identical-content/different-key objects and missing ETags.
5. **Scanner authentication:** Test absent, empty, incorrect, substring-containing, and exact credentials, including missing server configuration; unauthorized cases must fail before storage or database work.

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 better-supported remediation priority: investigate and restrict the injectable privileged helper rather than treating possession of an already-global credential as a separate tenant authorization exploit. Its additional conditional audit-write analysis and regression scenarios improve coverage of the requested boundary. This is a clear comparative advantage, not a slight forced preference, although exploitation in the deployed environment remains unproven.

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