fix: prevent exception diagnostics from leaking in API problem responses (#1405)

* Potential fix for code scanning alert no. 11: Information exposure through an exception

traceback should not be in client side code

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* fix: keep unexpected API error details private and test problem responses

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Normann
2026-10-14 15:22:22 +02:00
committed by GitHub
co-authored by Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
parent 49ea062dc8
commit 812aa3dda9
2 changed files with 96 additions and 7 deletions
+1 -7
View File
@@ -1,5 +1,4 @@
import html
import traceback
from dataclasses import dataclass
from typing import Optional, cast
@@ -8,8 +7,6 @@ from fastapi.exceptions import HTTPException, RequestValidationError
from fastapi.responses import JSONResponse
from loguru import logger
from akkudoktoreos.core.coreabc import get_config
@dataclass(slots=True)
class EOSProblem(Exception):
@@ -45,9 +42,6 @@ def _problem_response(
if cause is not None:
logger.exception(cause)
if get_config().logging.api_level in ("TRACE", "DEBUG"):
body["traceback"] = traceback.format_exception(cause)
return JSONResponse(
status_code=status,
media_type="application/problem+json",
@@ -86,7 +80,7 @@ async def unexpected_exception_handler(request: Request, exc: Exception) -> JSON
request=request,
status=500,
title="Internal Server Error",
detail=str(exc),
detail="An unexpected error occurred.",
cause=exc,
type="/problems/internal-server-error",
)