Andrea Cosentino created CAMEL-24371:
----------------------------------------
Summary: camel-a2a - fix WebhookUrlValidator address
classification and host matching
Key: CAMEL-24371
URL: https://issues.apache.org/jira/browse/CAMEL-24371
Project: Camel
Issue Type: Bug
Components: camel-ai
Reporter: Andrea Cosentino
Assignee: Andrea Cosentino
Fix For: 4.22.1, 4.23.0
{{WebhookUrlValidator}} in {{camel-a2a}} classifies webhook host addresses
inconsistently, and its literal check matches more than intended.
h3. 1. Pre-resolution and post-resolution checks disagree
{{validateAndResolve()}} first checks the host string with {{isPrivateIpv6()}}
(recognises fc00::/7, fe80::/10, ::1, ::ffff:), then classifies the resolved
address with {{isLoopbackAddress()}}, {{isAnyLocalAddress()}},
{{isLinkLocalAddress()}} and {{isSiteLocalAddress()}}.
Those two sets do not cover the same ranges.
{{Inet6Address.isSiteLocalAddress()}} reports the deprecated fec0::/10 block,
not fc00::/7, so an address reached through a hostname is classified
differently from the same address written as a literal. Verified on JDK 21:
{{fd00::1}} and {{fc00::1}} return false for all four predicates, while
{{fec0::1}} returns site=true.
The predicate set also does not recognise IPv4-compatible IPv6
({{::10.0.0.1}}), NAT64 (64:ff9b::/96), 6to4 (2002::/16) or shared address
space (100.64.0.0/10). IPv4-mapped IPv6 needs no extra handling, since the JDK
returns an {{Inet4Address}} for {{::ffff:x.x.x.x}}.
h3. 2. isPrivateIpv6() over-matches hostnames
It prefix-matches the raw host string with {{startsWith("fc")}} /
{{startsWith("fd")}} without first establishing that the host is an IP literal,
so any hostname beginning with those two characters is rejected.
{{https://fcm.googleapis.com/webhook}} and
{{https://fd-edge.example.com/webhook}} are both refused today, which blocks
legitimate webhook targets.
h3. Proposed change
In
{{components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/util/WebhookUrlValidator.java}}:
* Classify the resolved {{InetAddress}} by raw bytes rather than relying on the
{{InetAddress}} convenience predicates alone, covering the ranges listed above.
* Apply one shared classifier to both the literal and the resolved path so the
two agree by construction.
* Restrict {{isPrivateIpv6()}} to genuine IP literals so ordinary hostnames are
not caught by the prefix match.
* Extend {{WebhookUrlValidatorTest}} with cases for each range, using an in-JVM
{{InetAddressResolverProvider}} fixture so the resolved path is covered
deterministically without DNS.
Related: CAMEL-23876 previously hardened the same validator's
resolve-and-connect path.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)