mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2976] [Issue]: createLorebookSchema lacks the scope-conflict validation updateLorebookSchema enforces, so POST silently drops fields and can leak a global character book to every chat #1553
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#1553
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?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2976
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When creating a lorebook (
POST /lorebooks), contradictory scope fields are accepted silently, whereas the exact same payload sent as aPATCHis rejected with 400. Two concrete bad outcomes:characterIdandcharacterIdssilently drops the singlecharacterId(the array wins), so the book links to the wrong character set with no error.isGlobal: truetogether withcharacterId/personaIdstores the row as global, andlistActiveEntriesthen returns it for every chat (theisGlobalshort-circuit runs before the character/persona checks) — leaking a book the caller intended to scope to one character into all chats.The update schema's
superRefinecatches both; the create schema has nosuperRefineat all.How to reproduce (try it yourself)
POST /api/lorebookswith{"name":"Test","isGlobal":true,"characterId":"char-1"}. It is created with no 400.char-1and run a generation/scan — the lorebook's entries activate becauseisGlobalwins.POST /api/lorebookswith{"name":"Test2","characterId":"A","characterIds":["B"]}— the created book links only to B; A is silently lost.PATCH /api/lorebooks/:idinstead — it is rejected with 400.Expected:
POSTrejects the same contradictory payloadsPATCHalready rejects.Where it is
packages/shared/src/schemas/lorebook.schema.ts:67-94(createLorebookSchema, nosuperRefine) vs:96-154(updateLorebookSchemawithsuperRefine; see:147-153for theisGlobalcheck).packages/server/src/services/storage/lorebooks.storage.ts:51-55(resolveLinkIdsprefers the array, drops the scalar),:303+:318(create storescharacterIds[0]),:321(storesisGlobalverbatim),:453(listActiveEntries:if (b.isGlobal) return true;short-circuits scope filtering before the character/persona/chat checks at:455-463).packages/server/src/routes/lorebooks.routes.ts:398(POST uses create schema) vs:410(PATCH uses update schema).What's happening
createLorebookSchemais a plainz.objectwith no.superRefine, so the cross-field invariants (characterId XOR characterIds, personaId XOR personaIds, isGlobal excludes character/persona links) are only validated on update. Storagecreate()then usesresolveLinkIds(input.characterIds, input.characterId), which prefers the array and discards the scalar, and storesisGlobalverbatim — so conflicting input is accepted and partially discarded instead of rejected.Suggested fix
Extract the
superRefinebody fromupdateLorebookSchemainto a shared refinement and apply it tocreateLorebookSchemaas well (e.g.createLorebookSchema = baseObject.superRefine(sameChecks)), soPOSTrejects the same contradictory payloadsPATCHalready rejects. Note this only gates the public route — internal callers (importSTLorebook, the keeper'spersistLorebookKeeperUpdates) callstorage.create()directly and bypass the schema, so they are unaffected.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in the v2.0.7 branch: createLorebookSchema now shares the same scope-conflict validation as updates, rejecting conflicting character/persona/global targets at create time. Validated with pnpm check and shared tsc.