Skip to content

Custom Spring Security firewall is lost when using spring-boot-cloudfoundry and Actuator in a reactive web application - #51549

Merged
wilkinsona merged 2 commits into
spring-projects:4.0.xfrom
aashikantkumar:gh-45377
Sep 8, 2026
Merged

Custom Spring Security firewall is lost when using spring-boot-cloudfoundry and Actuator in a reactive web application#51549
wilkinsona merged 2 commits into
spring-projects:4.0.xfrom
aashikantkumar:gh-45377

Conversation

@aashikantkumar

Copy link
Copy Markdown
Contributor

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 2, 2026

@wilkinsona wilkinsona left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. I've left a couple of comments for your consideration.

@wilkinsona wilkinsona self-assigned this Sep 7, 2026
@wilkinsona wilkinsona changed the title Preserve firewall in reactive Cloud Foundry security auto-configuration Custom Spring Security firewall is lost when using spring-boot-cloudfoundry and Actuator in a reactive web application Sep 8, 2026
Prior to this commit, CloudFoundryReactiveActuatorAutoConfiguration
registered a BeanPostProcessor replaced the WebFilterChainProxy bean
with one that handled CF security and delegated to the existing
chain.

Constructing a new WebFilterChainProxy resulted in the loss of any
firewall customization on the existing chain as Spring Security does
not provide an API to retreive the firewall from the existing chain
and apply it to the new chain.

This commit changes the approach and aligns it with its Servlet
counterpart. Instead of post-processing the filter chain proxy, a new
SecurityWebFilterChain that handles cloudfoundryapplication/**
is defined. This chain becomes part of the existing
WebFilterChainProxy, preserving any firewall customization.

Signed-off-by: aashikantkumar <aashikantkumar2@gmail.com>

See spring-projectsgh-51549
wilkinsona added a commit to aashikantkumar/spring-boot that referenced this pull request Sep 8, 2026
…figuration"

See spring-projectsgh-51549

Signed-off-by: Andy Wilkinson <andy.wilkinson@broadcom.com>
@wilkinsona
wilkinsona changed the base branch from main to 4.0.x September 8, 2026 08:17
See spring-projectsgh-51549

Signed-off-by: Andy Wilkinson <andy.wilkinson@broadcom.com>
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 8, 2026
@wilkinsona wilkinsona modified the milestones: 4.0.x, 4.0.9 Sep 8, 2026
@wilkinsona
wilkinsona merged commit ad8f14e into spring-projects:4.0.x Sep 8, 2026
1 check passed
@wilkinsona

Copy link
Copy Markdown
Member

Thanks very much, @aashikantkumar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Spring Security firewall is lost when using spring-boot-cloudfoundry and Actuator in a reactive web application

3 participants