[GH-ISSUE #6691] [Feature]: Reviewed server fixes, part 1: routes, middleware, storage recovery, importers, sidecars and SSRF #3746

Closed
opened 2026-10-21 06:06:46 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @SirAdoni on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6691

Originally assigned to: @SpicyMarinara on GitHub.

Part of the contribution roadmap in #6624 (package D).

What problem does this solve?

A read-through of the server routes and middleware turned up a set of small bugs. None is large on its own, but a few lose data or weaken a safety check, so they seemed worth fixing together:

  • Data loss: a crash could drop writes still waiting in the store's debounce window, and emptying a table right before a crash could bring deleted rows back from the .pre-shard backup.
  • Safety checks: an IPv4 CIDR prefix over 32 was accepted by the IP allowlist, IPv6 local hosts were judged by string instead of address range, a route's own config.rateLimit was not read, and reserved address ranges could be reached through TRUSTED_PRIVATE_NETWORKS or a cross-origin redirect that kept provider keys.
  • Everyday annoyances: a .env reload warned about a restart on every save, some chat and conversation routes overwrote fields they did not own, the /raw route kept running after a disconnect, and the conversation summary ignored its abort and timeout.
  • Smaller fixes in backgrounds, backups and exports, chat presets, connection images, emoji and sticker imports, fonts, gallery selfies, sprites, translation, the SillyTavern and RisuAI importers, the Lorebook Keeper and the local sidecar downloads.

Proposed solution

Targeted fixes to the existing code, keeping its APIs, names and structure as they are. Every fix has its own regression (server-hunt-b<N>), so each one can be reviewed, kept or dropped on its own.

  • How it's switched: no switch. These are bug fixes, and every request that worked before gets the same answer. Fixes that would change prompts or stored data are not in this package.
  • Areas touched (for spotting overlap):
    • packages/server/src/routes: backgrounds, backup, capability packages, chat presets, chats, connections, conversation, custom emojis and stickers, fonts, gallery, generate, import, sprites, utility sidecar
    • packages/server/src/routes/generate: raw route, dry run, agent retry, conversation history and connected context, Lorebook Keeper and expression agent helpers
    • packages/server/src/middleware: IP allowlist, rate limit
    • packages/server/src/services: sidecar download and process, utility sidecar, SillyTavern importers, auto summary, translation, textual tool-call parser, chats and custom tools storage
    • packages/server/src/db (file-backed store, background seed), config/runtime-config.ts, utils/security.ts
    • One client hook (use-custom-tools.ts), CHANGELOG.md, and a short section in the foundations overview doc
  • Size: about 87 files, about 5,900 added lines, of which 38 files are regressions.
  • Status: implemented and tested in a fork, on Windows and on Linux (WSL, the CI-equivalent run).

Alternatives considered

  • One PR per bug: about 50 tiny PRs would be a lot of review overhead. Grouping them by area (this package covers routes and middleware; package E covers services and storage) keeps each PR reviewable, while the per-fix regressions keep them separable.
  • Leaving the security-adjacent ones for later: the SSRF and allowlist fixes are small and have regressions, so they seemed safer to include than to hold back.

Additional context

  • A few pieces were deliberately not ported because staging has already reworked that code (the joined-select pre-filter and the branch creation rollback).
  • Implementation depends on #6647 (foundations); PRs will follow once it merges, one package at a time.
  • If you're working in any of these areas, please comment so we can coordinate before a PR.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @SirAdoni on GitHub (Sep 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6691 Originally assigned to: @SpicyMarinara on GitHub. <!-- roadmap issue D, draft v1.0 --> Part of the contribution roadmap in #6624 (package D). ## What problem does this solve? A read-through of the server routes and middleware turned up a set of small bugs. None is large on its own, but a few lose data or weaken a safety check, so they seemed worth fixing together: - **Data loss:** a crash could drop writes still waiting in the store's debounce window, and emptying a table right before a crash could bring deleted rows back from the `.pre-shard` backup. - **Safety checks:** an IPv4 CIDR prefix over 32 was accepted by the IP allowlist, IPv6 local hosts were judged by string instead of address range, a route's own `config.rateLimit` was not read, and reserved address ranges could be reached through `TRUSTED_PRIVATE_NETWORKS` or a cross-origin redirect that kept provider keys. - **Everyday annoyances:** a `.env` reload warned about a restart on every save, some chat and conversation routes overwrote fields they did not own, the `/raw` route kept running after a disconnect, and the conversation summary ignored its abort and timeout. - Smaller fixes in backgrounds, backups and exports, chat presets, connection images, emoji and sticker imports, fonts, gallery selfies, sprites, translation, the SillyTavern and RisuAI importers, the Lorebook Keeper and the local sidecar downloads. ## Proposed solution Targeted fixes to the existing code, keeping its APIs, names and structure as they are. Every fix has its own regression (`server-hunt-b<N>`), so each one can be reviewed, kept or dropped on its own. - **How it's switched:** no switch. These are bug fixes, and every request that worked before gets the same answer. Fixes that would change prompts or stored data are not in this package. - **Areas touched (for spotting overlap):** - `packages/server/src/routes`: backgrounds, backup, capability packages, chat presets, chats, connections, conversation, custom emojis and stickers, fonts, gallery, generate, import, sprites, utility sidecar - `packages/server/src/routes/generate`: raw route, dry run, agent retry, conversation history and connected context, Lorebook Keeper and expression agent helpers - `packages/server/src/middleware`: IP allowlist, rate limit - `packages/server/src/services`: sidecar download and process, utility sidecar, SillyTavern importers, auto summary, translation, textual tool-call parser, chats and custom tools storage - `packages/server/src/db` (file-backed store, background seed), `config/runtime-config.ts`, `utils/security.ts` - One client hook (`use-custom-tools.ts`), `CHANGELOG.md`, and a short section in the foundations overview doc - **Size:** about 87 files, about 5,900 added lines, of which 38 files are regressions. - **Status:** implemented and tested in a fork, on Windows and on Linux (WSL, the CI-equivalent run). ## Alternatives considered - **One PR per bug:** about 50 tiny PRs would be a lot of review overhead. Grouping them by area (this package covers routes and middleware; package E covers services and storage) keeps each PR reviewable, while the per-fix regressions keep them separable. - **Leaving the security-adjacent ones for later:** the SSRF and allowlist fixes are small and have regressions, so they seemed safer to include than to hold back. ## Additional context - A few pieces were deliberately not ported because `staging` has already reworked that code (the joined-select pre-filter and the branch creation rollback). - Implementation depends on #6647 (foundations); PRs will follow once it merges, one package at a time. - If you're working in any of these areas, please comment so we can coordinate before a PR. ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 26, 2026):

Awaiting PR.

<!-- gh-comment-id:5848650315 --> @SpicyMarinara commented on GitHub (Sep 26, 2026): Awaiting PR.
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#3746
No description provided.