aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-02-07 11:21:25 +0100
committerChocobozzz <me@florianbigard.com>2022-02-07 11:21:25 +0100
commitf33e515991a32885622b217bf2ed1d1b0d9d6832 (patch)
tree43bf9e63c821f2b363ee60e8b1de07ab7c883580 /server/helpers
parent4afec7357129590b0e0f3558ecb9ac20e0903600 (diff)
downloadPeerTube-f33e515991a32885622b217bf2ed1d1b0d9d6832.tar.gz
PeerTube-f33e515991a32885622b217bf2ed1d1b0d9d6832.tar.zst
PeerTube-f33e515991a32885622b217bf2ed1d1b0d9d6832.zip
Correctly check import target URL IP
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/dns.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/server/helpers/dns.ts b/server/helpers/dns.ts
new file mode 100644
index 000000000..da8b666c2
--- /dev/null
+++ b/server/helpers/dns.ts
@@ -0,0 +1,29 @@
1import { lookup } from 'dns'
2import { parse as parseIP } from 'ipaddr.js'
3
4function dnsLookupAll (hostname: string) {
5 return new Promise<string[]>((res, rej) => {
6 lookup(hostname, { family: 0, all: true }, (err, adresses) => {
7 if (err) return rej(err)
8
9 return res(adresses.map(a => a.address))
10 })
11 })
12}
13
14async function isResolvingToUnicastOnly (hostname: string) {
15 const addresses = await dnsLookupAll(hostname)
16
17 for (const address of addresses) {
18 const parsed = parseIP(address)
19
20 if (parsed.range() !== 'unicast') return false
21 }
22
23 return true
24}
25
26export {
27 dnsLookupAll,
28 isResolvingToUnicastOnly
29}