mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6133] A chat can store an on/off choice for a lorebook entry it is not allowed to see #3410
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#3410
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 (Sep 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6133
Originally assigned to: @SpicyMarinara on GitHub.
The route that saves a per-chat lorebook entry switch accepts any entry id that exists, without checking the entry belongs to a lorebook this chat can actually use. Saving a switch for an entry in a book the chat has never attached succeeds and leaves a meaningless setting on the chat forever.
How to reproduce (try it yourself)
The chat settings panel only lists entries of books already attached to the chat, so this cannot be clicked through - it needs a direct request. With the app running on :7860:
LB=$(curl -s -X POST http://127.0.0.1:7860/api/lorebooks -H 'content-type: application/json' -d '{"name":"stray","scope":{"mode":"disabled"}}' | python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])')EN=$(curl -s -X POST http://127.0.0.1:7860/api/lorebooks/$LB/entries -H 'content-type: application/json' -d '{"name":"stray entry","content":"x"}' | python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])')curl -s -w '\n%{http_code}\n' -X PATCH http://127.0.0.1:7860/api/chats/<anyChatId>/lorebook-entries/$EN -H 'content-type: application/json' -d '{"enabled":false}'What you'll see: 200, and the returned chat's
metadata.entryStateOverridesnow holds a key for an entry in a book this chat cannot see. A made-up entry id already returns 404 and a made-up chat id already returns 404, so the scope check is the one guard that is missing.What should happen: 404 (or 409). The route should read the entry's
lorebookIdand refuse unless that book is in the chat's resolvable set - attached books, plus character, persona, global and chat-scoped books, minus the ones excluded for this chat.Where it is
At staging
52799569c,packages/server/src/routes/chats.routes.ts:1364-1388, the handler forPATCH /:id/lorebook-entries/:entryId. It checks three things and nothing else: the body shape, that the entry exists, and that an entry being switched on is not switched off globally.packages/server/src/routes/chats.routes.ts:1367-const entry = await createLorebooksStorage(app.db).getEntry(req.params.entryId);is a bare lookup by id. ComparegetFolderatpackages/server/src/services/storage/lorebooks.storage.ts:846-853, which takes an optionallorebookIdprecisely to stop this kind of cross-object addressing.What's happening
The handler treats the entry id as a global address. It never asks which lorebook the entry belongs to, so it never compares that book against the chat's own lorebook settings, and the merge at
:1374-1386writes the key unconditionally.The stored setting is inert for the standard prompt path - these switches are only ever subtractive there (
packages/server/src/services/lorebook/index.ts:1124-1141removes an entry when the switch says off; a switch saying on never adds one), and the knowledge-router path works from entries already limited to the books the chat resolved. So this is hardening against meaningless state rather than a content leak, and it is not reachable from the interface:packages/client/src/components/chat/ChatSettingsDrawer.tsx:7229mounts the entry editor only for a book already active on the chat.Suggested fix
Resolve
entry.lorebookIdin the handler and reject the write unless that book is in the chat's resolvable set, reusing the same scope resolution the prompt builder already performs rather than re-deriving it.getFolder's optional-lorebookIdshape is the precedent for scoping a lookup to its parent. Add a case toscripts/regressions/chat-lorebook-entry-scope.regression.ts, which today covers per-chat isolation and the global-off floor but not scope validation.Context
The route was added by PR #5981 (merged 2026-09-09) for issue #5954. Neither asked for scope validation, so this is a gap in a new feature rather than a regression, and since the write is inert and unreachable from the interface it is closer to housekeeping than to a malfunction. It is filed separately from the related cleanup issue because the fix lives in a different file. Unreleased on staging (latest release is v2.4.4).
Found by an AI-assisted sweep of merged PR #5981 against issue #5954, then re-verified against staging
52799569con 2026-09-13. Please verify before fixing.Related issue from the same sweep: #6132 (the cleanup gap for the same stored switches).
@SpicyMarinara commented on GitHub (Sep 13, 2026):
@SpicyMarinara is taking this report through the issue sweep in draft PR #6137, with Codex assisting. The affected current-code path has been checked; implementation and focused regression verification are in progress.
@SpicyMarinara commented on GitHub (Sep 13, 2026):
Fixed in #6137, now merged to staging (
e044997a2). Chat-local lore-entry toggles enforce book visibility and generation respects the shared-off floor.