tunnckoCore / express-ip-filter

Middleware for `express` that filters IPs against glob patterns, RegExp, string or array of globs. Support custom 403 Forbidden message, blacklists, whitelists and custom ID.
http://j.mp/1LsPKGz
MIT License
13 stars 2 forks source link

wish: support CIDR ranges #7

Open markstos opened 6 years ago

markstos commented 6 years ago

Firewall rules are often provided in CIDR notation. Example:

192.0.2.0/24

Supporting CIDR ranges directly would be welcome addition.

The module ip-range-check can be used to check whether an incoming IP address within a provided whitelisted CIDR range.

tunnckoCore commented 6 years ago

Wee are using micromatch here, doesn't it working? Oor otherwise we can implement it somehow in the ip-filter package?

tunnckoCore commented 6 years ago

I mean we are using micromatch in the ip-filter

markstos commented 6 years ago

Neither ip-filter docs nor the micromatch docs make any mention of supporting CIDR notation.

tunnckoCore commented 6 years ago

yea but it is glob patterns. it works great for path-like strings, that's why I think it would work.

For example I think 192.0.2.* would match all. or 192.0.2.[0-9] or such. The thing is to learn the supported globbing patterns, ext globs and such. Kinda like regex, there are dozen of ways. In case of 0/24 you can search how to match it withbregex. Yea, probably won't be exactly the same as define it as CIDR but...

Anyway, I think it should be implemented in ip-filter.