Skip to content

fix(db): owner-scoped file half and chunked instance sweep for DELETE /v1/batches/delete-completed (SEC-C/SEC-D, omni-code-sec on #12969) - #13374

Merged
diegosouzapw merged 5 commits into
fix/batches-delete-completed-authzfrom
fix/batches-sweep-file-ownership-chunks
Sep 14, 2026
Merged

diegosouzapw merged 5 commits into
fix/batches-delete-completed-authzfrom
fix/batches-sweep-file-ownership-chunks

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

Closes SEC-C and SEC-D of the omni-code-sec battery on #12969.

Validation

files-delete-owned-by 4/4 · ownership-wvxc 11/11 · route-scope 10/10 · batch-deletion 8/8 · typecheck:core · changelog-integrity vs the feature branch. Full suite on .113: last comment.

⚠️ base-red inherited: #12732
Refs #12969

…NCE_SWEEP_CHUNK ids per statement

The B3 restructure collected ALL of a key's completed batch ids into one
IN (…) list; past SQLite's 32766 bound-parameter ceiling the sweep would
throw and the tenant's only bulk-cleanup path would stay dead. Key mode now
runs the same 200-id unit inside ONE outer transaction (nested calls are
savepoints), so it stays all-or-nothing and never exceeds the ceiling.
Also: whitespace-only apiKeyId rejected at the top; JSDoc qualifies the
nulled-file guarantee as per-chunk in instance mode.

Refs #12969
jonlwheat2-gif added a commit to jonlwheat2-gif/OmniRoute that referenced this pull request Sep 13, 2026
…pw#13377)

Auth (from PR diegosouzapw#13375):
- Delete isStaleDashboardJwtError + staleDashboardJwtWarningEmitted from pipeline.ts; emit log in !payload branch
- Minters use getDashboardJwtSecret() (trimmed) in login/route.ts, oidc/callback/route.ts
- ws/handshake.ts uses getDashboardJwtSecret() instead of raw env
- verifyDashboardSessionToken: pin {algorithms:['HS256']}, reject empty Uint8Array
- Use DASHBOARD_SESSION_COOKIE/CLAIM constants in 7 consumers
- Source guard: allowlist dashboardSessionToken.ts + oidc/callback for jwtVerify imports
- Add try/finally around env mutation in dashboard-session-token-13298.test.ts
- AUTHZ_GUIDE.md: 'route guard' -> 'dashboard route guard (isDashboardSessionAuthenticated())'

Tests: 28/28 auth tests pass, typecheck clean

Scope note: the Batches half of diegosouzapw#13377 (forward-progress guard for
deleteCompletedBatches) is intentionally NOT in this PR. The issue's wording
("both for (;;) loops") targets PR diegosouzapw#13374's chunked implementation, which is
stacked on PR diegosouzapw#12969 — not this release/v3.8.51 base. It is tracked separately.
@diegosouzapw

Copy link
Copy Markdown
Owner Author

Full suite on the .113 box

head test:unit test:vitest build
f23a759c (B1–B4) 37 708 pass / 49 fail / 27 skipped — 0 in batches/files/api-keys passed OK
92ca71c1 (+ fix wave: key-mode never binds > 200 ids) 37 692 pass / 41 fail / 27 skipped — 0 in batches/files/api-keys passed OK

Every failing file is either in the inherited set already recorded on #13262/#13297/#13375, or proven environmental with the box idle: the 6 catalog files new on f23a759c pass on both head and base; the 2 tproxy-* files new on 92ca71c1 fail at the base commit inside the same directory too (the directory's build artifacts + root make POST /tproxy succeed where the test expects a 500) and pass in a clean base checkout. No failure is introduced by this branch.

Focused: batches-delete-completed-ownership-wvxc 13/13 · route-scope 10/10 · batch-deletion 8/8 · files-delete-owned-by 4/4. Final whole-branch review: with fixes → all addressed (92ca71c1); may-ship residuals tracked in #13377.

@diegosouzapw
diegosouzapw merged commit ebd6e19 into fix/batches-delete-completed-authz Sep 14, 2026
3 checks passed
@diegosouzapw
diegosouzapw deleted the fix/batches-sweep-file-ownership-chunks branch September 14, 2026 16:42
diegosouzapw added a commit that referenced this pull request Sep 14, 2026
Merged after reconciling the whole stack onto the tip, operator-reviewed before merge.

The core ownership fix for GHSA-wvxc-jp3v-5mg5 had already landed via #13211 with a different implementation of the same endpoint. This branch carries a stricter one, built up in layers: this PR, #13262 (explicit scope, audit log, atomic sweep), #13297 (revoked, deactivated, banned or expired keys rejected) and #13374 (owner-scoped file half, chunked instance sweep — SEC-C/SEC-D). The stack's implementation was kept over #13211's because it is stricter on every point:

- **route:** with #13211, a request carrying BOTH a dashboard session cookie and an API key swept the whole instance. Here a presented key always scopes the sweep to that key; only a session without a key sweeps all tenants; neither returns 401. Instance-wide and row-deleting sweeps log at warn as an audit trail, and a failing sweep returns a sanitized 500.
- **`deleteCompletedBatches`:** takes an explicit `{ apiKeyId } | { allTenants: true }`. An omitted or blank key throws instead of widening, and passing both throws.
- **files:** a key sweep only soft-deletes files the caller owns (`deleteFileOwnedBy`), so a batch referencing another tenant's or an unowned file never nulls its content.
- **transactions:** key mode is all-or-nothing across chunks; instance mode commits per 200-id chunk so a large sweep never holds one write lock on the table.

#13211's own test was aligned to the explicit-scope API with its assertions unchanged. Its seed now creates the file with the batch's owner, as an upload through that key does in production — without that, SEC-C correctly leaves the unowned file intact.

- 51/51 across the six batch suites (#13211's test, this stack's ownership and route-scope tests, `batch-deletion`, `batch-deletion-route-logic`, `files-delete-owned-by`)
- ESLint, `typecheck:core`, complexity, cognitive-complexity, changelog integrity: clean

⚠️ base-red inherited: #12732
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…w#12969)

Merged after reconciling the whole stack onto the tip, operator-reviewed before merge.

The core ownership fix for GHSA-wvxc-jp3v-5mg5 had already landed via diegosouzapw#13211 with a different implementation of the same endpoint. This branch carries a stricter one, built up in layers: this PR, diegosouzapw#13262 (explicit scope, audit log, atomic sweep), diegosouzapw#13297 (revoked, deactivated, banned or expired keys rejected) and diegosouzapw#13374 (owner-scoped file half, chunked instance sweep — SEC-C/SEC-D). The stack's implementation was kept over diegosouzapw#13211's because it is stricter on every point:

- **route:** with diegosouzapw#13211, a request carrying BOTH a dashboard session cookie and an API key swept the whole instance. Here a presented key always scopes the sweep to that key; only a session without a key sweeps all tenants; neither returns 401. Instance-wide and row-deleting sweeps log at warn as an audit trail, and a failing sweep returns a sanitized 500.
- **`deleteCompletedBatches`:** takes an explicit `{ apiKeyId } | { allTenants: true }`. An omitted or blank key throws instead of widening, and passing both throws.
- **files:** a key sweep only soft-deletes files the caller owns (`deleteFileOwnedBy`), so a batch referencing another tenant's or an unowned file never nulls its content.
- **transactions:** key mode is all-or-nothing across chunks; instance mode commits per 200-id chunk so a large sweep never holds one write lock on the table.

diegosouzapw#13211's own test was aligned to the explicit-scope API with its assertions unchanged. Its seed now creates the file with the batch's owner, as an upload through that key does in production — without that, SEC-C correctly leaves the unowned file intact.

- 51/51 across the six batch suites (diegosouzapw#13211's test, this stack's ownership and route-scope tests, `batch-deletion`, `batch-deletion-route-logic`, `files-delete-owned-by`)
- ESLint, `typecheck:core`, complexity, cognitive-complexity, changelog integrity: clean

⚠️ base-red inherited: diegosouzapw#12732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant