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
+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