X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fsignup.ts;h=f094531eb721926431f9a17f7e80322d21eaebc9;hb=cd25344f741e8c97b113b36eb6babc7be490114d;hp=8fa81e601d7a712e314dd036a2151648ee8f8353;hpb=10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/signup.ts b/server/lib/signup.ts index 8fa81e601..f094531eb 100644 --- a/server/lib/signup.ts +++ b/server/lib/signup.ts @@ -1,6 +1,6 @@ -import { UserModel } from '../models/user/user' -import * as ipaddr from 'ipaddr.js' +import { IPv4, IPv6, parse, subnetMatch } from 'ipaddr.js' import { CONFIG } from '../initializers/config' +import { UserModel } from '../models/user/user' const isCidr = require('is-cidr') @@ -22,33 +22,33 @@ async function isSignupAllowed (): Promise<{ allowed: boolean, errorMessage?: st function isSignupAllowedForCurrentIP (ip: string) { if (!ip) return false - const addr = ipaddr.parse(ip) + const addr = parse(ip) const excludeList = [ 'blacklist' ] let matched = '' - // if there is a valid, non-empty whitelist, we exclude all unknown adresses too + // if there is a valid, non-empty whitelist, we exclude all unknown addresses too if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) { excludeList.push('unknown') } if (addr.kind() === 'ipv4') { - const addrV4 = ipaddr.IPv4.parse(ip) + const addrV4 = IPv4.parse(ip) const rangeList = { whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr)) - .map(cidr => ipaddr.IPv4.parseCIDR(cidr)), + .map(cidr => IPv4.parseCIDR(cidr)), blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr)) - .map(cidr => ipaddr.IPv4.parseCIDR(cidr)) + .map(cidr => IPv4.parseCIDR(cidr)) } - matched = ipaddr.subnetMatch(addrV4, rangeList, 'unknown') + matched = subnetMatch(addrV4, rangeList, 'unknown') } else if (addr.kind() === 'ipv6') { - const addrV6 = ipaddr.IPv6.parse(ip) + const addrV6 = IPv6.parse(ip) const rangeList = { whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr)) - .map(cidr => ipaddr.IPv6.parseCIDR(cidr)), + .map(cidr => IPv6.parseCIDR(cidr)), blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr)) - .map(cidr => ipaddr.IPv6.parseCIDR(cidr)) + .map(cidr => IPv6.parseCIDR(cidr)) } - matched = ipaddr.subnetMatch(addrV6, rangeList, 'unknown') + matched = subnetMatch(addrV6, rangeList, 'unknown') } return !excludeList.includes(matched)