Skip to content

Commit 47f0dc3

Browse files
committed
fix(net): normalize single-result SSRF lookups
1 parent 29a5679 commit 47f0dc3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/infra/net/ssrf.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type LookupCallback = (
2121
family?: number,
2222
) => void;
2323

24+
type LookupResult = LookupAddress | readonly LookupAddress[];
25+
2426
export class SsrFBlockedError extends Error {
2527
constructor(message: string) {
2628
super(message);
@@ -200,6 +202,10 @@ function assertAllowedResolvedAddressesOrThrow(
200202
}
201203
}
202204

205+
function normalizeLookupResults(results: LookupResult): readonly LookupAddress[] {
206+
return Array.isArray(results) ? results : [results];
207+
}
208+
203209
export function createPinnedLookup(params: {
204210
hostname: string;
205211
addresses: string[];
@@ -331,7 +337,9 @@ export async function resolvePinnedHostnameWithPolicy(
331337
}
332338

333339
const lookupFn = params.lookupFn ?? dnsLookup;
334-
const results = await lookupFn(normalized, { all: true });
340+
const results = normalizeLookupResults(
341+
(await lookupFn(normalized, { all: true })) as LookupResult,
342+
);
335343
if (results.length === 0) {
336344
throw new Error(`Unable to resolve hostname: ${hostname}`);
337345
}

0 commit comments

Comments
 (0)