fix(net): enable family fallback for pinned SSRF dispatcher

This commit is contained in:
Peter Steinberger
2026-02-22 17:08:29 +01:00
parent 4d0ca7c315
commit e9ed688c2c
3 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { describe, expect, it, vi } from "vitest";
const { agentCtor } = vi.hoisted(() => ({
agentCtor: vi.fn(function MockAgent(this: { options: unknown }, options: unknown) {
this.options = options;
}),
}));
vi.mock("undici", () => ({
Agent: agentCtor,
}));
import { createPinnedDispatcher, type PinnedHostname } from "./ssrf.js";
describe("createPinnedDispatcher", () => {
it("enables network family auto-selection for pinned lookups", () => {
const lookup = vi.fn();
const pinned: PinnedHostname = {
hostname: "api.telegram.org",
addresses: ["149.154.167.220"],
lookup,
};
const dispatcher = createPinnedDispatcher(pinned);
expect(dispatcher).toBeDefined();
expect(agentCtor).toHaveBeenCalledWith({
connect: {
lookup,
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout: 300,
},
});
});
});

View File

@@ -296,6 +296,8 @@ export function createPinnedDispatcher(pinned: PinnedHostname): Dispatcher {
return new Agent({
connect: {
lookup: pinned.lookup,
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout: 300,
},
});
}