← Model losses

Head-to-head comparison

openai / gpt-6-astra / high / high effort preferred over openai / gpt-6.1-sol / xhigh / xhigh 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

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.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.

Primary judge's stated reason

B has a slight practical advantage in explaining how ordinary duplicate-content objects can replace manifest provenance and create inconsistent queued references, helping readers design a targeted regression scenario. This is a forced, weak preference, not an established material quality gap; an independent review could reasonably reject it.

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