Closed krezovic closed 2 months ago
Looks like a off-by-one error in ForwardedHeaderTransformer#getForwardedPrefix
.
May I ask why not /myapp
but /myapp,/
?
It was a misconfiguration;
We tried to implement sub-path based routing, but rather than using spring-cloud-gateway builtin "stripPrefix" filter, we used "rewritePath" twice - and each rewritePath invocation adds a segment to X-Forwarded-Prefix
We did eventually switch to stripPrefix, so it ended up as /myapp
... but that was after several hours of debugging "why the webflux app suddenly fails"
Since it went unnoticed for more than a year on our side, I figured it would be nice to report the issue to save somebody else the trouble.
Affects: 6.1
I have stumbled upon hard-to-debug issue which affects the reactive stack (webflux) but works fine in servlet stack (webmvc)
The spring-cloud-gateway had sent the
X-Forwarded-Prefix = '/myapp,/'
header due to multiple "rewrite" usages.Now, with
server.forward-headers-strategy=framework
everything works fine in servlet stack.However, in reactive stack, it fails with
I'd appreciate if this was unified across both servlet and reactive stacks. It took quite a while to debug this as we kept receiving error 400 and no @ControllerAdvice @ExceptionHandler was being called.
Reproducer:
https://github.com/krezovic/spring-forwardedprefix
Simply run
./mvnw test