← 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

## Conclusion

Independent, read-only review of the supplied snapshot found one potentially critical privileged-function exposure, two scanner integrity/authentication defects, and an audit-policy tenant-binding gap. Exploitability depends on privileges, gateway configuration, and constraints not shown here. **No tests were run.**

### 1. Privileged policy helper accepts SQL injection; hardening does not revoke PUBLIC execution
**Severity: Critical if callable by an untrusted role; confidence: high in the defect, conditional in reachability.**

**Evidence**
- `supabase/migrations/00008_enable_rls_and_policies.sql:21–47`, function `app.apply_member_policies(text)`, is `SECURITY DEFINER`.
- Lines 33–45 interpolate caller-controlled `tbl_name` and derived `policy_name` into executable SQL using unquoted `%s`.
- `supabase/migrations/00015_hardening.sql:9,13` revokes function privileges from `authenticated`, **not `PUBLIC`**. Line 5 preserves authenticated schema usage.

**Actor and impact:** If PostgreSQL’s default PUBLIC function-execution grant remains, an authenticated database/API caller able to invoke this function can supply SQL syntax rather than a table name. Statements execute with the function owner’s authority, potentially altering policies or other objects and defeating tenant isolation.

**Proven versus conditional:** Unsafe privileged SQL construction is proven. PostgreSQL normally grants new functions EXECUTE to PUBLIC; the snapshot does not establish whether another migration changed defaults or revoked that grant. Owner privileges and RPC exposure also are not shown. Even without injection, arbitrary caller-selected policy targets are an unsafe administrative capability.

**Existing tests:** `test-rls.sql:124–131` checks policy existence only; no test checks helper execution privileges, malicious arguments, or preservation of policies after an untrusted call.

**Minimal regression:** As the actual authenticated role, verify EXECUTE is denied on this helper. In a disposable database, verify malformed/malicious table arguments cannot execute additional SQL or change policies. Remove runtime access to this migration helper, or strictly validate and quote identifiers.

### 2. Scanner authentication fails open when its secret is absent or empty
**Severity: Medium, configuration-dependent; confidence: high.**

**Evidence:** `supabase/functions/scanner/index.ts:20–27` tests:
```ts
authHeader?.includes(Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") || "")
```
Every present string includes `""`.

**Actor and impact:** If the service-role secret is absent/empty and the request reaches the handler, any Authorization header passes its local authentication check. The caller controls the requested tenant prefix, and the handler subsequently initializes S3 credentials and lists objects (`:46–65`), permitting unauthorized S3 scanning/resource consumption when initialization succeeds.

**Limits:** This does **not** prove unauthorized database writes under that configuration: the same absent secret is used by `createClient` (`:40–43`), which may fail before S3 access or yield failed database operations. Upstream JWT enforcement is unspecified. With a nonempty secret, substring matching is weaker than exact Bearer-token validation, but does not itself let someone authenticate without knowing the secret.

**Existing tests:** No scanner authentication coverage exists in `test-rls.sql`.

**Minimal regression:** Missing/empty secret, missing header, arbitrary header, and malformed Bearer headers must fail before client initialization or S3 access; only the exact configured credential should succeed.

### 3. Scans can overwrite manifest state and repeatedly enqueue parsing
**Severity: Medium, ingestion-integrity impact; confidence: high in handler behavior.**

**Evidence**
- `supabase/functions/scanner/index.ts:76–78` uses an ETag—or the constant `"unknown"`—as `sha256`.
- `:85–99` upserts on `(tenant_id,sha256)` with updates enabled, always writing `bundle_uri` and `status: "queued"`.
- `:106–119` inserts a parse job for every successfully processed recognized-format manifest, without checking whether it is new or already processed.

**Actor and impact:** An authorized operator repeating a scan can reset an existing manifest to queued and submit another parse job. An uploader whose objects are scanned can cause distinct keys with identical ETags, including copies of identical content, to target the same tenant/hash manifest and replace its URI. Missing ETags also share `"unknown"`. This can lose distinct manifest provenance and create duplicate processing.

