fetch-node: ensure unicast checks allow psl domains ()

This commit is contained in:
devin ivy 2025-01-16 18:43:27 -05:00 committed by GitHub
parent 4ab7075fde
commit 9c01281931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions
.changeset
packages/internal/fetch-node/src

@ -0,0 +1,5 @@
---
"@atproto-labs/fetch-node": patch
---
Unicast checks should permit PSL domains.

@ -9,7 +9,7 @@ import {
FetchRequestError,
} from '@atproto-labs/fetch'
import ipaddr from 'ipaddr.js'
import { isValid as isValidDomain } from 'psl'
import { parse as pslParse } from 'psl'
import { Agent, Client } from 'undici'
import { isUnicastIp } from './util.js'
@ -185,6 +185,14 @@ export function unicastLookup(
})
}
// see lupomontero/psl#258 for context on psl usage.
// in short, this ensures a structurally valid domain
// plus a "listed" tld.
function isValidDomain(domain: string) {
const parsed = pslParse(domain)
return !parsed.error && parsed.listed
}
function isNotUnicast(ip: ipaddr.IPv4 | ipaddr.IPv6): boolean {
return ip.range() !== 'unicast'
}