Files
letta-server/letta/server/rest_api/middleware/check_password.py
Kian Jones b8e9a80d93 merge this (#4759)
* wait I forgot to comit locally

* cp the entire core directory and then rm the .git subdir
2025-09-17 15:47:40 -07:00

25 lines
852 B
Python

from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
class CheckPasswordMiddleware(BaseHTTPMiddleware):
def __init__(self, app, password: str):
super().__init__(app)
self.password = password
async def dispatch(self, request, call_next):
# Exclude health check endpoint from password protection
if request.url.path in {"/v1/health", "/v1/health/", "/latest/health/"}:
return await call_next(request)
if (
request.headers.get("X-BARE-PASSWORD") == f"password {self.password}"
or request.headers.get("Authorization") == f"Bearer {self.password}"
):
return await call_next(request)
return JSONResponse(
content={"detail": "Unauthorized"},
status_code=401,
)