Files
romm/backend/endpoints/logs.py
Georges-Antoine Assi f522d3959b fix(logs): keep password reset links out of the log viewer buffer (#5343)
When SMTP is off or sending fails, the reset link is logged so an admin
can read it from stdout and pass it on. LogStreamHandler copied that
record into the Redis buffer behind GET /api/logs and the log socket,
which any logs.read holder can see, and logs.read is not admin-only.

Records logged with extra=STDOUT_ONLY now skip LogStreamHandler, and the
reset link uses it. The invite flow already logs only the token id.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 07:43:53 -04:00

42 lines
1.3 KiB
Python

from fastapi import HTTPException, Request, status
from config import DISABLE_LOGS_VIEWER
from decorators.auth import protected_route
from endpoints.responses.log import LogEntrySchema
from endpoints.sockets.logs import get_recent_logs
from handler.auth.constants import Scope
from logger.log_stream_handler import LOG_BUFFER_SIZE
from utils.router import APIRouter
router = APIRouter(
prefix="/logs",
tags=["logs"],
)
# Largest backfill the buffer holds, derived from the producer's ring buffer
# so the two never drift.
MAX_LOG_LIMIT = LOG_BUFFER_SIZE
@protected_route(router.get, "", [Scope.LOGS_READ])
async def get_logs(
request: Request, limit: int = MAX_LOG_LIMIT
) -> list[LogEntrySchema]:
"""Return the most recent backend log lines for backfill.
Args:
request (Request): FastAPI Request object.
limit (int): Maximum number of recent lines to return.
Returns:
list[LogEntrySchema]: Recent log lines, oldest-first.
"""
if DISABLE_LOGS_VIEWER:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Logs viewer is disabled"
)
bounded = max(1, min(limit, MAX_LOG_LIMIT))
entries = await get_recent_logs(bounded)
return [LogEntrySchema(**entry) for entry in entries]