**Limits:** Manifest updates and job insertion depend on table routing, constraints, and successful database operations. Downstream duplicate suppression is not shown. ETag use does not establish a practical arbitrary-content collision attack, and the conflict key includes `tenant_id`, so this is not a demonstrated cross-tenant overwrite.

**Existing tests:** `test-rls.sql` tests neither `app.manifest` nor `app.job`, rescan idempotency, hash validation, or state transitions.

**Minimal regression:** Scan twice and require unchanged completed state and no duplicate active job. Scan two keys sharing an ETag and verify intended provenance semantics. Missing ETags must not silently become a shared content identifier.

### 4. Audit-event insertion does not bind the event to an authorized tenant
**Severity: Medium if an untrusted role has INSERT access; confidence: high in the policy gap, conditional in exploitability.**

**Evidence:** `supabase/migrations/00008_enable_rls_and_policies.sql:75–77`, policy `audit_event_insert` on `app.audit_event`, checks only `user_id = auth.uid()`. It does not check `app.is_member(tenant_id)`. The SELECT policy (`:71–73`) allows tenant members to read events.

**Actor and impact:** A caller with applicable INSERT privileges can submit their own user ID but another tenant’s ID, injecting apparently tenant-associated audit events into that tenant’s readable audit trail.

**Limits:** `00015_hardening.sql:7` revokes authenticated table privileges, so a normal authenticated caller with no inherited/PUBLIC grants cannot exploit this after hardening. Other grants and table constraints are not shown.

**Existing tests:** No audit insertion or cross-tenant audit-integrity assertion appears in `test-rls.sql`.

**Minimal regression:** Under every exposed writer role, inserting an audit event with the caller’s user ID and an unrelated tenant must fail; valid same-tenant insertion should succeed where intended.

## Boundary conclusions and unsupported hypotheses

- **Tenant identity:** Standard policies use `app.is_member(tenant_id)` (`00008:38–45`), but its definition is not supplied. JWT identity derivation and that helper’s own security cannot be judged.
- **Scanner trust:** The scanner accepts the body’s `tenant_id` and writes using a service-role client (`scanner/index.ts:30,40–43,89,111`). There is no tenant-membership check. A service-key holder can choose any tenant, but that holder already possesses a globally privileged credential; this alone is **not** a new tenant-user escalation.
- **S3 prefix:** `${tenant_id}/${prefix}` (`:56`) provides a literal prefix, not filesystem traversal. No supported `../` cross-tenant escape is demonstrated.
- **Relational cross-tenant writes:** Member policies check each row’s tenant ID, not the tenancy of referenced assets/surveys. Without foreign-key definitions, a cross-tenant reference vulnerability cannot be established.
- **Views:** Hardening grants SELECT on `public.api_*` views (`00015:15–22`). Their definitions and security settings are outside this packet. Neither safe RLS propagation nor a view-based leak is proven.

## Priority and test adequacy

1. **First:** establish helper EXECUTE grants and remove untrusted access to `app.apply_member_policies`.
2. **Next:** make scanner authentication fail closed; test rescan/hash integrity.
3. **Then:** close the audit tenant-binding gap and verify actual writer privileges.

The existing script is largely a manual checklist, not executable isolation assertions. Its “simulations” filter by tenant without changing role or JWT identity (`test-rls.sql:134–185`); its cross-tenant query deliberately uses service-role visibility (`:218–231`). Its claim that views inherit RLS (`:237`) is not generally guaranteed.

Add actual authenticated-role/JWT tests for two tenants: unfiltered reads, unauthorized INSERT/UPDATE/DELETE, attempted tenant reassignment, public API-view reads, and cross-tenant references. After hardening, explicitly test that direct `app` table access is denied and approved API views expose only permitted rows.

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

## Prioritized findings

