Skip to content

Commit 6fd72ba

Browse files
committed
fix(http): options not parsed accurately
1 parent 294b168 commit 6fd72ba

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

apps/sim/lib/core/security/input-validation.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { LookupAddress, LookupOptions } from 'dns'
12
import dns from 'dns/promises'
23
import http from 'http'
34
import https from 'https'
@@ -907,26 +908,37 @@ export async function secureFetchWithPinnedIP(
907908
const isIPv6 = resolvedIP.includes(':')
908909
const family = isIPv6 ? 6 : 4
909910

910-
const agentOptions = {
911+
const agentOptions: http.AgentOptions = {
911912
lookup: (
912913
_hostname: string,
913-
_options: unknown,
914-
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void
914+
options: LookupOptions,
915+
callback: (
916+
err: NodeJS.ErrnoException | null,
917+
address: string | LookupAddress[],
918+
family?: number
919+
) => void
915920
) => {
916-
callback(null, resolvedIP, family)
921+
if (options.all) {
922+
callback(null, [{ address: resolvedIP, family }])
923+
} else {
924+
callback(null, resolvedIP, family)
925+
}
917926
},
918927
}
919928

920-
const agent = isHttps
921-
? new https.Agent(agentOptions as https.AgentOptions)
922-
: new http.Agent(agentOptions as http.AgentOptions)
929+
const agent = isHttps ? new https.Agent(agentOptions) : new http.Agent(agentOptions)
930+
931+
// Remove accept-encoding since Node.js http/https doesn't auto-decompress
932+
// Headers are lowercase due to Web Headers API normalization in executeToolRequest
933+
const sanitizedHeaders = { ...options.headers }
934+
sanitizedHeaders['accept-encoding'] = undefined
923935

924936
const requestOptions: http.RequestOptions = {
925937
hostname: parsed.hostname,
926938
port,
927939
path: parsed.pathname + parsed.search,
928940
method: options.method || 'GET',
929-
headers: options.headers || {},
941+
headers: sanitizedHeaders,
930942
agent,
931943
timeout: options.timeout || 30000,
932944
}

0 commit comments

Comments
 (0)