Repository navigation
fix(security): sanitize raw err.message in web executors + embeddings/search bodies (Rule #12) (#3494, #3495) #3573
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |||||
| } from "../config/providerHeaderProfiles.ts"; | ||||||
| import { sanitizeQwenThinkingToolChoice } from "../services/qwenThinking.ts"; | ||||||
| import { buildCosyHeadersForValidation } from "../services/qoderCli.ts"; | ||||||
| import { sanitizeErrorMessage } from "../utils/error.ts"; | ||||||
|
|
||||||
| function getAuthToken(credentials: ProviderCredentials): string { | ||||||
| if (typeof credentials.apiKey === "string" && credentials.apiKey.trim()) { | ||||||
|
|
@@ -230,7 +231,7 @@ export class QoderExecutor extends BaseExecutor { | |||||
| response: new Response( | ||||||
| JSON.stringify({ | ||||||
| error: { | ||||||
| message: `Qoder fetch error: ${error.message}`, | ||||||
| message: `Qoder fetch error: ${sanitizeErrorMessage(error.message)}`, | ||||||
|
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. Accessing
Suggested change
|
||||||
| type: "provider_error", | ||||||
| }, | ||||||
| }), | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { isDetailedLoggingEnabled } from "@/lib/db/detailedLogs"; | |||||
| import { getCallLogPipelineCaptureStreamChunks } from "@/lib/logEnv"; | ||||||
| import { toJsonErrorPayload } from "@/shared/utils/upstreamError"; | ||||||
| import { stripStaleEncodingHeaders } from "../utils/upstreamResponseHeaders.ts"; | ||||||
| import { sanitizeErrorMessage } from "../utils/error.ts"; | ||||||
|
|
||||||
| interface ClientRawRequest { | ||||||
| endpoint: string; | ||||||
|
|
@@ -339,7 +340,7 @@ export async function handleEmbedding({ | |||||
| return { | ||||||
| success: false, | ||||||
| status: 502, | ||||||
| error: `Embedding provider error: ${err.message}`, | ||||||
| error: `Embedding provider error: ${sanitizeErrorMessage(err.message)}`, | ||||||
|
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. Accessing
Suggested change
|
||||||
| }; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { safeOutboundFetch } from "@/shared/network/safeOutboundFetch"; | |||||
| import { Client } from "@modelcontextprotocol/sdk/client/index.js"; | ||||||
| import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; | ||||||
| import { z } from "zod"; | ||||||
| import { sanitizeErrorMessage } from "../utils/error.ts"; | ||||||
|
|
||||||
| // ── Types ──────────────────────────────────────────────────────────────── | ||||||
|
|
||||||
|
|
@@ -1164,7 +1165,7 @@ async function tryZaiMCPProvider( | |||||
| return { | ||||||
| success: false, | ||||||
| status: isTimeout ? 504 : 502, | ||||||
| error: `Search provider ${isTimeout ? "timeout" : "error"}: ${err.message}`, | ||||||
| error: `Search provider ${isTimeout ? "timeout" : "error"}: ${sanitizeErrorMessage(err.message)}`, | ||||||
|
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. Accessing
Suggested change
|
||||||
| }; | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -1434,7 +1435,7 @@ async function tryProvider( | |||||
| return { | ||||||
| success: false, | ||||||
| status: isTimeout ? 504 : 502, | ||||||
| error: `Search provider ${isTimeout ? "timeout" : "error"}: ${err.message}`, | ||||||
| error: `Search provider ${isTimeout ? "timeout" : "error"}: ${sanitizeErrorMessage(err.message)}`, | ||||||
|
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. Accessing
Suggested change
|
||||||
| }; | ||||||
| } | ||||||
| } | ||||||
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.
In the
isTlsUnavailbranch, castingerr as Errorand accessing.messagedirectly is unsafe iferris not an instance ofError(or is null/undefined). This could throw aTypeErrorand crash the handler. It is safer to use the same fallback check as the second branch.