Repository navigation
feat: add API proxy port 10004 for OpenCode engine #1055
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 |
|---|---|---|
|
|
@@ -258,6 +258,35 @@ | |
| console.log('[API Proxy] GitHub Copilot proxy listening on port 10002'); | ||
| }); | ||
| } | ||
|
|
||
| // OpenCode API proxy (port 10004) — routes to Anthropic (default BYOK provider) | ||
| // OpenCode gets a separate port from Claude (10001) for per-engine rate limiting, | ||
| // metrics isolation, and future provider routing (OpenCode is BYOK and may route | ||
| // to different providers in the future based on model prefix). | ||
| if (ANTHROPIC_API_KEY) { | ||
| const opencodeServer = http.createServer((req, res) => { | ||
| if (req.url === '/health' && req.method === 'GET') { | ||
| res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
| res.end(JSON.stringify({ status: 'healthy', service: 'opencode-proxy' })); | ||
| return; | ||
| } | ||
|
|
||
| const logMethod = sanitizeForLog(req.method); | ||
| const logUrl = sanitizeForLog(req.url); | ||
| console.log(`[OpenCode Proxy] ${logMethod} ${logUrl}`); | ||
| console.log('[OpenCode Proxy] Injecting x-api-key header with ANTHROPIC_API_KEY'); | ||
| const anthropicHeaders = { 'x-api-key': ANTHROPIC_API_KEY }; | ||
| if (!req.headers['anthropic-version']) { | ||
| anthropicHeaders['anthropic-version'] = '2023-06-01'; | ||
| } | ||
| proxyRequest(req, res, 'api.anthropic.com', anthropicHeaders); | ||
| }); | ||
|
|
||
| opencodeServer.listen(10004, '0.0.0.0', () => { | ||
| console.log('[API Proxy] OpenCode proxy listening on port 10004 (-> Anthropic)'); | ||
| }); | ||
| } | ||
|
Comment on lines
+262
to
+288
|
||
|
|
||
| // Graceful shutdown | ||
| process.on('SIGTERM', () => { | ||
| console.log('[API Proxy] Received SIGTERM, shutting down gracefully...'); | ||
|
|
||
Check warning
Code scanning / CodeQL
Log injection Medium
Copilot Autofix
AI 8 months ago
In general, to fix log injection, all user-controlled data should be sanitized before logging: remove or normalize line breaks and control characters, optionally collapse or escape other whitespace that could visually obscure boundaries, and clearly delimit user input in log messages so operators can see what part is untrusted.
For this specific code, the best low-impact fix is:
sanitizeForLogto also strip Unicode line/paragraph separators and normalize tabs to spaces, while still removing ASCII control chars and limiting length to 200 characters.sanitizeForLogonreq.methodandreq.urlas already done."[OpenCode Proxy] method=%s url=%s"where the method and URL are enclosed in quotes. This doesn’t change functionality but makes the boundary between fixed text and user data explicit.Concretely in
containers/api-proxy/server.js:sanitizeForLogimplementation around lines 38–43 to:\u2028) and paragraph (\u2029) separators.console.log(`[OpenCode Proxy] ${logMethod} ${logUrl}`);console.log(`[OpenCode Proxy] method="${logMethod}" url="${logUrl}"`);No new imports are needed; all changes are inside the already-present helper and log call.