feat: tts proxy to forward request to openai tts server#2030
feat: tts proxy to forward request to openai tts server#2030
Conversation
| @@ -0,0 +1,3 @@ | |||
| """ | |||
There was a problem hiding this comment.
建议整体放到 openai_tts2_python/examples/openai_tts_proxy 目录下
Code Review: TTS Proxy ServerThank you for this contribution! Overall, this is a well-structured HTTP proxy implementation. Below are my findings across code quality, potential issues, performance, security, and test coverage. ✅ Strengths
🔴 Critical Issues1. Security: API Key Exposure RiskLocation: The proxy forwards the Authorization header from environment variables if not present in requests. This could expose API keys in logs or to unauthorized clients. Recommendation:
# Current code (line 97-98)
if "authorization" not in headers and OPENAI_API_KEY:
headers["authorization"] = f"Bearer {OPENAI_API_KEY}"
# Recommended approach
if "authorization" not in headers:
logger.error("Missing Authorization header in request")
return Response(
content="Authorization header is required",
status_code=401,
)2. Security: No Input ValidationLocation: The proxy accepts and forwards any request body without validation. This could be exploited to:
Recommendation: 3. Resource Leak: Stream Context Not Always Cleaned UpLocation: If an exception occurs between Recommendation: async def _proxy_to_openai(request: Request):
stream_context = None
try:
# ... existing code ...
stream_context = http_client.stream(...)
response = await stream_context.__aenter__()
# ... rest of logic ...
except Exception as e:
logger.error(f"Error: {e}")
raise
finally:
if stream_context:
try:
await stream_context.__aexit__(None, None, None)
except Exception:
pass
|
9be0564 to
c4f8b85
Compare
PR Review: TTS Proxy to Forward Request to OpenAI TTS ServerSummaryThis PR adds an OpenAI TTS proxy server that forwards requests from TTS clients to the OpenAI API. The proxy is implemented as a FastAPI application and is located in the examples folder of the Code Quality & Best Practices✅ Strengths
|
| Priority | Issue | Location |
|---|---|---|
| 🔴 HIGH | API key logging security | proxy_server.py:82-108 |
| 🟡 MEDIUM | Stream context management | proxy_server.py:114-147 |
| 🟡 MEDIUM | Missing input validation | Throughout |
| 🟡 MEDIUM | Silent error swallowing | proxy_server.py:205-222 |
| 🟡 MEDIUM | No test coverage | Entire PR |
| 🟢 LOW | HTTP/2 configuration | proxy_server.py:38 |
Recommendations
Must Fix Before Merge
- Improve sensitive data masking in logs
- Add proper async context manager usage
- Add at least basic test coverage
Should Fix
- Add input validation
- Log exceptions instead of silently catching them
- Clarify production readiness in documentation
Consider
- Make HTTP/2 configurable
- Add rate limiting
- Reduce logging verbosity or make it configurable
Conclusion
This is a useful addition to the TEN framework that provides a practical solution for forwarding TTS requests to OpenAI. The code is generally well-written and follows good async patterns. However, there are security concerns around logging, missing test coverage, and some error handling improvements needed before this should be merged.
Overall Assessment: Approve with changes requested ✋
Please address the high-priority security issues and add basic test coverage before merging.
No description provided.