Repository navigation
Conversation
Node reports IPv4 clients of a dual-stack server as ::ffff:a.b.c.d, so
ipMatch('::ffff:192.168.2.123', '192.168.2.0/24') returned false while
ipMatch('::ffff:192.168.2.123', '192.168.2.123') returned true. Go Casbin
(net.IPNet.Contains) returns true for both.
An IPv4 subnet now reads an IPv4-mapped address (::ffff:0:0/96 only) as
its IPv4 address before masking.
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.
ipMatchnever matched an IPv4-mapped IPv6 address against an IPv4 CIDR:This is the form Node uses for IPv4 clients on a dual-stack server (
server.listen()binds::by default, soreq.socket.remoteAddressis::ffff:192.168.2.123). A policy likeipMatch(r.ip, '192.168.2.0/24')therefore denied every IPv4 client, while an exact-IP policy worked.subnet().contains()masked the low 4 bytes of the IPv6 address and then compared a 16-byte result with the 4-byte network, so it was alwaysfalse. Now, when the subnet is IPv4, an address in::ffff:0:0/96is read as its IPv4 address first. Other IPv6 addresses (::c0a8:27b,2001:db8::c0a8:27b) still never match an IPv4 CIDR. This is the same as Go Casbin, wherenet.IPNet.Containsdoes theTo4()step.Testing
test/util.test.tsfails before (Expected: true, Received: false) and passes after.net.ParseCIDR(...).Contains(net.ParseIP(...))(what Goutil.IPMatchuses): same result for all of them.jest(17 suites, 240 passed),eslint . --ext .js,.ts,tscclean.