Skip to content

Validate operation delegation targets at connection time - #1105

Merged
aaronzi merged 2 commits into
eclipse-basyx:mainfrom
aaronzi:fix/operation-delegation-dns-rebinding
Nov 23, 2026
Merged

aaronzi merged 2 commits into
eclipse-basyx:mainfrom
aaronzi:fix/operation-delegation-dns-rebinding

Conversation

@aaronzi

@aaronzi aaronzi commented Nov 23, 2026

Copy link
Copy Markdown
Member

Description of Changes

Operation delegation targets are now validated by the HTTP client's own name resolution at connection time.

Previously, the delegation target host was resolved and checked by OperationDelegationTargetValidator before the request, while the outbound connection was opened by Reactor Netty after a separate DNS lookup of its own. The address that was checked was therefore not necessarily the address that was connected to.

With this change, the host is resolved once and only addresses that passed validation are used for the connection.

Changes

  • Added OperationDelegationAddressResolverGroup
    • a Netty AddressResolverGroup that resolves delegation target hosts through the validator
    • rejects the connection if any resolved address is blocked (loopback, private, link-local, multicast, metadata), unless it is allowlisted
    • performs resolution off the Netty event loop
  • Added OperationDelegationWebClientFactory
    • builds the delegation WebClient with a Reactor Netty HttpClient that uses the resolver above
    • keeps the existing pre-request URI validation (scheme, port allowlist, IP literals)
    • used by OperationDelegationSubmodelRepositoryConfiguration and by the tests, so the tests exercise the production wiring
  • OperationDelegationTargetValidator
    • new resolveAndValidate(String host), which resolves a host once and validates every address
    • optional HostResolver constructor argument (defaults to InetAddress::getAllByName) so DNS answers can be simulated in tests
  • Readme: documented that validation happens at connection time

Host and CIDR allowlists and security.enabled=false behave as before. The request URI is not rewritten, so the Host header and TLS SNI are unchanged.

Related Issue

N/A

BaSyx Configuration for Testing

Default configuration; the Operation Delegation security defaults apply (basyx.submodelrepository.feature.operation.delegation.security.*).

AAS Files Used for Testing

None; covered by unit tests.

Additional Information

  • TestOperationDelegationFeature#invokeOperationDelegationBlocksDnsRebindingToLoopback: the simulated DNS returns a public address for the first lookup and the loopback address for later lookups. The test verifies that the delegated request never reaches the loopback server. It fails without the new resolver.
  • TestOperationDelegationAddressResolverGroup: blocked addresses, mixed public/private answers, a single lookup per resolution, host and CIDR allowlists, disabled security, and unknown hosts.

The delegation target validator resolved the target host with
InetAddress, but the WebClient's Reactor Netty connector resolved the
host again on its own before connecting. A host whose DNS answer changes
between the two lookups (DNS rebinding) could therefore pass validation
with a public address and still be connected to a loopback or private
address.

The WebClient now uses a Reactor Netty HttpClient with a custom
AddressResolverGroup that resolves the host once through the validator
and hands only validated addresses to the connector. The pre-exchange
URI validation (scheme, port, IP literals) is kept.

- Extract OperationDelegationWebClientFactory so tests exercise the
  production WebClient wiring
- Add an injectable HostResolver to OperationDelegationTargetValidator
- Add OperationDelegationAddressResolverGroup (resolution runs off the
  event loop)
- Add a regression test reproducing the rebinding bypass and unit tests
  for the connection-time resolver

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Trailing-dot normalization can redirect DNS resolution to an unintended search-suffixed host, and the tests do not prove that the production HTTP client successfully uses the validated address.

2 open issues
What changed in this PR

This PR strengthens HTTP operation delegation in the submodel repository by validating the addresses used for outbound connections, closing the DNS-rebinding gap between validation and connection.

Changes:

  • Adds a Netty resolver that validates resolved addresses off the event loop.
  • Shares production and test WebClient setup while retaining pre-request URI checks.
  • Adds resolver and DNS-rebinding tests and documents connection-time validation.
File Description
TestOperationDelegationFeature.java Uses production client setup and adds a rebinding regression test.
TestOperationDelegationAddressResolverGroup.java Tests address validation, allowlists, and resolution failures.
OperationDelegationWebClientFactory.java Centralizes WebClient creation with the validating resolver.
OperationDelegationTargetValidator.java Adds injectable resolution and returns validated addresses.
OperationDelegationSubmodelRepositoryConfiguration.java Wires delegation through the shared client factory.
OperationDelegationAddressResolverGroup.java Supplies validated connection addresses without blocking the event loop.
Readme.md Documents connection-time DNS-rebinding protection.

Review effort: Balanced

Normalization stripped the trailing dot of absolute host names before
resolution, so a target such as "service.example." was looked up as the
relative name "service.example" and could pick up DNS search domains.
The host is now resolved as given; the normalized form is only used for
allowlist matching.

Also add a test that a delegated request to a host name known only to
the injected resolver succeeds, proving the HTTP client connects to the
validated address instead of performing its own DNS lookup.
@aaronzi
aaronzi merged commit 5417b0c into eclipse-basyx:main Nov 23, 2026
56 of 57 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