Skip to content
Merged
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
25 changes: 14 additions & 11 deletions apps/sim/lib/core/security/input-validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dns from 'dns/promises'
import http from 'http'
import https from 'https'
import type { LookupFunction } from 'net'
import { createLogger } from '@sim/logger'
import * as ipaddr from 'ipaddr.js'

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

const agentOptions = {
lookup: (
_hostname: string,
_options: unknown,
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void
) => {
const lookup: LookupFunction = (_hostname, options, callback) => {
if (options.all) {
callback(null, [{ address: resolvedIP, family }])
} else {
callback(null, resolvedIP, family)
},
}
}

const agent = isHttps
? new https.Agent(agentOptions as https.AgentOptions)
: new http.Agent(agentOptions as http.AgentOptions)
const agentOptions: http.AgentOptions = { lookup }

const agent = isHttps ? new https.Agent(agentOptions) : new http.Agent(agentOptions)

// Remove accept-encoding since Node.js http/https doesn't auto-decompress
// Headers are lowercase due to Web Headers API normalization in executeToolRequest
const { 'accept-encoding': _, ...sanitizedHeaders } = options.headers ?? {}

const requestOptions: http.RequestOptions = {
hostname: parsed.hostname,
port,
path: parsed.pathname + parsed.search,
method: options.method || 'GET',
headers: options.headers || {},
headers: sanitizedHeaders,
agent,
timeout: options.timeout || 30000,
}
Expand Down