openai / gpt-6-astra / high / high effort preferred over openai / gpt-6.1-sol / low / low 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 / 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.Primary judge's stated reason
A receives a slight forced preference because its explicit conditional audit severity better supports the requested remediation prioritization. B's sharper unfiltered-view regression scenario is a genuine countervailing benefit. This is not an established material quality difference; an independent review could reasonably reject the preference.
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_dec5cd80fb4a7e667a601b794dc603d5a5a68eafdf855040d465f8428a92cfb6. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.