Skip to content

xds: Fix CIDR /0 matching and treat_missing_header_as_empty - #13212

Merged
AgraVator merged 1 commit into
grpc:masterfrom
AgraVator:fix-xds-cidr-and-missing-header
Dec 1, 2026
Merged

AgraVator merged 1 commit into
grpc:masterfrom
AgraVator:fix-xds-cidr-and-missing-header

Conversation

@AgraVator

Copy link
Copy Markdown
Contributor

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.

`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.
@AgraVator
AgraVator merged commit 5ebe3bf into grpc:master Dec 1, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants