Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if the device wants to be cloud-only, then it belongs to the cloud
if (this.hasKind('cloud-only'))
return this._ownerTier = Tier.CLOUD;
// if the device wants to be phone-only, then it belongs to the phone
if (this.hasKind('phone-only'))
return this._ownerTier = Tier.PHONE;
// online accounts belong to the cloud
if (this.hasKind('online-account'))
return this._ownerTier = Tier.CLOUD;
// if this device is on (some) local network, it belongs to home
if (this.state) {
if ('host' in this.state && ip.isPrivate(this.state.host))
return this._ownerTier = Tier.SERVER;
if ('ip-address' in this.state && ip.isPrivate(this.state['ip-address']))
return this._ownerTier = Tier.SERVER;
}
// anything else belongs to the phone
// (in particular, this means that physical devices with a cloud
// attachment, or an omlet ID, get handled by the phone, which ensures
// privacy and makes everyone happy)
return this._ownerTier = Tier.CLOUD;
},
public async serve() {
if (await checkPort(this._options.port!)) {
throw new err.ErrorServerPortInUse(this._options.port!);
}
this._server = this.app.listen(this._options.port);
const IP = ip.address();
const host = ip.isPrivate(IP) ? 'localhost' : IP;
info(
'Server',
'Is now running at',
// tslint:disable-next-line no-http-string
colors.yellow(`http://${host}:${this._options.port!.toString()}`)
);
// Run the default scripts
await runScripts(this);
}
.filter(function (peer) {
// Removing peers with private address or nonce equal to self
if ((process.env['NODE_ENV'] || '').toUpperCase() === 'TEST') {
return peer.nonce !== modules.system.getNonce() && (peer.os !== 'lisk-js-api');
}
return !ip.isPrivate(peer.ip) && peer.nonce !== modules.system.getNonce() && (peer.os !== 'lisk-js-api');
}).value();
};
let isPrivate = false
let isNearby = false
let addr
try {
addr = maddr.nodeAddress()
} catch (_) {
// Might explode if maddr does not have an IP or cannot be converted
// to a node address. This might happen if it's a relay. We do not print
// or handle the error, otherwise we would get perhaps thousands of logs.
return { isPrivate, isNearby }
}
// At this point, addr.address and publicIP must be valid IP addresses. Hence,
// none of the calls bellow for ip library should fail.
isPrivate = ip.isPrivate(addr.address)
if (publicIP) {
if (ip.isV4Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/24`).contains(addr.address)
} else if (ip.isV6Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/48`).contains(addr.address) &&
!ip.cidrSubnet('fc00::/8').contains(addr.address)
// peerIP6 ∉ fc00::/8 to fix case of cjdns where IPs are not spatial allocated.
}
}
return { isPrivate, isNearby }
}
function isLocal (e) {
// don't rely on private ip address, because
// cjdns creates fake private ip addresses.
return ip.isPrivate(e.host) && e.source === 'local'
}
function is_addr_local(addr) {
if (ip.isPrivate(addr) == true) {
return true;
} else {
return false;
}
}
/**
function middleware(req, res, next) {
if (ip.isPrivate(req.ip)) {
next();
} else {
res.status(401);
res.send("Only local requests are allowed to this host.");
}
}
isPrivate(at=null){
const value = this.valueAt(at);
return nodeIp.isPrivate(value);
}
var globalize = function(addr) {
if (ip.isPrivate(addr)) {
return global_ip;
} else {
return addr;
}
}