attempt to fix mail sending
This commit is contained in:
@@ -170,11 +170,42 @@ export async function safeFetch(rawUrl: string, opts: SafeFetchOptions = {}): Pr
|
||||
// Pin the resolved IP. We pass an Agent with a custom `lookup` that always
|
||||
// returns our pre-validated address, so the actual TCP connect can't be
|
||||
// re-resolved to something else (DNS-rebinding defense).
|
||||
//
|
||||
// Note: Node 20+ enables Happy Eyeballs (`autoSelectFamily: true`) by
|
||||
// default on the http/https agents. Happy Eyeballs calls `lookup` with
|
||||
// `{ all: true }` and expects the callback to receive an *array* of
|
||||
// `{ address, family }` records. If we ignore that and always invoke the
|
||||
// 3-arg form, the connector hands `undefined` to `socket.connect()`,
|
||||
// which then throws `Invalid IP address: undefined`.
|
||||
type LookupCb =
|
||||
| ((err: NodeJS.ErrnoException | null, address: string, family: number) => void)
|
||||
| ((err: NodeJS.ErrnoException | null, addresses: { address: string; family: number }[]) => void);
|
||||
const pinnedLookup = (
|
||||
_hostname: string,
|
||||
_options: unknown,
|
||||
cb: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
||||
) => cb(null, address, family);
|
||||
optionsOrCb: { all?: boolean; family?: number } | LookupCb,
|
||||
maybeCb?: LookupCb,
|
||||
) => {
|
||||
let options: { all?: boolean; family?: number } = {};
|
||||
let cb: LookupCb;
|
||||
if (typeof optionsOrCb === "function") {
|
||||
cb = optionsOrCb;
|
||||
} else {
|
||||
options = optionsOrCb ?? {};
|
||||
cb = maybeCb as LookupCb;
|
||||
}
|
||||
if (options.all) {
|
||||
(cb as (err: NodeJS.ErrnoException | null, addresses: { address: string; family: number }[]) => void)(
|
||||
null,
|
||||
[{ address, family }],
|
||||
);
|
||||
} else {
|
||||
(cb as (err: NodeJS.ErrnoException | null, address: string, family: number) => void)(
|
||||
null,
|
||||
address,
|
||||
family,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const isHttps = url.protocol === "https:";
|
||||
const agent = isHttps
|
||||
|
||||
Reference in New Issue
Block a user