Skip to content

fix(python-fastapi): stop exposing exception details in API errors#117

Merged
cbullinger merged 4 commits into
mainfrom
fix/codeql-python-stack-trace
Jun 8, 2026
Merged

fix(python-fastapi): stop exposing exception details in API errors#117
cbullinger merged 4 commits into
mainfrom
fix/codeql-python-stack-trace

Conversation

@cbullinger

Copy link
Copy Markdown
Collaborator

Summary

Resolves 16 CodeQL py/stack-trace-exposure findings in movies.py by returning generic error messages to clients while logging full exceptions server-side.

Changes

  • Add server_error_response() in errorResponse.py (uses logger.exception())
  • Replace all str(e) in HTTP error payloads in movies.py with fixed messages
  • Harden get_embedding() Voyage AI error handling (generic VoyageAPIError messages + logging)
  • Remove exc.message from VoyageAPIError handler details in main.py

Test plan

Related

Made with Cursor

Add server_error_response() to log failures server-side and return
generic messages. Resolves CodeQL py/stack-trace-exposure alerts (#7-22).

Co-authored-by: Cursor <cursoragent@cursor.com>
@cbullinger cbullinger force-pushed the fix/codeql-python-stack-trace branch from 3761e51 to bae04ff Compare June 4, 2026 18:59
@cbullinger cbullinger changed the base branch from development to main June 4, 2026 18:59
@cbullinger cbullinger requested a review from Copilot June 5, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Remediates CodeQL py/stack-trace-exposure findings in the Python FastAPI mflix app by ensuring API responses don’t echo raw exception details, while preserving full exception context in server logs.

Changes:

  • Introduces a shared server_error_response() helper that logs exceptions and returns a generic error payload.
  • Replaces str(e) usage in multiple movies.py endpoints with fixed client-safe messages.
  • Tightens Voyage AI embedding error handling by logging SDK exceptions and returning generic VoyageAPIError messages; removes exc.message from the Voyage API error handler response.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
mflix/server/python-fastapi/src/utils/errorResponse.py Adds server_error_response() to centralize “log + generic 500 response” behavior.
mflix/server/python-fastapi/src/routers/movies.py Replaces exception-detail responses with server_error_response() and logs Voyage AI SDK errors in get_embedding().
mflix/server/python-fastapi/main.py Removes exc.message from VoyageAPIError handler payload to avoid leaking internal details.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mflix/server/python-fastapi/main.py Outdated
Comment thread mflix/server/python-fastapi/src/routers/movies.py
cbullinger and others added 2 commits June 5, 2026 09:10
Use VoyageAPIError.status_code in the global handler and wrap cursor
iteration in get_all_movies so database errors are logged consistently.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
).embeddings
return embeddings[0]
except voyage_error.AuthenticationError as e:
except voyage_error.AuthenticationError:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VoyageAuthError is the one path that still has no server-side logging. voyage_error.AuthenticationError is caught here and re-raised as VoyageAuthError, but neither this site nor the voyage_auth_error_handler in main.py calls logger.exception(). A rotated or revoked key would produce no trace in the logs. Consider adding a log call before the re-raise:

except voyage_error.AuthenticationError:
    logger.exception("Voyage AI authentication failed")
    raise VoyageAuthError("Invalid Voyage AI API key. Please check your VOYAGE_API_KEY in the .env file")

@dacharyc dacharyc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggested improvement, but overall LGTM. ✅

Add logger.exception before raising VoyageAuthError so revoked or
invalid API keys leave a trace in server logs. Addresses PR #117 review.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cbullinger

Copy link
Copy Markdown
Collaborator Author

Added logger.exception("Voyage AI authentication failed") before raising VoyageAuthError in get_embedding() — pushed in 48c91c1. Matches the logging pattern used for the other Voyage error paths.

@cbullinger cbullinger merged commit 660a48a into main Jun 8, 2026
6 checks passed
@cbullinger cbullinger deleted the fix/codeql-python-stack-trace branch June 8, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants