Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const decartClientOptionsSchema = z
baseUrl: z.url().optional(),
proxy: proxySchema.optional(),
integration: z.string().optional(),
queryParams: z.any().optional(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zod schema uses z.any() instead of typed record

Medium Severity

The Zod schema uses z.any() for queryParams but the TypeScript type declares it as Record<string, string>. This validation gap means the schema accepts values that don't match the expected type (e.g., nested objects, numbers, arrays). When spread into URLSearchParams, non-string values will be coerced via .toString(), causing objects to become [object Object] in the URL. The schema could use z.record(z.string(), z.string()).optional() to match the type.

Fix in Cursor Fix in Web

})
.refine(
(data) => {
Expand All @@ -72,12 +73,16 @@ export type DecartClientOptions =
apiKey?: never;
baseUrl?: string;
integration?: string;
/** Additional query parameters to append to the WebSocket connection URL */
queryParams?: Record<string, string>;
}
| {
proxy?: never;
apiKey?: string;
baseUrl?: string;
integration?: string;
/** Additional query parameters to append to the WebSocket connection URL */
queryParams?: Record<string, string>;
};

/**
Expand Down Expand Up @@ -145,7 +150,7 @@ export const createDecartClient = (options: DecartClientOptions = {}) => {
} else {
baseUrl = parsedOptions.data.baseUrl || "https://api.decart.ai";
}
const { integration } = parsedOptions.data;
const { integration, queryParams } = parsedOptions.data;

// Realtime (WebRTC) always requires direct API access with API key
// Proxy mode is only for HTTP endpoints (process, queue, tokens)
Expand All @@ -155,6 +160,7 @@ export const createDecartClient = (options: DecartClientOptions = {}) => {
baseUrl: wsBaseUrl,
apiKey: apiKey || "",
integration,
queryParams,
});

const process = createProcessClient({
Expand Down
12 changes: 10 additions & 2 deletions packages/sdk/src/realtime/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type RealTimeClientOptions = {
baseUrl: string;
apiKey: string;
integration?: string;
/** Additional query parameters to append to the WebSocket connection URL */
queryParams?: Record<string, string>;
};

const realTimeClientInitialStateSchema = modelStateSchema;
Expand Down Expand Up @@ -90,7 +92,7 @@ export type RealTimeClient = {
};

export const createRealTimeClient = (opts: RealTimeClientOptions) => {
const { baseUrl, apiKey, integration } = opts;
const { baseUrl, apiKey, integration, queryParams } = opts;

const connect = async (
stream: MediaStream | null,
Expand Down Expand Up @@ -141,8 +143,14 @@ export const createRealTimeClient = (opts: RealTimeClientOptions) => {
: undefined;

const url = `${baseUrl}${options.model.urlPath}`;
// Build query string with api_key, model, and any additional query params
const urlParams = new URLSearchParams({
api_key: apiKey,
model: options.model.name,
...(queryParams || {}),
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query params can override reserved URL parameters

Medium Severity

The queryParams spread happens after api_key and model in the object passed to URLSearchParams. In JavaScript object spread, later properties override earlier ones. If queryParams contains api_key or model keys, they will silently replace the SDK-configured values, potentially causing authentication failures or model mismatches where the URL path uses one model but the query parameter specifies another.

Fix in Cursor Fix in Web

const webrtcManager = new WebRTCManager({
webrtcUrl: `${url}?api_key=${apiKey}&model=${options.model.name}`,
webrtcUrl: `${url}?${urlParams.toString()}`,
apiKey,
sessionId,
fps: options.model.fps,
Expand Down