Skip to content

Commit

Permalink
fetch-node: ensure unicast checks allow psl domains (#3379)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy authored Jan 16, 2025
1 parent 4ab7075 commit 9c01281
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silver-birds-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto-labs/fetch-node": patch
---

Unicast checks should permit PSL domains.
10 changes: 9 additions & 1 deletion packages/internal/fetch-node/src/unicast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit 9c01281

Please sign in to comment.