Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isLocal (e) {
// don't rely on private ip address, because
// cjdns creates fake private ip addresses.
// ignore localhost addresses, because sometimes they get broadcast.
return !ip.isLoopback(e.host) && ip.isPrivate(e.host) && e.source === 'local'
}
server.use(cors.actual);
server.use((request, response, next) => {
const result = this.apiUtilities.authorize(request);
if (result) {
response.status(result.status);
response.send({
message: result.message,
});
return;
}
return next();
});
// TODO: Temp solution to listen all adapters in local net.
let serverListenAddress = this.config.node_rpc_ip;
if (ip.isLoopback(serverListenAddress)) {
serverListenAddress = '0.0.0.0';
}
// promisified server.listen()
const startServer = () => new Promise((resolve, reject) => {
server.listen(this.config.node_rpc_port, serverListenAddress, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
await startServer(server, serverListenAddress);
this.logger.notify(`API exposed at ${server.url}`);
server.use(cors.actual);
server.use((request, response, next) => {
const result = this.apiUtilities.authorize(request);
if (result) {
response.status(result.status);
response.send({
message: result.message,
});
return;
}
return next();
});
// TODO: Temp solution to listen all adapters in local net.
let serverListenAddress = this.config.node_rpc_ip;
if (ip.isLoopback(serverListenAddress)) {
serverListenAddress = '0.0.0.0';
}
// promisified server.listen()
const startServer = () => new Promise((resolve, reject) => {
server.listen(this.config.node_rpc_port, serverListenAddress, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
await startServer(server, serverListenAddress);
this.logger.notify(`API exposed at ${server.url}`);
m.rpush(pre + ':privs:' + priv, num);
}
else
m.rpush(pre + ':posts', num);
}
else {
// TODO: Add to alternate thread list?
// set conditional hide?
op = num;
if (!view.immortal) {
var score = expiry_queue_score(msg.time);
var entry = num + ':' + tag_key(this.tag);
m.zadd(expiry_queue_key(), score, entry);
}
/* Rate-limit new threads */
if (ipUtils.isLoopback(ip))
m.setex('ip:'+ip+':throttle:thread',
config.THREAD_THROTTLE, op);
}
/* Denormalize for backlog */
view.nonce = msg.nonce;
view.body = body;
if (msg.links)
view.links = msg.links;
extract(view);
delete view.ip;
var self = this;
async.waterfall([
function (next) {
if (!msg.image)
function parse(addr) {
var parts = addr.split('~')[0].split(':')
var protocol = parts[0], host = parts[1]
return {
protocol: protocol,
group: (ip.isLoopback(host) || !host) ? 'loopback' : ip.isPrivate(host) ? 'local' : 'internet',
host: host
}
}
var addresses = interfaces[nic].filter(function (details) {
details.family = details.family.toLowerCase();
if (details.family !== 'ipv4' || ip.isLoopback(details.address)) {
return false;
}
return true;
});
return addresses.length ? addresses[0].address : undefined;
return addresses.filter((a) => !ip.isLoopback(a) && a !== host);
},
checker.isAddressLocal = function(addr, cb) {
if (cb) {
if (ip.isPrivate(addr) || ip.isLoopback(addr)) cb(null, true);
else cb(null, false);
} else {
if (ip.isPrivate(addr) || ip.isLoopback(addr)) return true;
else return false;
}
};
function isOffline (e) {
if(ip.isLoopback(e.host)) return false
return !hasNetwork()
}
Y.reserve_post = function (op, ip, callback) {
if (this.ident.readOnly)
return callback(Muggle("Can't post right now."));
var r = this.connect();
if (ipUtils.isLoopback(ip))
return reserve();
var key = 'ip:' + ip + ':throttle:';
var now = Date.now();
var shortTerm = key + short_term_timeslot(now);
var longTerm = key + long_term_timeslot(now);
r.mget([shortTerm, longTerm], function (err, quants) {
if (err)
return callback(Muggle("Limiter failure.", err));
if (quants[0] > config.SHORT_TERM_LIMIT ||
quants[1] > config.LONG_TERM_LIMIT)
return callback(Muggle('Reduce your speed.'));
reserve();
});