fix: allow CIDR prefix length /0 to trust all addresses#59
Open
mahmoodhamdi wants to merge 1 commit into
Open
Conversation
The range validation in parseipNotation rejected /0 prefix length because the check used `range <= 0`, which incorrectly treated 0 as invalid. However, /0 is valid CIDR notation meaning "match all addresses" — 0.0.0.0/0 matches all IPv4 and ::/0 matches all IPv6. Changed the validation to explicitly check for null (invalid format) separately from the numeric range check, allowing 0 as a valid prefix length. Fixes jshttp#28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the range validation in
parseipNotationto accept/0as a valid CIDR prefix length.Problem
0.0.0.0/0and::/0are valid CIDR notation meaning "match all addresses", butproxyaddr.compile('0.0.0.0/0')throwsTypeError: invalid range on address: 0.0.0.0/0.This is because the validation check on line 191 used
range <= 0, which incorrectly treated0as invalid:This affects users who want to trust all proxy addresses (e.g., when behind a reverse proxy that already handles trust). The issue was reported with Mastodon's streaming server which sets
app.set('trust proxy', '0.0.0.0/0').Fix
Changed the validation to explicitly check for
null(which represents an unparseable format) separately from the numeric bound check:This allows
0as a valid prefix length while still rejecting:-46)/6000,/136for IPv6)rangeisnull)Testing
Added 3 new tests:
proxyaddr.compile('0.0.0.0/0')accepts IPv4 CIDR /0proxyaddr.compile('::/0')accepts IPv6 CIDR /0proxyaddr(req, '0.0.0.0/0')functionally trusts all IPv4 addressesAll 73 tests pass. Lint clean.
Fixes #28