Skip to content

Commit 857521d

Browse files
fix: prevent exception details from leaking in API error responses (#2007)
* fix: removed str(e) in exceptions to prevent internals from leaking Signed-off-by: vchen7629 <chenvincent7629@gmail.com> * style: ruff autofix (auto) * fix: added missing status_code Signed-off-by: vchen7629 <chenvincent7629@gmail.com> * style: ruff autofix (auto) --------- Signed-off-by: vchen7629 <chenvincent7629@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 9c97ca5 commit 857521d

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

src/api/settings/endpoints.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ async def get_settings(
245245
langflow_port=str(LANGFLOW_PORT),
246246
)
247247

248-
except Exception as e:
249-
logger.error(f"Failed to retrieve settings: {str(e)}")
250-
return JSONResponse({"error": f"Failed to retrieve settings: {str(e)}"}, status_code=500)
248+
except Exception:
249+
logger.exception("Failed to retrieve settings")
250+
return JSONResponse({"error": "Failed to retrieve settings"}, status_code=500)
251251

252252

253253
async def update_settings(
@@ -785,12 +785,12 @@ async def update_settings(
785785
)
786786
return SettingsUpdateResponse(message="Configuration updated successfully")
787787

788-
except Exception as e:
789-
logger.error("Failed to update settings", error=str(e))
788+
except Exception:
789+
logger.exception("Failed to update settings")
790790
await TelemetryClient.send_event(
791791
Category.SETTINGS_OPERATIONS, MessageId.ORB_SETTINGS_UPDATE_FAILED
792792
)
793-
return JSONResponse({"error": f"Failed to update settings: {str(e)}"}, status_code=500)
793+
return JSONResponse({"error": "Failed to update settings"}, status_code=500)
794794

795795

796796
async def onboarding(
@@ -1126,13 +1126,10 @@ async def onboarding(
11261126
logger.info("Initializing OpenSearch index after onboarding configuration")
11271127
await init_index(opensearch_client, admin_username=admin_username)
11281128
logger.info("OpenSearch index initialization completed successfully")
1129-
except Exception as e:
1130-
logger.error(
1131-
"Failed to initialize OpenSearch index after onboarding",
1132-
error=str(e),
1133-
)
1129+
except Exception:
1130+
logger.exception("Failed to initialize OpenSearch index after onboarding")
11341131
return JSONResponse(
1135-
{"error": str(e)},
1132+
{"error": "Failed to initialize OpenSearch index after onboarding"},
11361133
status_code=500,
11371134
)
11381135

@@ -1528,9 +1525,9 @@ async def remove_filter(filter_id: str | None):
15281525
deleted_conversations=deleted_conversations_count,
15291526
)
15301527

1531-
except Exception as e:
1532-
logger.error("Failed to rollback onboarding configuration", error=str(e))
1533-
return JSONResponse({"error": f"Failed to rollback onboarding: {str(e)}"}, status_code=500)
1528+
except Exception:
1529+
logger.exception("Failed to rollback onboarding configuration")
1530+
return JSONResponse({"error": "Failed to rollback onboarding"}, status_code=500)
15341531

15351532

15361533
async def update_docling_preset(

0 commit comments

Comments
 (0)