Skip to content

Preserve firewall in reactive Cloud Foundry security auto-configuration - #51549

Open
aashikantkumar wants to merge 1 commit into
spring-projects:mainfrom
aashikantkumar:gh-45377
Open

Preserve firewall in reactive Cloud Foundry security auto-configuration#51549
aashikantkumar wants to merge 1 commit into
spring-projects:mainfrom
aashikantkumar:gh-45377

Conversation

@aashikantkumar

Copy link
Copy Markdown

Fixes #45377

Hi team,

This PR addresses an issue where custom ServerWebExchangeFirewall configurations are lost when running reactive applications on Cloud Foundry.

What was happening?
When VCAP_APPLICATION is present, CloudFoundryReactiveActuatorAutoConfiguration used a BeanPostProcessor (WebFilterChainPostProcessor) to wrap WebFilterChainProxy.

The trouble with that approach is that instantiating a new WebFilterChainProxy creates a fresh instance with its private firewall field defaulting to new StrictServerWebExchangeFirewall(). As a result:

Any custom ServerWebExchangeFirewall bean declared by the user was discarded.
Direct customizations (e.g. calling setFirewall(...) on the proxy) were also lost.
Incoming requests were evaluated by the new proxy's strict firewall at the perimeter, rejecting valid requests that rely on customized firewall rules (like matrix parameters or specific URI encodings).
The Fix
Following @wilkinsona's suggestion in #45377, we aligned the reactive configuration with how the servlet side already handles this in IgnoredCloudFoundryPathsWebSecurityConfiguration:

Removed WebFilterChainPostProcessor.
Added a dedicated @order(-1) SecurityWebFilterChain bean matching /cloudfoundryapplication/** with permitAll(), csrf.disable(), and CORS configuration.
This allows Spring Security's native ServerHttpSecurityConfiguration to create and keep the single WebFilterChainProxy. Cloud Foundry routes are given higher precedence to bypass authentication, while the rest of the application's security configuration and the user's custom firewall remain completely untouched.

How this was verified
Added regression tests in CloudFoundryReactiveActuatorAutoConfigurationTests:

customFirewallBeanIsPreserved: Asserts that a custom ServerWebExchangeFirewall @bean stays on WebFilterChainProxy.
directlyConfiguredFirewallIsPreserved: Asserts that firewalls set directly via proxy.setFirewall(...) in a post-processor survive.
customFirewallIsInvokedOnRequests: Verifies runtime execution of firewall.getFirewalledExchange(...).
userSecurityWebFilterChainIsPreserved: Confirms that user-defined SecurityWebFilterChain beans coexist alongside the Cloud Foundry chain with correct ordering.
Ran:

bash
./gradlew :module:spring-boot-cloudfoundry:test
./gradlew :module:spring-boot-cloudfoundry:check
All reactive tests, servlet tests, checkstyle, and Spring JavaFormat checks pass cleanly.

Contributor Checklist
Signed-off-by trailer included in commit for DCO
Code formatted with Spring JavaFormat
Checkstyle checks pass
@author tag added
Unit/slice regression tests added

Prior to this commit, `CloudFoundryReactiveActuatorAutoConfiguration` registered a `BeanPostProcessor` (`WebFilterChainPostProcessor`) that intercepted the primary `WebFilterChainProxy` bean and instantiated a second, new `WebFilterChainProxy` wrapping the original. Because constructing a new `WebFilterChainProxy` initializes its private `firewall` field with `new StrictServerWebExchangeFirewall()`, any custom `ServerWebExchangeFirewall` (configured either via a Spring `@Bean` or via `proxy.setFirewall(...)`) was lost.

This commit aligns the reactive Cloud Foundry security configuration with its servlet counterpart (`IgnoredCloudFoundryPathsWebSecurityConfiguration` in `CloudFoundryActuatorAutoConfiguration`). The `BeanPostProcessor` is removed, and a dedicated `@Bean @order(-1) SecurityWebFilterChain` is registered for the path `/cloudfoundryapplication/**` with `permitAll()`, `csrf.disable()`, and CORS support.

Spring Security's `ServerHttpSecurityConfiguration` collects this chain and places it with higher precedence inside the single, global `WebFilterChainProxy`. The existing proxy instance—including its custom firewall, decorators, and settings—remains untouched.

Regression tests have been added to verify that:
- A custom `ServerWebExchangeFirewall` bean is preserved on the proxy.
- A firewall configured directly via a `BeanPostProcessor` calling `proxy.setFirewall(...)` is preserved.
- The custom firewall is executed at runtime during request processing.
- Application-defined `SecurityWebFilterChain` beans coexist with the Cloud Foundry chain under correct order.

Closes spring-projectsgh-45377

Signed-off-by: aashikantkumar <aashikantkumar2@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReactiveCloudFoundryActuatorAutoConfiguration ignores firewall set on the WebFilterChainProxy when postprocessing it

2 participants