mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3037] [Issue]: Mutating connection routes return the unmasked apiKeyEncrypted ciphertext, breaking the masking contract on the GET routes #1605
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#1605
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/3037
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The read routes deliberately mask the stored key:
GET /(viastorage.list) andGET /:idboth overwriteapiKeyEncryptedwith"••••••••"before returning. But the create/update/duplicate/image-upload routes return the raw DB row straight from storage (each ends ingetById, which selects the full row), so the encrypted key blob (iv:ciphertext:authTaghex) is sent back to the client on every create, patch, duplicate, and connection-image upload. This contradicts the masking the codebase clearly intends and leaks the ciphertext into response bodies, the browser network tab, and any client-side log capture. The value is AES-GCM ciphertext, not plaintext — not directly usable without the on-disk encryption key, hence low severity — but it is still an unintended disclosure of a field the app otherwise treats as never-returnable, and it leaks key length/uniqueness and the fact that a key is set.How to reproduce (try it yourself)
POST /api/connectionswith a non-emptyapiKey.GET /api/connections/:idon the same id.You'll see: the POST response contains
apiKeyEncrypted: "<iv>:<cipher>:<tag>"(the real ciphertext) instead of the masked"••••••••". Same forPATCH /api/connections/:id(any field),POST /api/connections/:id/duplicate, andPOST /api/connections/:id/image. TheGETroute correctly returnsapiKeyEncrypted: "••••••••".Expected: all four mutation responses mask
apiKeyEncryptedidentically to the GET routes.Where it is
packages/server/src/routes/connections.routes.ts:POST /(lines 253-258,return created;),PATCH /:id(260-265,return updated;),POST /:id/image(286-288,return updated;),POST /:id/duplicate(329-333,return result;). Root cause inpackages/server/src/services/storage/connections.storage.ts:getByIdreturns the full row (lines 19-22), andcreate/update/duplicateallreturn this.getById(...)(lines 111/203/243). Masking already applied atconnections.storage.ts:16(list) andconnections.routes.ts:250(GET /:id). No response schema or onSend hook strips the field (app.ts:131-136only sets Cache-Control).What's happening
Masking of
apiKeyEncryptedis applied ad hoc only on the two GET handlers, not centralized in storage. The write handlers forwardgetById's full row, which includes the unmaskedapiKeyEncryptedcolumn, bypassing the masking the read paths apply.Suggested fix
Apply the SAME inline masking the GET route already uses (
connections.routes.ts:250) to the four write handlers, at the route layer only — do NOT move masking into storage/getById. Add one route-local null-safe helper near the top ofconnectionsRoutes(afterconst storage = ...):Then
return maskConnection(created);(POST /),return maskConnection(updated);(PATCH /:id — preserves the null→200 behavior since the helper passes null through), and after the existingif (!updated)/if (!result)404 guards,return maskConnection(updated);/return maskConnection(result);for the image and duplicate routes.Regression avoided: do NOT mask inside
getById()or any shared helper it feeds.getWithKey()(connections.storage.ts:25-28) is built ongetById()and decryptsapiKeyEncrypted— a masked value would decrypt to an empty key and silently send EMPTY API keys on every provider request (test, models, generate, agents, and all internal callers).duplicate()readsgetById()and copiesapiKeyEncryptedinto the new row — a masked value would permanently corrupt the cloned connection's stored key. The route-handler approach has neither problem:getById()keeps returning the raw row for internal decryption/duplication, and only the four client-facing responses get masked. Verified the client never readsapiKeyEncryptedback from a mutation response, so no round-trip breaks.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.