Skip to content

✂️ fix: Cap Audit Chain Verification and Honor Client Cancellation#13903

Merged
danny-avila merged 1 commit into
devfrom
codex/fix-unbounded-audit-chain-verification
Jun 23, 2026
Merged

✂️ fix: Cap Audit Chain Verification and Honor Client Cancellation#13903
danny-avila merged 1 commit into
devfrom
codex/fix-unbounded-audit-chain-verification

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Motivation

  • The audit verification path could walk and hash an unbounded per-tenant chain synchronously, allowing a delegated auditor to pin Node workers and MongoDB cursors (availability DoS).
  • The change limits server-side work for HTTP-triggered verification and makes verification abortable on client disconnect so a cancelled request no longer forces full cursor iteration.

Description

  • Add MAX_AUDIT_VERIFY_ROWS and extend VerifyAuditChainOptions with isCancelled?: () => boolean and maxRows?: number so the methods layer can stop early.
  • Update verifyAuditChain to observe isCancelled and maxRows, close the cursor and return a bounded non-OK result on cancellation or row-limit overflow.
  • Wire cancellation and the shared row cap into the admin handler: verifyAuditLogHandler now listens for res.once('close') / req.once('aborted'), passes isCancelled and MAX_AUDIT_VERIFY_ROWS to the methods layer, and skips writing a response if the client disconnected.
  • Add regression tests exercising cancellation and row-cap behavior in packages/api/src/admin/auditLog.spec.ts and packages/data-schemas/src/methods/auditLog.spec.ts, and export the new constant from packages/data-schemas.

Testing

  • Built the schemas package with npm run build:data-schemas, which completed successfully.
  • Built the API with npm run build:api, which completed successfully.
  • Ran the admin handler unit tests with cd packages/api && npx jest src/admin/auditLog.spec.ts --runInBand, which passed (34 tests).
  • Attempted to run the data-schemas methods tests with cd packages/data-schemas && MONGOMS_VERSION=7.0.14 npx jest src/methods/auditLog.spec.ts --runInBand, but the suite was blocked by mongodb-memory-server failing to download the MongoDB binary in this environment (HTTP 403), so the full methods-suite could not be executed here.

Codex Task

@danny-avila
danny-avila marked this pull request as ready for review June 23, 2026 00:05
@danny-avila
danny-avila changed the base branch from main to dev June 23, 2026 00:05
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 780078a74c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila changed the title fix: bound audit chain verification ✂️ fix: Cap Audit Chain Verification and Honor Client Cancellation Jun 23, 2026
@danny-avila
danny-avila merged commit d9251fc into dev Jun 23, 2026
19 checks passed
@danny-avila
danny-avila deleted the codex/fix-unbounded-audit-chain-verification branch June 23, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant