[PR #8216] [MERGED] fix: reject malformed chat rosters before schema validation #8190

Closed
opened 2026-10-25 04:04:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8216
Author: @SpicyMarinara
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/chat-request-validation-hardening


📝 Commits (3)

  • 6c79d46 fix: bound ordinary chat validation diagnostics
  • f6f14c1 test: preserve large transfers while rejecting malformed chat rosters
  • 70ca79f test: budget real chat transfer regression for CI

📊 Changes

5 files changed (+231 additions, -3 deletions)

View changed files

📝 packages/server/src/middleware/error-handler.ts (+3 -1)
➕ packages/server/src/routes/chat-request-validation.ts (+26 -0)
📝 packages/server/src/routes/chats.routes.ts (+3 -2)
➕ scripts/regressions/chat-request-validation.regression.ts (+197 -0)
📝 scripts/run-regressions.mjs (+2 -0)

📄 Description

Linked issue

Closes #8215

Why this change

Ordinary chat creation and settings updates should reject malformed roster data before allocating a schema issue for every invalid entry. Diagnostic responses also need to remain useful without echoing thousands of errors. This is assessed controller hardening; no authentication bypass or server crash is claimed.

What changed

  • Ordinary chat creation and identity/roster updates now reject resource requests larger than 1 MiB. This budget applies only to POST /api/chats and PATCH /api/chats/:id.
  • Reject the first non-string roster entry before schema validation. Valid rosters have no new count cap.
  • Return at most 50 public schema-validation details as secondary protection.
  • Preserve import/export, upload, backup, profile, message-content and shared-schema behavior. No transfer limits are added or tightened, and no user text is shortened.

Zod remains 3.25.76 in this focused patch. The separate major-version migration needs compatibility work; a version-only upgrade does not address unbounded validation by itself.

Validation

Local validation on exact head 70ca79f158dc32743ca4eeafc99056994d6163d6:

  • pnpm check passed, including production client/server builds. One existing HomeProfessorMariChat.tsx hook-dependency warning remains.
  • New chat-request-validation.regression.ts passed: both real resource controllers reject all-invalid and first/last-invalid 10,000-entry rosters with zero schema element visits; the shared hook/schema accepts 10,001 valid IDs; both resource body budgets and the diagnostic cap are checked.
  • Real native character JSON import/export preserves 5,900,833 exported bytes and the user-text hash. That exported file also reimports through multipart and reexports with the same text hash. A separate native lorebook roundtrip preserves all 10,001 entries and their content (13,057,692 exported bytes).
  • Existing large-native-json-import and card-field-alternatives-import regressions passed. The existing regression-runner timeout-policy checks also passed.
  • The real large-transfer regression has the established 90-second slow-fixture budget and diagnostic stage timings. Its original fixture/assertion bytes are unchanged; replay through the actual runner passed in 17.788 seconds locally. The original hosted run exceeded the default 30-second process budget both in the pool and on its serial retry; this follow-up preserves that failure as evidence.
  • Substantive local CodeRabbit review completed with zero findings across the original four-file patch and the subsequent two-file CI-budget/timing follow-up (five final files in total).
  • Transfer caller/source audit confirms 61 global/shared/importer/transfer/frontend files are unchanged from the original staging base; all chat message/metadata/transfer handlers are also byte-identical after removing the three resource-only edits.

These are local in-process Fastify/real-storage checks. They do not claim network-authentication, browser/device or Docker execution. Hosted CI and Dottore Review remain merge gates.

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Manually verify ordinary chat creation and roster edits in the UI, then import and export representative large user data. Browser/device and local Docker validation were not performed for this backend-only patch.

Docs and release impact

No public UI/options, persistent storage format or release version changes. Existing transfer ceilings remain unchanged; this PR does not describe them as unlimited.

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened
  • Version/release files updated (only if this PR includes a version bump)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8216 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/chat-request-validation-hardening` --- ### 📝 Commits (3) - [`6c79d46`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c79d46ecd44f4dc2a4c355fa2b6e467e0d9e37b) fix: bound ordinary chat validation diagnostics - [`f6f14c1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f6f14c12a9dcddc9bb9fe8f050d62798f6a19fe0) test: preserve large transfers while rejecting malformed chat rosters - [`70ca79f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/70ca79f158dc32743ca4eeafc99056994d6163d6) test: budget real chat transfer regression for CI ### 📊 Changes **5 files changed** (+231 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/middleware/error-handler.ts` (+3 -1) ➕ `packages/server/src/routes/chat-request-validation.ts` (+26 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+3 -2) ➕ `scripts/regressions/chat-request-validation.regression.ts` (+197 -0) 📝 `scripts/run-regressions.mjs` (+2 -0) </details> ### 📄 Description ## Linked issue Closes #8215 ## Why this change Ordinary chat creation and settings updates should reject malformed roster data before allocating a schema issue for every invalid entry. Diagnostic responses also need to remain useful without echoing thousands of errors. This is assessed controller hardening; no authentication bypass or server crash is claimed. ## What changed - Ordinary chat creation and identity/roster updates now reject resource requests larger than 1 MiB. This budget applies only to `POST /api/chats` and `PATCH /api/chats/:id`. - Reject the first non-string roster entry before schema validation. Valid rosters have no new count cap. - Return at most 50 public schema-validation details as secondary protection. - Preserve import/export, upload, backup, profile, message-content and shared-schema behavior. No transfer limits are added or tightened, and no user text is shortened. Zod remains 3.25.76 in this focused patch. The separate major-version migration needs compatibility work; a version-only upgrade does not address unbounded validation by itself. ## Validation Local validation on exact head `70ca79f158dc32743ca4eeafc99056994d6163d6`: - `pnpm check` passed, including production client/server builds. One existing `HomeProfessorMariChat.tsx` hook-dependency warning remains. - New `chat-request-validation.regression.ts` passed: both real resource controllers reject all-invalid and first/last-invalid 10,000-entry rosters with zero schema element visits; the shared hook/schema accepts 10,001 valid IDs; both resource body budgets and the diagnostic cap are checked. - Real native character JSON import/export preserves 5,900,833 exported bytes and the user-text hash. That exported file also reimports through multipart and reexports with the same text hash. A separate native lorebook roundtrip preserves all 10,001 entries and their content (13,057,692 exported bytes). - Existing `large-native-json-import` and `card-field-alternatives-import` regressions passed. The existing regression-runner timeout-policy checks also passed. - The real large-transfer regression has the established 90-second slow-fixture budget and diagnostic stage timings. Its original fixture/assertion bytes are unchanged; replay through the actual runner passed in 17.788 seconds locally. The original hosted run exceeded the default 30-second process budget both in the pool and on its serial retry; this follow-up preserves that failure as evidence. - Substantive local CodeRabbit review completed with zero findings across the original four-file patch and the subsequent two-file CI-budget/timing follow-up (five final files in total). - Transfer caller/source audit confirms 61 global/shared/importer/transfer/frontend files are unchanged from the original staging base; all chat message/metadata/transfer handlers are also byte-identical after removing the three resource-only edits. These are local in-process Fastify/real-storage checks. They do not claim network-authentication, browser/device or Docker execution. Hosted CI and Dottore Review remain merge gates. - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Manually verify ordinary chat creation and roster edits in the UI, then import and export representative large user data. Browser/device and local Docker validation were not performed for this backend-only patch. ## Docs and release impact No public UI/options, persistent storage format or release version changes. Existing transfer ceilings remain unchanged; this PR does not describe them as unlimited. - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened - [ ] Version/release files updated (only if this PR includes a version bump) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-25 04:04:34 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8190
No description provided.