mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2623] [MERGED] fix: W2 audit batch — restore secrets, metadata races, untrusted-input DoS (#2611-#2621) #5692
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5692
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2623
Author: @Romuromylus
Created: 6/18/2026
Status: ✅ Merged
Merged: 6/18/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/audit-w2-batch-2611-2621📝 Commits (10+)
87ac248fix(backup): preserve live secrets on profile restore UPDATE path733fe0afix(discord-webhook): suppress mentions on mirrored content61a2df1fix(png-parser): read chunk length unsigned and guard the chunk walk4e0c3d4fix(import): normalize numeric selectiveLogic/position in native lorebook importer55d222dfix(knowledge-sources): cache extracted text and make meta writes atomice815d0dfix(game): preserve field locks and manual overrides on checkpoint loadb0a18c7fix(regex): reject ReDoS-prone prompt regex at apply time and on save61a4555fix(retry-agents): abort upstream agent calls on client disconnect2ff81fdfix(file-store): copy-on-write transaction rollbackd4ff900fix(import): accept unknown in resolvePosition for native importer pass-through📊 Changes
13 files changed (+324 additions, -114 deletions)
View changed files
📝
packages/client/src/lib/png-parser.ts(+12 -4)📝
packages/server/src/db/file-backed-store.ts(+46 -5)📝
packages/server/src/routes/backup.routes.ts(+27 -1)📝
packages/server/src/routes/chats.routes.ts(+10 -11)📝
packages/server/src/routes/game.routes.ts(+64 -53)📝
packages/server/src/routes/generate.routes.ts(+2 -2)📝
packages/server/src/routes/generate/retry-agents-route.ts(+23 -0)📝
packages/server/src/routes/knowledge-sources.routes.ts(+117 -31)📝
packages/server/src/services/discord-webhook.ts(+3 -1)📝
packages/server/src/services/import/marinara.importer.ts(+3 -2)📝
packages/server/src/services/import/st-lorebook.importer.ts(+2 -2)📝
packages/server/src/services/regex/regex-application.ts(+4 -1)📝
packages/shared/src/schemas/regex.schema.ts(+11 -1)📄 Description
Linked issue
This PR addresses 11 issues filed from the W2 static audit of
staging. The PR base isstaging, whose default-branch ismain, soCloses #would not auto-fire on merge — these are closed manually after merge:Refs #2611, #2612, #2613, #2614, #2615, #2616, #2617, #2618, #2619, #2620, #2621
Why this change
All 11 are pre-existing (non-regression) defects the W2 audit surfaced across the server and one client parser. They cluster into a few themes — secret/data loss on restore, metadata/meta lost-write races, untrusted-input DoS, and a leak/perf pair — and each fix mirrors a pattern already present elsewhere in the repo. Grouping them keeps the review in one place; every commit is scoped to a single issue so they remain individually traceable and revertable.
api_connections.apiKeyEncrypted,agent_configssecret settings, andcustom_tools.webhookUrl— secrets that are not in the archive, so the loss is unrecoverable. Now the conflict-UPDATE path omits those columns so the stored value is preserved; fresh inserts still carry the blanks.FileTableStore.transaction()deep-cloned the whole table map for rollback and restored all of it on throw — dropping concurrent writes to untouched tables and allocating O(total-rows) per call on a hot path (setMemoriesper agent turn). Rollback is now copy-on-write: a table is snapshotted only on first mutation and only dirty tables are restored.updateMetadata({ ...staleMeta, ...changes }), racing the queue-serializedpatchMetadata. The priority LLM-bearing handlers and/summariesnow route throughpatchMetadata, which re-reads fresh metadata inside the per-chat queue./retry-agentshad no abort wiring, so a client disconnect left every in-flight agent LLM call running. Mirrors the main generate route:AbortController, close-listener,context.signalthreaded into the agent context, post-start events viatrySendSseEvent, listener removed infinally.allowed_mentions, so mirrored content could@everyone/@here/role-ping. Nowallowed_mentions: { parse: [] }on every body.(size, uploadedAt), invalidated on re-upload/delete..marinara.jsonlorebook importer passed numericselectiveLogic/positionthrough verbatim; a numeric value silently disabled selective gating. Now routed through the sameresolveSelectiveLogic/resolvePositionnormalizers the ST importer uses./game/checkpoint/loaddroppedfieldLocks/manualOverrideswhen cloning the restored snapshot, so locked tracker fields were silently lost on restore. Both are now carried onto the cloned state.isPatternSafeat apply time and rejected at thePOST/PATCH /regex-scriptsvalidation layer, matching the lorebook regex posture.meta.jsonwrites serialized the write but not the read-modify-write, allowing a lost update.writeMetanow takes a mutator that re-reads inside the serialized critical section, mirroringwithMetadataPatchQueue.What changed
Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkpasses locally and the per-package vitest suite passes (focused regression tests added for #2611, #2616, and #2618 — kept local-only per our test-file convention). The boxes above are intentionally left unticked as a reviewer to-do; below is what I verified directly on a build of this branch deployed to my private instance.Confirmed on the deployed branch (real data, with a full data snapshot taken first):
api_connectionsrow withapiKeyEncryptedblanked (exactly what a redacted export contains). The import ran the conflict-UPDATE path on all 14 rows (HTTP 200,connections: 14) and every stored key was preserved byte-for-byte (0 blanked, 0 changed). On the pre-fix code this path blanks all 14. Net change to the data: none.PUT /game/:chatId/noteshandler (now routed throughpatchMetadata) updatedgamePlayerNoteswhile leaving every other key intact (witness keygameActiveStateunchanged). Restored afterward.Still worth a reviewer eyeball in normal use:
promptOnlyregex script with a catastrophic pattern via the API; confirm it is rejected at validation and not run per turn.Docs and release impact
UI evidence (if applicable)
Verified on a build of this branch deployed to my private EasyPanel instance (CI
pnpm-validate+container-build-testboth green):api_connectionsrows → HTTP 200, all 14 stored keys preserved (0 blanked / 0 changed); the pre-fix path would have blanked all 14.PUT /game/:chatId/noteson a 63-key game chat →gamePlayerNotesupdated, all other keys (incl.gameActiveState) intact.After verification the deployment was repointed back to
staging, the data snapshot was restored to pre-test state, and the snapshot was removed.Summary by CodeRabbit
Bug Fixes
New Features
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.