-
Notifications
You must be signed in to change notification settings - Fork 0
π Fix HIGH SEVERITY Security Vulnerabilities - Flask Debug Mode & Information Exposure #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,20 @@ | |
| # Note: Avoid monkey-patching httpx internals. Tests should handle httpx.StreamConsumed | ||
| # or public APIs directly when dealing with closed file objects. | ||
|
|
||
| def sanitize_exception(exc: Exception) -> str: | ||
| """Sanitize exception messages to prevent information exposure.""" | ||
| # Only expose safe, generic error messages | ||
| if isinstance(exc, ValidationError): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line uses |
||
| return "Validation error occurred" | ||
| elif isinstance(exc, ValueError): | ||
| return "Invalid value provided" | ||
| elif isinstance(exc, KeyError): | ||
| return "Missing required field" | ||
| elif isinstance(exc, TypeError): | ||
| return "Type mismatch error" | ||
| else: | ||
| return "Internal server error" | ||
|
|
||
| # Global AI models (loaded on startup) | ||
| emotion_detector = None | ||
| text_summarizer = None | ||
|
|
@@ -1237,7 +1251,7 @@ async def chat_websocket(websocket: WebSocket, token: str = Query(None)) -> None | |
| exc, | ||
| exc_info=True, | ||
| ) | ||
| response["summary_error"] = str(exc) | ||
| response["summary_error"] = sanitize_exception(exc) | ||
|
|
||
| await websocket.send_json(response) | ||
| except WebSocketDisconnect: | ||
|
|
@@ -1717,7 +1731,7 @@ async def batch_transcribe_voice( | |
| "file_index": i, | ||
| "filename": audio_file.filename, | ||
| "success": False, | ||
| "error": str(exc) | ||
| "error": sanitize_exception(exc) | ||
| }) | ||
|
|
||
| processing_time = (time.time() - start_time) * 1000 | ||
|
|
@@ -1921,7 +1935,7 @@ async def websocket_realtime_processing(websocket: WebSocket, token: str = Query | |
| except Exception as exc: | ||
| await websocket.send_json({ | ||
| "type": "error", | ||
| "message": str(exc) | ||
| "message": sanitize_exception(exc) | ||
| }) | ||
| else: | ||
| await websocket.send_json({ | ||
|
|
@@ -2031,7 +2045,7 @@ async def detailed_health_check( | |
| except Exception as exc: | ||
| health_status = "degraded" | ||
| issues.append(f"Emotion detection model error: {exc}") | ||
| model_checks["emotion_detection"] = {"status": "error", "error": str(exc)} | ||
| model_checks["emotion_detection"] = {"status": "error", "error": sanitize_exception(exc)} | ||
|
|
||
| if text_summarizer is None: | ||
| health_status = "degraded" | ||
|
|
@@ -2045,7 +2059,7 @@ async def detailed_health_check( | |
| except Exception as exc: | ||
| health_status = "degraded" | ||
| issues.append(f"Text summarization model error: {exc}") | ||
| model_checks["text_summarization"] = {"status": "error", "error": str(exc)} | ||
| model_checks["text_summarization"] = {"status": "error", "error": sanitize_exception(exc)} | ||
|
|
||
| if voice_transcriber is None: | ||
| health_status = "degraded" | ||
|
|
@@ -2074,9 +2088,9 @@ async def detailed_health_check( | |
| "status": "healthy" if cpu_percent < 90 and memory.percent < 90 else "warning" | ||
| } | ||
| except Exception as exc: | ||
| system_checks = {"status": "error", "error": str(exc)} | ||
| system_checks = {"status": "error", "error": sanitize_exception(exc)} | ||
| health_status = "degraded" | ||
| issues.append(f"System check failed: {exc}") | ||
| issues.append("System check failed: Internal error") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Loss of original error details in health check issues list. Retain the original exception message in logs or a secure admin-only field to aid debugging, while keeping the public message generic. |
||
|
|
||
| return { | ||
| "status": health_status, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
logmethod's signature was changed to includeself, but it is still decorated with@staticmethodon the preceding line. A static method does not receive the instance as the first argument, so this will cause aTypeErrorat runtime. To fix this, the@staticmethoddecorator should be removed, makingloga regular instance method.