fix(api): access log keeps the mcp path but not its query, the token rode in it
This commit is contained in:
1 parent
283eab1eb0
commit
869f8291fb
2 files changed
+22
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import logging
|
||||
|
||||
QUERYLESS_PREFIXES = ("/mcp",)
|
||||
_PATH_ARG = 2
|
||||
|
||||
|
||||
class DropQueryFilter(logging.Filter):
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
args = record.args
|
||||
if isinstance(args, tuple) and len(args) > _PATH_ARG:
|
||||
path = str(args[_PATH_ARG])
|
||||
if path.startswith(QUERYLESS_PREFIXES):
|
||||
bare = path.partition("?")[0]
|
||||
record.args = (*args[:_PATH_ARG], bare, *args[_PATH_ARG + 1 :])
|
||||
return True
|
||||
|
||||
|
||||
def hide_mcp_query() -> None:
|
||||
logging.getLogger("uvicorn.access").addFilter(DropQueryFilter())
|
||||
@@ -9,6 +9,7 @@ from fastapi.responses import FileResponse, RedirectResponse
|
||||
from fastmcp.utilities.lifespan import combine_lifespans
|
||||
from starlette.applications import Starlette
|
||||
|
||||
from api.access_log import hide_mcp_query
|
||||
from api.auth import BearerAuthMiddleware
|
||||
from api.mcp.server import mcp
|
||||
from api.realtime import hub
|
||||
@@ -45,6 +46,8 @@ if env.auth.token is None:
|
||||
raise RuntimeError(msg)
|
||||
_token = env.auth.token.get_secret_value()
|
||||
|
||||
hide_mcp_query()
|
||||
|
||||
mcp_app = mcp.http_app(path="/")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user