Repository navigation
xds: Fix CIDR /0 matching and treat_missing_header_as_empty - #13212
Merged
Merged
Conversation
`Matchers.CidrMatcher` used signed `BigInteger(byte[])` arithmetic
right-shifts, excluding upper-half IPv4 (>= 128.0.0.0) and IPv6 (>=
8000::) addresses from `/0` CIDR ranges. In `RbacFilter`, upper-half
peers bypassed `0.0.0.0/0` and `::/0` policies. In
`FilterChainMatchingProtocolNegotiators`, a `0.0.0.0/0` or `::/0`
`prefix_ranges` or `source_prefix_ranges` entry failed to match
upper-half addresses, causing `FilterChainSelector.select()` to silently
fall through to `default_filter_chain` (applying a different TLS/mTLS
context and HTTP filter chain, such as omitting RBAC), or to close the
connection when no default chain was configured. In addition,
`RbacFilter.resolve` accepted an empty `CidrRange` `address_prefix`
because `InetAddress.getByName("")` returns loopback (`127.0.0.1/0`,
matching lower-half IPv4 previously and all IPv4 once `/0` is fixed).
Meanwhile, `MatcherParser` and `Matchers.HeaderMatcher` ignored Envoy
`HeaderMatcher.treat_missing_header_as_empty` in both RBAC and RDS route
matching, causing inverted header matchers to fail open when clients
omitted the header.
Switch `Matchers.CidrMatcher` to unsigned `BigInteger(1, byte[])`,
reject empty `address_prefix` strings in `RbacFilter.resolve` while
keeping `InetAddress.getByName` for backport compatibility, and add
`HeaderMatcher.withTreatMissingHeaderAsEmpty` wired from `MatcherParser`
so missing headers evaluate as `""` before matching and inversion per
Envoy semantics.
kannanjgithub
approved these changes
Dec 1, 2026
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.
Matchers.CidrMatcherused signedBigInteger(byte[])arithmetic right-shifts, excluding upper-half IPv4 (>= 128.0.0.0) and IPv6 (>= 8000::) addresses from/0CIDR ranges. InRbacFilter, upper-half peers bypassed0.0.0.0/0and::/0policies. InFilterChainMatchingProtocolNegotiators, a0.0.0.0/0or::/0prefix_rangesorsource_prefix_rangesentry failed to match upper-half addresses, causingFilterChainSelector.select()to silently fall through todefault_filter_chain(applying a different TLS/mTLS context and HTTP filter chain, such as omitting RBAC), or to close the connection when no default chain was configured. In addition,RbacFilter.resolveaccepted an emptyCidrRangeaddress_prefixbecauseInetAddress.getByName("")returns loopback (127.0.0.1/0, matching lower-half IPv4 previously and all IPv4 once/0is fixed).Meanwhile,
MatcherParserandMatchers.HeaderMatcherignored EnvoyHeaderMatcher.treat_missing_header_as_emptyin both RBAC and RDS route matching, causing inverted header matchers to fail open when clients omitted the header.Switch
Matchers.CidrMatcherto unsignedBigInteger(1, byte[]), reject emptyaddress_prefixstrings inRbacFilter.resolvewhile keepingInetAddress.getByNamefor backport compatibility, and addHeaderMatcher.withTreatMissingHeaderAsEmptywired fromMatcherParserso missing headers evaluate as""before matching and inversion per Envoy semantics.