Skip to content

fix: prevent exception details from leaking in API error responses#2007

Open
Vchen7629 wants to merge 4 commits into
mainfrom
endpoint-raw-exception-leaks
Open

fix: prevent exception details from leaking in API error responses#2007
Vchen7629 wants to merge 4 commits into
mainfrom
endpoint-raw-exception-leaks

Conversation

@Vchen7629

@Vchen7629 Vchen7629 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Changes

  • Updates src/api/settings/endpoints.py to prevent api detail leakage

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling across settings and onboarding flows.
    • Users now see generic error messages when settings retrieval, settings updates, onboarding initialization, or onboarding rollback fail.
    • Detailed exception information is no longer exposed in HTTP responses, while errors continue to be recorded in logs for troubleshooting.

@Vchen7629 Vchen7629 requested a review from lucaseduoli July 2, 2026 19:32
@github-actions github-actions Bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. labels Jul 2, 2026
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch endpoint-raw-exception-leaks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c8cb9f1f-3268-4996-ac03-f316a7cb14df

📥 Commits

Reviewing files that changed from the base of the PR and between aac2eb8 and 08d5c41.

📒 Files selected for processing (1)
  • src/api/settings/endpoints.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api/settings/endpoints.py

Walkthrough

Four settings/onboarding exception handlers now log tracebacks server-side and return generic 500 JSON error messages instead of exposing raw exception text.

Changes

Exception message redaction

Layer / File(s) Summary
Redact exception text in error handlers
src/api/settings/endpoints.py
get_settings, update_settings, onboarding OpenSearch initialization, and rollback_onboarding now use logger.exception and generic 500 JSON errors instead of including exception messages.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

Suggested labels: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main security fix to stop leaking exception details in API error responses.
Linked Issues check ✅ Passed The changes address the four reported handlers by replacing raw exception text with generic responses and server-side exception logging.
Out of Scope Changes check ✅ Passed The PR stays focused on the linked security fix in src/api/settings/endpoints.py with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch endpoint-raw-exception-leaks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/api/settings/endpoints.py (1)

1000-1005: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Same CodeQL exception-leak pattern remains unfixed in adjacent onboarding handlers.

Within this same onboarding function, two other except blocks still return str(e) directly to the client: the provider-validation failure at line 1003 (JSONResponse({"error": str(e)}, status_code=400)) and the outer catch-all at lines 1259-1263 (logger.error(..., error=str(e)) plus JSONResponse({"error": str(e)}, status_code=500)). These weren't in the four CodeQL-flagged lines this PR targets, but they leak the same class of internal exception details (e.g. provider auth errors) to clients.

Also applies to: 1258-1264

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/api/settings/endpoints.py` around lines 1000 - 1005, The onboarding
handler still leaks raw exception text in adjacent exception paths; update the
provider-validation and outer catch-all branches in onboarding to avoid
returning or logging str(e) directly to clients. Use the same error-handling
pattern as the fixed CodeQL spots by replacing the JSONResponse({"error":
str(e)}) and logger.error(..., error=str(e)) usage with a generic client-facing
message while preserving the detailed exception only in internal logs, and
locate the affected code in the onboarding function’s except blocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/settings/endpoints.py`:
- Around line 1129-1133: The OpenSearch onboarding failure path in the exception
handler is returning a default HTTP 200 because the JSONResponse in the
onboarding initialization block omits an explicit status code. Update the except
Exception branch around the OpenSearch initialization logic to return the same
error payload from JSONResponse with status_code=500 so the client sees a real
server error; use the existing logger.exception message and the JSONResponse
call in that handler as the place to fix it.

---

Outside diff comments:
In `@src/api/settings/endpoints.py`:
- Around line 1000-1005: The onboarding handler still leaks raw exception text
in adjacent exception paths; update the provider-validation and outer catch-all
branches in onboarding to avoid returning or logging str(e) directly to clients.
Use the same error-handling pattern as the fixed CodeQL spots by replacing the
JSONResponse({"error": str(e)}) and logger.error(..., error=str(e)) usage with a
generic client-facing message while preserving the detailed exception only in
internal logs, and locate the affected code in the onboarding function’s except
blocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a301591e-49a2-4709-a07f-3bc6cdc80932

📥 Commits

Reviewing files that changed from the base of the PR and between 4f104ec and aac2eb8.

📒 Files selected for processing (1)
  • src/api/settings/endpoints.py

Comment thread src/api/settings/endpoints.py
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026
@github-actions github-actions Bot added the lgtm label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: Avoid leaking raw exception messages in API 500 error responses (CodeQL)

2 participants