security: sanitize Perplexity API error messages (CWE-200; re-impl of #103)#107
Open
jliounis wants to merge 1 commit into
Open
security: sanitize Perplexity API error messages (CWE-200; re-impl of #103)#107jliounis wants to merge 1 commit into
jliounis wants to merge 1 commit into
Conversation
Re-implementation of #103. Credit: @sebastiondev for the original analysis and patch. Problem ------- makeApiRequest, performChatCompletion, and performSearch previously embedded raw upstream details into thrown Error messages: throw new Error(`Network error while calling Perplexity API: ${error}`); throw new Error(`Perplexity API error: ${status} ${statusText}\n${errorText}`); throw new Error(`Failed to parse JSON response from Perplexity API: ${error}`); The MCP SDK returns thrown tool errors verbatim to remote callers in `result.content[].text`. Because this server can also run as an unauthenticated HTTP service bound to 0.0.0.0, a remote MCP client could trigger upstream failures and read back: - the upstream response body (provider internal traces, account hints) - raw exception text from the network layer (proxy/DNS details, etc.) - raw JSON-parse exception text (may include partial payloads) That is CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): medium severity, reachable via the HTTP transport, mitigable without losing operator visibility. Fix --- Separate operator diagnostics from caller-visible errors: - The full upstream body, parser exception, and network exception text are now logged server-side via the existing structured logger (writes to stderr; survives STDIO transport). - The Error that bubbles up to the MCP SDK now contains only a stable, generic, non-secret message: "Perplexity API error: <status> <statusText>" "Network error while calling Perplexity API" "Failed to parse JSON response from Perplexity API" "Failed to parse JSON response from Perplexity Search API" - Timeout and validation errors are unchanged (they were already sanitized). Tests ----- - Updated "should handle error text parse failures" to assert the new sanitized output and the absence of the underlying exception text. - Added 3 new CWE-200 regression tests: * JSON parse error must not leak parser exception text * Network error must not leak network exception text * Upstream 4xx/5xx must not leak the response body - npm test: 81 passed / 81 (was 78 on main). - npm run build: clean. Co-authored-by: @sebastiondev
rbuchmayer-pplx
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-implementation of the previously-closed #103. Credit: @sebastiondev for the original analysis and patch.
Vulnerability
CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor) — Medium severity.
makeApiRequest,performChatCompletion, andperformSearchpreviously embedded raw upstream details into thrownErrormessages:The MCP SDK returns thrown tool errors verbatim to remote callers in
result.content[].text. Because this server can also run as an unauthenticated HTTP service bound to0.0.0.0, a remote MCP client can trigger upstream failures and read back:Fix
Separate operator diagnostics from caller-visible errors:
logger(writes to stderr; survives STDIO transport).Errorthat bubbles up to the MCP SDK now contains only a stable, generic, non-secret message:Perplexity API error: <status> <statusText>Network error while calling Perplexity APIFailed to parse JSON response from Perplexity APIFailed to parse JSON response from Perplexity Search APITests
should handle error text parse failuresto assert the sanitized output and the absence of the underlying exception text.npm test: 81 passed / 81 (was 78 on main).npm run build: clean.Backward compatibility
"Perplexity API error: 401"etc. continues to work.