[PR #11711] fix: security vulnerabilities and bug fixes #13902

Closed
opened 2026-02-16 18:18:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11711

State: closed
Merged: No


Summary

This PR addresses several security vulnerabilities and bugs discovered during a comprehensive code review:

Security Fixes

  • Critical: Remove code injection vulnerability in debug agent - The parseToolParams function was using new Function() to evaluate user input when JSON parsing failed, allowing arbitrary code execution. Now only accepts valid JSON.

  • High: Fix XSS vulnerability in OAuth callback - Error messages from OAuth providers were being interpolated directly into HTML without escaping. Added proper HTML escaping to prevent XSS attacks.

Bug Fixes

  • High: Fix race condition in OAuth cancelPending - The cancelPending function was using mcpName as the key to lookup pending auths, but pendingAuths uses oauthState as the key. Fixed to correctly iterate and match by mcpName.

  • Medium: Fix unhandled exception in read tool - fs.readdirSync was being called without error handling. Now wrapped in try-catch to return empty array instead of throwing when directory doesn't exist.

Files Changed

  • packages/opencode/src/cli/cmd/debug/agent.ts - Remove new Function() eval
  • packages/opencode/src/mcp/oauth-callback.ts - Add HTML escaping + fix cancelPending
  • packages/opencode/src/mcp/index.ts - Pass mcpName to waitForCallback
  • packages/opencode/src/tool/read.ts - Safe directory listing

Testing

  • All 841 tests pass
  • TypeScript typecheck passes for all 12 packages

Checklist

  • Code follows project style guidelines
  • All tests pass
  • No breaking changes
  • Security vulnerabilities addressed
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11711 **State:** closed **Merged:** No --- ## Summary This PR addresses several security vulnerabilities and bugs discovered during a comprehensive code review: ### Security Fixes - **Critical: Remove code injection vulnerability in debug agent** - The `parseToolParams` function was using `new Function()` to evaluate user input when JSON parsing failed, allowing arbitrary code execution. Now only accepts valid JSON. - **High: Fix XSS vulnerability in OAuth callback** - Error messages from OAuth providers were being interpolated directly into HTML without escaping. Added proper HTML escaping to prevent XSS attacks. ### Bug Fixes - **High: Fix race condition in OAuth cancelPending** - The `cancelPending` function was using `mcpName` as the key to lookup pending auths, but `pendingAuths` uses `oauthState` as the key. Fixed to correctly iterate and match by `mcpName`. - **Medium: Fix unhandled exception in read tool** - `fs.readdirSync` was being called without error handling. Now wrapped in try-catch to return empty array instead of throwing when directory doesn't exist. ## Files Changed - `packages/opencode/src/cli/cmd/debug/agent.ts` - Remove `new Function()` eval - `packages/opencode/src/mcp/oauth-callback.ts` - Add HTML escaping + fix cancelPending - `packages/opencode/src/mcp/index.ts` - Pass mcpName to waitForCallback - `packages/opencode/src/tool/read.ts` - Safe directory listing ## Testing - All 841 tests pass - TypeScript typecheck passes for all 12 packages ## Checklist - [x] Code follows project style guidelines - [x] All tests pass - [x] No breaking changes - [x] Security vulnerabilities addressed
yindo added the pull-request label 2026-02-16 18:18:43 -05:00
yindo closed this issue 2026-02-16 18:18:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13902