aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/signup.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/signup.ts')
-rw-r--r--server/lib/signup.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/lib/signup.ts b/server/lib/signup.ts
index 8fa81e601..3c1397a12 100644
--- a/server/lib/signup.ts
+++ b/server/lib/signup.ts
@@ -1,6 +1,6 @@
1import { UserModel } from '../models/user/user' 1import { IPv4, IPv6, parse, subnetMatch } from 'ipaddr.js'
2import * as ipaddr from 'ipaddr.js'
3import { CONFIG } from '../initializers/config' 2import { CONFIG } from '../initializers/config'
3import { UserModel } from '../models/user/user'
4 4
5const isCidr = require('is-cidr') 5const isCidr = require('is-cidr')
6 6
@@ -22,7 +22,7 @@ async function isSignupAllowed (): Promise<{ allowed: boolean, errorMessage?: st
22function isSignupAllowedForCurrentIP (ip: string) { 22function isSignupAllowedForCurrentIP (ip: string) {
23 if (!ip) return false 23 if (!ip) return false
24 24
25 const addr = ipaddr.parse(ip) 25 const addr = parse(ip)
26 const excludeList = [ 'blacklist' ] 26 const excludeList = [ 'blacklist' ]
27 let matched = '' 27 let matched = ''
28 28
@@ -32,23 +32,23 @@ function isSignupAllowedForCurrentIP (ip: string) {
32 } 32 }
33 33
34 if (addr.kind() === 'ipv4') { 34 if (addr.kind() === 'ipv4') {
35 const addrV4 = ipaddr.IPv4.parse(ip) 35 const addrV4 = IPv4.parse(ip)
36 const rangeList = { 36 const rangeList = {
37 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr)) 37 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr))
38 .map(cidr => ipaddr.IPv4.parseCIDR(cidr)), 38 .map(cidr => IPv4.parseCIDR(cidr)),
39 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr)) 39 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr))
40 .map(cidr => ipaddr.IPv4.parseCIDR(cidr)) 40 .map(cidr => IPv4.parseCIDR(cidr))
41 } 41 }
42 matched = ipaddr.subnetMatch(addrV4, rangeList, 'unknown') 42 matched = subnetMatch(addrV4, rangeList, 'unknown')
43 } else if (addr.kind() === 'ipv6') { 43 } else if (addr.kind() === 'ipv6') {
44 const addrV6 = ipaddr.IPv6.parse(ip) 44 const addrV6 = IPv6.parse(ip)
45 const rangeList = { 45 const rangeList = {
46 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr)) 46 whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr))
47 .map(cidr => ipaddr.IPv6.parseCIDR(cidr)), 47 .map(cidr => IPv6.parseCIDR(cidr)),
48 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr)) 48 blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr))
49 .map(cidr => ipaddr.IPv6.parseCIDR(cidr)) 49 .map(cidr => IPv6.parseCIDR(cidr))
50 } 50 }
51 matched = ipaddr.subnetMatch(addrV6, rangeList, 'unknown') 51 matched = subnetMatch(addrV6, rangeList, 'unknown')
52 } 52 }
53 53
54 return !excludeList.includes(matched) 54 return !excludeList.includes(matched)