security: image MCP fails closed when the member's own key is absent
This commit is contained in:
1 parent
14b61e24da
commit
69ba4346cf
3 files changed
+31
-19
No files matched your search
@@ -322,14 +322,14 @@ needed.
|
||||
is deliberately NOT in the chat picker (image models are not chat models;
|
||||
chat-calling it was the source of the old 500s).
|
||||
- **Image generation — two paths**:
|
||||
1. **MCP tool (default, no key ever)**: `inference-image` server (tool
|
||||
`generate_image`) — members select it in the composer's **+** palette
|
||||
and just ask. Per-member billing via `customUserVars.IC_API_KEY` (seeded
|
||||
from the portal) + `env: IC_API_KEY: "{{IC_API_KEY}}"`; a system-key
|
||||
fallback (`system-image-fallback`, $5/30d) covers the rare empty-value
|
||||
case. The `customUserVars` gate blocks a not-yet-seeded member until the
|
||||
next sync (≤10 min) — accepted as a short delay over billing everything
|
||||
to the system account.
|
||||
1. **MCP tool (default)**: `inference-image` server (tool `generate_image`)
|
||||
— members select it in the composer's **+** palette and just ask.
|
||||
Per-member billing via `customUserVars.IC_API_KEY` (seeded from the
|
||||
portal) + `env: IC_API_KEY: "{{IC_API_KEY}}"`. **Fail-closed:** the co-op
|
||||
system key is not passed into per-user MCP processes at all, so a missing
|
||||
member key returns a message pointing at the dashboard instead of billing
|
||||
the co-op account. The `customUserVars` gate blocks a not-yet-seeded
|
||||
member until the next sync (≤10 min).
|
||||
2. **Agent tool**: LibreChat's built-in "OpenAI Image Tools" (env
|
||||
`IMAGE_GEN_OAI_BASEURL`/`IMAGE_GEN_OAI_MODEL` → gateway; no admin key,
|
||||
members paste their own). Note LibreChat v0.8.8 renders the generated
|
||||
|
||||
+3
-1
@@ -236,5 +236,7 @@ mcpServers:
|
||||
description: "Auto-loaded from your membership — no action needed."
|
||||
sensitive: true
|
||||
env:
|
||||
# ONLY the member's own key. The co-op system key is deliberately not
|
||||
# passed into per-user MCP processes: a missing member key must fail
|
||||
# closed, never bill image spend to the co-op account.
|
||||
IC_API_KEY: "{{IC_API_KEY}}"
|
||||
SYSTEM_IMAGE_KEY: "${SYSTEM_IMAGE_KEY}"
|
||||
+20
-10
@@ -37,16 +37,26 @@ def log(msg):
|
||||
|
||||
|
||||
def tool_generate_image(args):
|
||||
# Seamless: use the member's own key if LibreChat injected one; otherwise
|
||||
# fall back to the co-op's SYSTEM key (so a member who has never been
|
||||
# seeded — e.g. right after first login — still generates an image,
|
||||
# billed to the system account). Only if both are absent send keyless.
|
||||
key = (
|
||||
os.environ.get("IC_API_KEY")
|
||||
or os.environ.get("SYSTEM_IMAGE_KEY")
|
||||
or ""
|
||||
).strip()
|
||||
auth_header = {"Authorization": f"Bearer {key}"} if key else {}
|
||||
# FAIL CLOSED: image spend bills to the member's own LiteLLM team budget.
|
||||
# LibreChat injects IC_API_KEY per user (customUserVars + env). If it is
|
||||
# missing — the member has not been seeded yet, or their key was never
|
||||
# saved — refuse rather than falling back to a co-op account key. A silent
|
||||
# fallback would charge the co-op for a member action and hide the missing
|
||||
# key from the person who can fix it.
|
||||
key = (os.environ.get("IC_API_KEY") or "").strip()
|
||||
if not key:
|
||||
return {
|
||||
"content": [{
|
||||
"type": "text",
|
||||
"text": (
|
||||
"No co-op API key is attached to this session yet. "
|
||||
f"Create one at {DASHBOARD_URL}, save it in the MCP panel, "
|
||||
"then try again."
|
||||
),
|
||||
}],
|
||||
"isError": True,
|
||||
}
|
||||
auth_header = {"Authorization": f"Bearer {key}"}
|
||||
|
||||
prompt = str(args.get("prompt") or "").strip()
|
||||
if not prompt:
|
||||
|
||||
Reference in new issue
Block a user