Skip to content

Commit 145db9d

Browse files
fix(http): options not parsed accurately (#2914)
* fix(http): options not parsed accurately * fix lint * remove boilerplate code'
1 parent 294b168 commit 145db9d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dns from 'dns/promises'
22
import http from 'http'
33
import https from 'https'
4+
import type { LookupFunction } from 'net'
45
import { createLogger } from '@sim/logger'
56
import * as ipaddr from 'ipaddr.js'
67

@@ -907,26 +908,28 @@ export async function secureFetchWithPinnedIP(
907908
const isIPv6 = resolvedIP.includes(':')
908909
const family = isIPv6 ? 6 : 4
909910

910-
const agentOptions = {
911-
lookup: (
912-
_hostname: string,
913-
_options: unknown,
914-
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void
915-
) => {
911+
const lookup: LookupFunction = (_hostname, options, callback) => {
912+
if (options.all) {
913+
callback(null, [{ address: resolvedIP, family }])
914+
} else {
916915
callback(null, resolvedIP, family)
917-
},
916+
}
918917
}
919918

920-
const agent = isHttps
921-
? new https.Agent(agentOptions as https.AgentOptions)
922-
: new http.Agent(agentOptions as http.AgentOptions)
919+
const agentOptions: http.AgentOptions = { lookup }
920+
921+
const agent = isHttps ? new https.Agent(agentOptions) : new http.Agent(agentOptions)
922+
923+
// Remove accept-encoding since Node.js http/https doesn't auto-decompress
924+
// Headers are lowercase due to Web Headers API normalization in executeToolRequest
925+
const { 'accept-encoding': _, ...sanitizedHeaders } = options.headers ?? {}
923926

924927
const requestOptions: http.RequestOptions = {
925928
hostname: parsed.hostname,
926929
port,
927930
path: parsed.pathname + parsed.search,
928931
method: options.method || 'GET',
929-
headers: options.headers || {},
932+
headers: sanitizedHeaders,
930933
agent,
931934
timeout: options.timeout || 30000,
932935
}

0 commit comments

Comments
 (0)