1. **Scanner authorization accepts a substring rather than validating a credential. Severity: High, conditional on the service-role key being nonempty and the handler being reachable.**  
   In `supabase/functions/scanner/index.ts`, lines 20–27, authorization uses `authHeader.includes(SUPABASE_SERVICE_ROLE_KEY)`. Thus, a request whose `Authorization` header contains the key as any substring passes this check; it need not equal a bearer credential. A caller who learns the key, or can induce a request carrying it in a larger header value, can submit a chosen `tenant_id` and `prefix` (lines 29–36, 56) and trigger scanner writes. The latter exploit path depends on deployment and request-proxy behavior not shown here. The key is also used to create a service-role Supabase client (lines 39–43), so subsequent writes run with that client’s privileges. The RLS tests do not test scanner authentication or malformed authorization headers.

2. **Scanner trusts caller-supplied tenant and prefix for privileged cross-tenant ingestion. Severity: High, if an attacker can invoke the function with an accepted authorization header.**  
   The handler takes `tenant_id` and `prefix` directly from JSON (lines 29–36), constructs the S3 prefix as `${tenant_id}/${prefix}` (line 56), then upserts `manifest` and inserts `job` rows using that same tenant ID (lines 85–119). It does not verify that the tenant exists, that the caller is authorized for it, or that the S3 object’s tenant matches it. With a valid/accepted scanner credential, a caller can request another tenant’s S3 prefix and create or update its manifest/job records. Actual cross-tenant impact depends on S3 bucket contents, database constraints, and service-role privileges, which are not established in this packet. `test-rls.sql` describes user-level isolation assertions (lines 156–185, 218–231), but does not exercise scanner writes or service-role behavior.

3. **Tenant membership helper and RLS execution details are not evidenced; isolation claims in the test are largely expectations, not demonstrated assertions.**  
   `00008_enable_rls_and_policies.sql` enables RLS on `app` base tables (lines 5–18) and creates standard policies using `app.is_member(tenant_id)` (lines 20–47, applied to listed tables at lines 51–66). The definition, tenant-identity derivation, and privileges of `app.is_member` are absent, so it is not possible to establish whether it correctly derives identity from `auth.uid()`, whether it is `SECURITY DEFINER`, or whether it can be abused. The helper that creates policies is itself `SECURITY DEFINER` (lines 21–25), but its body only drops/creates policies using the supplied table name (lines 29–46); whether its execution privileges or input are exploitable is not established by the packet. `00015_hardening.sql` revokes authenticated access to `app` tables, sequences, and functions (lines 3–13), then grants authenticated users select on named public views (lines 15–22). It does not establish service-role restrictions.  
   In `test-rls.sql`, the membership check at lines 59–61 is described as expected behavior, while lines 108–115 and 170–185 explicitly say users must be tested through the app and that SQL Editor/service-role use cannot impersonate them. Cross-tenant results at lines 218–231 are stated as expected, not executed user assertions. No test is claimed to have run.

## Regression scenarios

1. Send scanner requests with the key absent, exact, embedded in a larger authorization value, and empty/unset in the environment; require only the intended credential form to pass.
2. Invoke scanner for tenant B while authenticated only for tenant A; assert no S3 scan and no tenant-B manifest/job changes.
3. As authenticated users in separate tenants, assert SELECT and insert/update/delete isolation on each listed tenant-scoped table, including attempts to supply another tenant’s ID.
4. Inspect and test `app.is_member` under real user JWTs, including whether its identity is `auth.uid()` and whether its privileges or definer context permit membership bypass.
5. Verify access through the granted `public.api_*` views under distinct user JWTs; do not treat service-role SQL results as user-isolation evidence.

The packet does not include the `app.is_member` definition, table constraints, or deployment configuration; conclusions depending on those are conditional.

Primary judge's stated reason

A provides better-supported prioritization and actionable coverage of privileged SQL execution, scanner fail-open configuration, ingestion integrity, and audit writes. Its separation of defective construction from uncertain reachability better satisfies the evidence-only review. This is a clear comparative advantage, not merely a forced slight preference; it does not establish that any exploit succeeded.

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

Battle wave: 10549f36-d72c-445b-a691-1df97fa35ca0. Pair: brp1_d7c673cb74c6aea8d30885607f496eed80b2bc117b5c40efc2757373fc781b75. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.