mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2656] [Issue]: Providers send auth headers built from empty/blank API keys (decrypt failure or keyless endpoint) → silent 401s #1307
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#1307
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 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2656
Originally assigned to: @kolacheee on GitHub.
Summary
The LLM provider adapters build their auth headers unconditionally from the connection's API key string. When that string is empty — either because
decryptApiKey()failed to decrypt a stored key, or because the connection is intentionally keyless (local/custom endpoint) — the outbound request still carries a blank credential (Authorization: Bearer/x-api-key:/x-goog-api-key:), producing opaque 401s on every generation with no actionable signal to the user.Expected behavior
Authorization/x-api-keyheader should be sent at all — a blank credential is worse than none.Actual behavior
decryptApiKey()returns""both when the stored value is empty and when decryption throws, logging only a server-sidelogger.warn.""straight intocreateLLMProvider()with no emptiness guard.How it breaks the pipeline
Code trace (staging @
b826f8f4):decryptApiKey()—packages/server/src/utils/crypto.ts:65—if (!encrypted) return "";(line 66) and thecatch { logger.warn(...); return ""; }(lines 78–82) both yield"". The only difference between "no key" and "key undecryptable" is a warn log.packages/server/src/services/storage/connections.storage.ts(getWithKey,getDefaultForAgents,getDefaultForImageGeneration,listRandomPool) forward the decrypted value without an emptiness check.packages/server/src/services/llm/providers/openai.provider.ts:439→Authorization: \Bearer ${this.apiKey}`(insidebuildHeaders()at:436`)packages/server/src/services/llm/providers/anthropic.provider.ts:280and:437→"x-api-key": this.apiKeypackages/server/src/services/llm/providers/google.provider.ts:140,:407,:567→"x-goog-api-key": ...Result: the request goes out with an empty token; the API rejects it with 401; the failure is indistinguishable from a wrong key.
Steps to reproduce
Manifestation A — decrypt failure (high impact):
<DATA_DIR>/.encryption-key).<DATA_DIR>/.encryption-key, moveDATA_DIR, or set/unsetENCRYPTION_KEYto a different value; restart the server.Authorization/x-api-keyheader → 401. The UI reports a generic auth failure; only a[CRYPTO] Failed to decrypt API keywarn appears server-side.Manifestation B — keyless endpoint (low impact):
Authorization: Bearer(empty token); some local servers/proxies reject the malformed header.Suggested fix
decryptApiKey(), distinguish "empty stored key" from "decrypt failure." On decrypt failure, throw or return a typed sentinel so callers can surface a clear "key could not be decrypted — re-enter it" error instead of silently sending a blank credential.Authorization/x-api-key/x-goog-api-keyfor blank keys) so keyless endpoints get a clean request.apiKeyEncryptedbut the decrypted key is empty, refuse to send and surface the decrypt error.Environment
b826f8f4)Additional context
Identified via a systematic source-level review of the connection-settings + preset → LLM-request pipeline on the staging branch; file/line references are against
b826f8f4. The decrypt-failure manifestation is especially likely after a reinstall, moving the data directory, or changingENCRYPTION_KEY. Filed alongside a set of related pipeline issues.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: