-
-
Notifications
You must be signed in to change notification settings - Fork 535
Description
Describe the bug
The server servlet context path is omitted when Springdoc is running behind a reverse proxy and an X-Forwarded-Prefix
header is present. The issue was originally reported in #2058 but dismissed, lacking some clarity in the reproduction.
Please see the new working example in https://github.com/joaonatalio/springdoc-context-path-bug demonstrating the issue for spring-boot-parent:3.0.2
and springdoc-openapi-starter-webmvc-ui:2.0.2
.
In application.yml
we have servlet.forward-headers-strategy: framework
defined so that our app processes the incoming X-Forwarded-*
from our reverse proxy, like it's suggested in springdoc's 2.x FAQ.
In our case we defined the following springdoc
config to show the problematic redirect behaviour more clearly:
springdoc:
api-docs:
path: /swagger/api-docs
swagger-ui:
path: /swagger/swagger-ui.html
To Reproduce
(For spring-boot:3.0.2
and springdoc-openapi-starter-webmvc-ui:2.0.2
)
-
Run Spring Boot application jar from local machine:
java -jar target/springdoc-context-path-1.0-SNAPSHOT.jar
-
Navigate to
http://localhost:8080/petstore/swagger/swagger-ui.html
to view petstore's swagger-ui, all resources are loaded correctly since it redirects the initial request to the expected urlhttp://localhost:8080/petstore/swagger/swagger-ui/index.html
. -
Stop application and run
docker compose up
which uses nginxX-Forwarded-Prefix
header with fixed/api
value, just for demo purposes. -
Navigate to
http://localhost:8080/api/petstore/swagger/swagger-ui.html
. We're redirected tohttp://localhost:8080/api/swagger/swagger-ui/index.html
, taking into account the passedX-Forwarded-Prefix
header, but omitting the servlet context path entirely.
Expected behavior
In step 4) the swagger-ui.html
should redirect to http://localhost:8080/api/petstore/swagger/swagger-ui/index.html
, taking into account the passed X-Forwarded-Prefix
and the servlet context path.