Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const server = http.createServer((request, response) => {
// gets the ip of the request
let ip = requestIp.getClientIp(request)
// this snippet closes the request to favicon.ico
if (request.url === '/favicon.ico') return response.end()
// here we add an attempt to the ip
lf.addAttempt(ip)
.then(() => {
// here we check if the client has reached the maximum number of attempts
// or if the client has an active timeout
return lf.checkClient(ip)
})
.then((client) => {
if (!client) {
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Hello World\n')
} else {
response.writeHead(403, {'Content-Type': 'text/plain'})
http.createServer((request, response) => {
// gets the ip of the request
let ip = requestIp.getClientIp(request)
// this snippet closes the request to favicon.ico
if (request.url === '/favicon.ico') {
response.end()
console.log('favicon requested')
return
}
// here we add an attempt to the ip
lf.addAttempt(ip, (errAdd) => {
if (errAdd) return console.log(errAdd)
// here we check if the client has reached the maximum number of attempts
// or if the client has an active timeout
lf.checkClient(ip, (errCheck, client) => {
if (errCheck) return console.log(errCheck)
if (!client) {
module.exports = (req) => {
if ('development' === NODE_ENV) {
// ignore limits during development
return
}
const clientIp = requestIp.getClientIp(req)
seen[clientIp] = seen[clientIp] || 0
if (seen[clientIp] > 10) {
const err = new Error('Too many views per IP')
err.statusCode = 429
throw err
}
seen[clientIp]++
}
const ipMiddleware = (req, res, next) => {
let clientIp;
if (req.header('cf-connecting-ip')){
req.clientIp = req.header('cf-connecting-ip'); // I want to always give priority to this header
} else {
req.clientIp = requestIp.getClientIp(req); // if it's not there then fall back
}
next();
};
function sendClientIP(req, res, path) {
parsedQueryString = querystring.parse(parsedURL.query);
var variable = parsedQueryString['var'];
var clientIp = requestIp.getClientIp(req);
//jsonp
res.writeHead(200, {'Content-Type': mimeTypes['js']});
res.end('var ' + variable + ' = \'' + clientIp + '\';');
console.log('Client IP has been sent successfully');
}
export const resetPassword = (accountsServer: AccountsServer) => async (
req: express.Request,
res: express.Response
) => {
try {
const { token, newPassword } = req.body;
const userAgent = getUserAgent(req);
const ip = getClientIp(req);
const password: any = accountsServer.getServices().password;
const loginResult = await password.resetPassword(token, newPassword, { userAgent, ip });
res.json(loginResult);
} catch (err) {
sendError(res, err);
}
};
async method (request, h) {
const remoteAddress = requestIp.getClientIp(request)
if (isWhitelist(['127.*'], remoteAddress)) {
return h.continue
}
if (!bucket.has(remoteAddress)) {
bucket.add(remoteAddress, isKnown(remoteAddress) ? 2000 : 1)
}
bucket.decrement(remoteAddress)
if (bucket.remaining(remoteAddress) <= 0) {
logger.debug(`${remoteAddress} has exceeded the maximum number of requests per minute.`)
return Boom.tooManyRequests()
}
function _extractIp(req) {
var ip = req.ip;
if (!ip) {
ip = requestIp.getClientIp(req);
}
return ip;
}