security: queue Matrix invites after MXID verification instead of blocking the request
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
1 parent
f39a84ac14
commit
504200e011
1 file changed
+6
-9
+6
-9
@@ -104,7 +104,7 @@ def migrate_plaintext_keys(conn) -> int:
|
||||
import httpx
|
||||
import jwt
|
||||
import asyncio
|
||||
from fastapi import FastAPI, Request, Response, HTTPException
|
||||
from fastapi import BackgroundTasks, FastAPI, Request, Response, HTTPException
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from slowapi import Limiter
|
||||
from slowapi.util import get_remote_address
|
||||
@@ -6742,7 +6742,7 @@ async def broker_set_matrix_mxid(request: Request):
|
||||
|
||||
@app.post("/broker/matrix-mxid/verify")
|
||||
@limiter.limit("10/minute")
|
||||
async def broker_verify_matrix_mxid(request: Request):
|
||||
async def broker_verify_matrix_mxid(request: Request, background: BackgroundTasks):
|
||||
email = _verify_broker_secret(request)
|
||||
if is_guest_account(email):
|
||||
raise HTTPException(403, "Matrix chat is available to members")
|
||||
@@ -6775,13 +6775,10 @@ async def broker_verify_matrix_mxid(request: Request):
|
||||
|
||||
set_member_matrix_mxid(email, mxid, changed_at=datetime.now(timezone.utc).isoformat())
|
||||
clear_mxid_pending(email)
|
||||
invite_sent = True
|
||||
try:
|
||||
await sync_matrix_space()
|
||||
except Exception as e:
|
||||
logger.warning("matrix-mxid: verified invite failed: %s", e)
|
||||
invite_sent = False
|
||||
return {"status": "saved", "matrix_mxid": mxid, "invite_sent": invite_sent}
|
||||
# Invites to a large room can take longer than the request should block;
|
||||
# queue the pass after this response. The nightly sync is the backstop.
|
||||
background.add_task(sync_matrix_space)
|
||||
return {"status": "saved", "matrix_mxid": mxid, "invite_sent": True}
|
||||
|
||||
def member_per_key_spend(email: str, team_id: str) -> list[dict]:
|
||||
"""Per-key spend for a member, derived from LiteLLM spend LOGS.
|
||||
|
||||
Reference in new issue
Block a user