ryanbillingsley / express-ipfilter

A light-weight IP address based connection filtering system
MIT License
109 stars 44 forks source link

The middleware when deny a request crash the server #37

Closed mcarboni-redant closed 7 years ago

mcarboni-redant commented 7 years ago

When the server receives a request from a blacklisted IP, the server crashes immediately.

Access denied to IP address: ::ffff:127.0.0.1
Error
    at /Users/mauriziocarboni/development/novus/novus-api/node_modules/express-ipfilter/src/ipfilter.js:186:15
    at Layer.handle [as handle_request] (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:312:13)
    at /Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:280:7
    at next (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:271:10)
    at expressInit (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/middleware/init.js:33:5)
    at Layer.handle [as handle_request] (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:312:13)
    at /Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:280:7
    at next (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:271:10)
    at query (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/middleware/query.js:44:5)
    at Layer.handle [as handle_request] (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:312:13)
    at /Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:280:7
    at next (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/router/index.js:176:3)
    at Function.handle (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/application.js:173:10)
    at Server.app (/Users/mauriziocarboni/development/novus/novus-api/node_modules/express/lib/express.js:38:9)
    at emitTwo (events.js:106:13)
    at Server.emit (events.js:191:7)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:547:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
ryanbillingsley commented 7 years ago

@mcarboni-redant how are you handling errors that get raised from ipfilter?

mcarboni-redant commented 7 years ago

Hello @ryanbillingsley , I'm using the following code:

app.use(function(err, req, res) {
  console.error('Error handler', err)
  res.sendStatus(err.status || 500)
})

But seems that isn't reached

mcarboni-redant commented 7 years ago

@ryanbillingsley I've solved, I didn't know that express counts the number of arguments to know which functions are error handlers

ryanbillingsley commented 7 years ago

@mcarboni-redant great, glad you found a solution 👍

mcarboni-redant commented 7 years ago

Can I suggest to put in the readme a little section about error handling for Ip Filter?

From the code in the folder "examples" I've found that the package exports an error type called IpDeniedError.

ryanbillingsley commented 7 years ago

@mcarboni-redant yes, that is a good idea. thanks

ryanbillingsley commented 7 years ago

Added documentation