mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2748] [Issue]: Cross-origin redirect in safeFetch re-sends provider API keys (TTS xi-api-key / image-gen Bearer) to the redirect target (key leakage) #1386
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#1386
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2748
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The shared
safeFetchhelper follows up to 5 HTTP redirects manually (redirect: "manual"+ self-issued fetch), but on each 3xx it re-issues the request to the newLocationhost without stripping the caller's auth headers. Because the redirect following is manual, the platform's normal cross-origin Authorization-stripping (which only applies to automaticredirect: "follow") is bypassed. Every TTS and image-generation provider call passes the user's plaintext API key in headers, so a provider/proxy that returns a cross-origin302(a malicious or compromised user-pasted base URL, or an on-path MITM over the permittedhttp:) receives the user's key. SSRF re-validation only blocks private/loopback/reserved IPs, not arbitrary public attacker hosts.This is one root cause (
safeFetch) feeding two call-site families; fixing it once fixes both subsystems.Sub-bug 1: Image-generation Bearer keys leaked (#18)
safeFetchdestructuresheadersonce (security.ts:542) and re-uses the sameheadersvariable for every redirect iteration. The 3xx branch (security.ts:561-570) validates the new URL andcontinues the loop without clearing/rewritingheaders. Image call sites build{ Authorization: \Bearer ${apiKey}` }(OpenAI generations ~677-685, xAI ~710-719, Stability multipart ~1065-1072, chat-completions/NovelAI ~1648-1660) and route throughimageFetch->safeFetch`.302 Location: https://attacker.example/.... Generate an image. The forwarded request to attacker.example carriesAuthorization: Bearer <user key>.redirect: "manual"-> security.ts:561-569 buildsnew URL(location)andcontinues with the sameheaders-> security.ts:554/555 re-sends Authorization to the redirect host.Sub-bug 2: TTS provider keys leaked (#68/#3-critic)
safeFetchmechanism. TTS speak/voice-list calls passxi-api-key(ElevenLabs, tts.routes.ts ~312-316),Authorization: Bearer(OpenAI ~318-322), orx-api-key+ Bearer (NanoGPT ~324-328) intosafeFetch. The POST body and method are also re-sent to the new host.http:). The redirect target receives the TTS provider key (and POST body).headersintosafeFetch-> security.ts:555-560 replays them on each redirect with no same-origin guard.Suggested Fix
In the
safeFetchredirect branch, when the redirect target's origin differs from the current request origin, drop sensitive request headers (Authorization,xi-api-key,x-api-key,api-key,Cookie) and the request body before following — mirroring browser/undici cross-origin credential stripping. Only retain credentials on same-origin redirects. Consider also constraining redirects to the originally-configured provider host.Verification checklist (all manual)
pnpm checkAffected files
packages/server/src/utils/security.tspackages/server/src/routes/tts.routes.tspackages/server/src/services/image/image-generation.tsAudit provenance
Found by a multi-agent static audit of the TTS/voice + image-generation subsystems (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified) against the merged
stagingtree. Severity: HIGH.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on PR #2747. safeFetch now tracks redirect state across manual redirects and, on a cross-origin hop, strips credential-like headers (Authorization/proxy auth/Cookie/xi-api-key/x-api-key/api-key) plus content headers and drops the request body before following. Same-origin redirects keep the original headers/body. This central fix covers the TTS and image-generation provider calls that route through safeFetch. Deferred full pnpm validation until the end of the issue sweep, per maintainer request.