Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function parseipNotation (note) {
range = null
}

if (range <= 0 || range > max) {
if (range === null || range < 0 || range > max) {
throw new TypeError('invalid range on address: ' + note)
}

Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ describe('proxyaddr(req, trust)', function () {
assert.strictEqual(proxyaddr(req, '10.0.0.2/26'), '10.0.0.200')
})

it('should accept /0 CIDR to trust all addresses', function () {
var req = createReq('10.0.0.1', {
'x-forwarded-for': '192.168.0.1, 172.16.0.1'
})
assert.strictEqual(proxyaddr(req, '0.0.0.0/0'), '192.168.0.1')
})

it('should accept netmask notation', function () {
var req = createReq('10.0.0.1', {
'x-forwarded-for': '192.168.0.1, 10.0.0.200'
Expand Down Expand Up @@ -490,6 +497,14 @@ describe('proxyaddr.compile(trust)', function () {
assert.throws(proxyaddr.compile.bind(null, '::ffff:a00:2/-46'), /invalid range on address/)
})

it('should accept IPv4 CIDR /0', function () {
assert.strictEqual(typeof proxyaddr.compile('0.0.0.0/0'), 'function')
})

it('should accept IPv6 CIDR /0', function () {
assert.strictEqual(typeof proxyaddr.compile('::/0'), 'function')
})

it('should not alter input array', function () {
var arr = ['loopback', '10.0.0.1']
assert.strictEqual(typeof proxyaddr.compile(arr), 'function')
Expand Down