From ef329de7624627f44c8c20edd0fd7c6b7ab2a29d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 6 Sep 2026 23:53:58 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[MEDIUM]=20?= =?UTF-8?q?Fix=20swallowed=20exception=20tracebacks=20in=20global=20except?= =?UTF-8?q?ion=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Explicitly log unhandled exceptions in the custom FastAPI Exception handler to prevent silent error swallowing due to bypassing Starlette's ServerErrorMiddleware. Co-authored-by: n24q02m <135627235+n24q02m@users.noreply.github.com> --- .jules/sentinel.md | 5 +++++ src/tacet/serve/server.py | 1 + 2 files changed, 6 insertions(+) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 80d5d5e..29fff2c 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -35,3 +35,8 @@ **Vulnerability:** The FastAPI application was missing the `Referrer-Policy` security header, which could leak sensitive path information or query parameters via the `Referer` header to external sites when navigating away from the application. **Learning:** Even when setting strict `Content-Security-Policy` and `X-Frame-Options`, `Referrer-Policy` is needed to prevent cross-origin information leakage on outbound requests. **Prevention:** Always include `Referrer-Policy: no-referrer` in the global security headers middleware to strictly drop referrer information on all outbound requests. + +## 2026-07-28 - Explicitly log exceptions in custom FastAPI exception handlers +**Vulnerability:** The global `Exception` handler bypassed Starlette's `ServerErrorMiddleware`, swallowing exceptions and blinding operators to critical server errors. +**Learning:** When overriding a global `Exception` handler in FastAPI/Starlette, the built-in exception logging is bypassed. +**Prevention:** Always explicitly log the exception (e.g., `log.error("Unhandled exception", exc_info=_exc)`) inside global exception handlers to preserve visibility. diff --git a/src/tacet/serve/server.py b/src/tacet/serve/server.py index 2df2279..8677968 100644 --- a/src/tacet/serve/server.py +++ b/src/tacet/serve/server.py @@ -357,6 +357,7 @@ async def add_security_headers(request: Request, call_next): @app.exception_handler(Exception) async def unhandled_exception_handler(request: Request, _exc: Exception) -> Response: + log.error("Unhandled server error", exc_info=_exc) response = PlainTextResponse("Internal Server Error", status_code=500) return _apply_security_headers(response, request.url.path)