December 2, 2026
Securing Webhook Calls in Spring Boot
A webhook feature lets each tenant register a URL, and your server sends an HTTP request to that URL whenever an event fires. So a tenant…

By bytebantz
4 min read
A webhook feature lets each tenant register a URL, and your server sends an HTTP request to that URL whenever an event fires. So a tenant decides where your server sends requests. Nothing in that design stops the tenant from choosing an address inside your own network.
That attack is server-side request forgery (SSRF). The tenant can't reach your admin ports, your sibling services or your cloud metadata endpoint, but your server can, and the webhook client will make the call for them.
Spring Boot gives you a filter for exactly this case. The filter works only when you understand what it checks, and one network setup takes its protection away.
This article covers three mistakes in a client that calls tenant-supplied URLs: trusting the URL, trusting the filter behind a proxy, and leaving cookie handling to whichever HTTP library is on the classpath.
Mistake 1: Calling whatever URL a tenant registers
The first version of a webhook client usually looks like this:
RestClient webhookClient = builder.build();
webhookClient.post().uri(tenant.callbackUrl()).body(event).retrieve().toBodilessEntity();RestClient webhookClient = builder.build();
webhookClient.post().uri(tenant.callbackUrl()).body(event).retrieve().toBodilessEntity();The client resolves the tenant's hostname and connects to whatever IP address comes back. If that address is 127.0.0.1, an admin port or 169.254.169.254, the client sends your event there with your server's network access.
Spring Boot provides InetAddressFilter, a functional interface that checks the IP address the client is about to connect to.
The check runs after DNS resolution and before the connection opens, so a hostname can't hide an internal address. InetAddressFilter.externalAddresses() allows external addresses only:
HttpClientSettings settings = HttpClientSettings.defaults()
.withInetAddressFilter(InetAddressFilter.externalAddresses());
RestClient webhookClient = builder.clone()
.requestFactory(ClientHttpRequestFactoryBuilder.detect().build(settings))
.build();HttpClientSettings settings = HttpClientSettings.defaults()
.withInetAddressFilter(InetAddressFilter.externalAddresses());
RestClient webhookClient = builder.clone()
.requestFactory(ClientHttpRequestFactoryBuilder.detect().build(settings))
.build();The fix applies the filter to this one client, through HttpClientSettings, and that scope matters.
You can also declare an InetAddressFilter as a @Bean, and Spring Boot then applies it to every auto-configured HTTP client builder.
A global externalAddresses() bean would also block the calls your application makes to its own internal services. Use the bean only when every client in the application should face the same rule.
For rules other than "external only", the interface has factory methods. InetAddressFilter.of("192.168.1.0/24") allows the addresses in a CIDR range, and .andNot("192.168.1.1", "192.168.1.10") takes specific addresses back out. You can also implement the interface yourself.
How to check it: register a test webhook that points at http://127.0.0.1. The webhook client should refuse to connect.
Mistake 2: Trusting the app-side filter behind an egress proxy
Some networks send all outbound traffic through a forward proxy. In that setup, the filter from the first fix stops protecting anything:
@Bean InetAddressFilter ssrf() { return InetAddressFilter.externalAddresses(); }
// JVM: -Dhttps.proxyHost=egress.corp -Dhttps.proxyPort=3128@Bean InetAddressFilter ssrf() { return InetAddressFilter.externalAddresses(); }
// JVM: -Dhttps.proxyHost=egress.corp -Dhttps.proxyPort=3128With a proxy, your application never resolves the tenant's hostname.
The client sends the requested host to the proxy as part of the request, and the proxy resolves it.
The only address your application connects to is the proxy's, so the filter checks the proxy's IP and nothing else.
If the tenant's URL points at an internal address, the proxy fetches it for you. With load-balancing DNS, the address your application would resolve can differ from the one the proxy resolves.
Enforce the restriction on the proxy itself, and use the app-side filter so that the application can reach only the proxy:
@Bean InetAddressFilter onlyEgressProxy() { return InetAddressFilter.of("10.20.0.15/32"); }
# egress proxy ACL
deny dst 10.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16
allow dst all@Bean InetAddressFilter onlyEgressProxy() { return InetAddressFilter.of("10.20.0.15/32"); }
# egress proxy ACL
deny dst 10.0.0.0/8 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16
allow dst allThe ACL denies the private ranges and the link-local range that holds cloud metadata endpoints.
The app-side filter now does a different job: it makes sure no client in the application skips the proxy. A global bean fits here, because every outbound call should go through the proxy.
How to check it: test both layers. From the application host, request an internal address through the proxy, and the proxy should deny it. Then point a client straight at any address other than the proxy's, and the filter should refuse it.
Mistake 3: Leaving cookie handling to the HTTP library
The third mistake has nothing to do with addresses. It comes from a dependency you add for a different reason:
# nothing set; httpclient5 added later for connection pooling# nothing set; httpclient5 added later for connection poolingWith no setting, each HTTP library follows its own default.
Apache HttpComponents and Jetty store the cookies a server sets and send them back on later requests.
The JDK client ignores them.
Apache HttpClient also sits first in Spring Boot's detection order, so adding httpclient5 for connection pooling switches every auto-configured client to Apache.
After that switch, your service-to-service clients start storing Set-Cookie values and replaying them on later calls, including sticky-session and auth cookies.
Nothing in the client code changed. For a webhook client, the servers sending those cookies belong to your tenants.
Pin the behaviour so a dependency change can't flip it:
spring.http.clients.cookie-handling=disablespring.http.clients.cookie-handling=disableThe property takes three values. disable turns cookies off. enable gives each client instance its own cookie store.
enable-when-possible enables cookies where the library supports them: Reactor Netty and the simple JDK request factory don't support cookies, so enable fails with them, while enable-when-possible leaves them unchanged.
HTTP interface groups accept cookie settings too, under spring.http.serviceclient.<group>, if one group needs a different rule.
How to check it: search your configuration for cookie-handling. If the property is missing, your cookie behaviour depends on the classpath.
"We validate the URL when the tenant registers it"
Validation at registration time catches the obvious cases, such as a tenant who types http://localhost:8080/admin. Keep it, because it gives the tenant a clear error early.
But registration-time validation checks a string, and the client connects to an IP address.
A hostname that resolves to a public address on the day the tenant registers can resolve to an internal address on the day the webhook fires.
InetAddressFilter checks the address at connection time, which is the only moment the answer is final. Validate at registration for a good error message, and filter at connection time for safety.
Conclusion
A tenant controls the URL. DNS controls the address behind it. With a proxy in the path, the proxy controls the connection. An SSRF defense works only at the point that makes the final connection, so put the filter wherever your traffic leaves the network.