Skip to content

Server servlet context path omitted when run with X-Forwarded-Prefix #2068

@joaonatalio

Description

@joaonatalio

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)

  1. Run Spring Boot application jar from local machine: java -jar target/springdoc-context-path-1.0-SNAPSHOT.jar

  2. 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 url http://localhost:8080/petstore/swagger/swagger-ui/index.html.

  3. Stop application and run docker compose up which uses nginx X-Forwarded-Prefix header with fixed /api value, just for demo purposes.

  4. Navigate to http://localhost:8080/api/petstore/swagger/swagger-ui.html. We're redirected to http://localhost:8080/api/swagger/swagger-ui/index.html, taking into account the passed X-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions