Skip to content

Swagger UI: X-XSRF-TOKEN is sent to OAuth2 token url #1036

Closed
@daniel-shuy

Description

@daniel-shuy

Describe the bug
When configuring OpenAPI with OAuth2 security scheme and springdoc-openapi-ui with springdoc.csrf.enabled=true, Swagger UI will include X-XSRF-TOKEN in the request to the OAuth2 token url.

Certain OAuth2 providers (in my case, Keycloak) with CORS protection may cause the browser to block the request due to the presence of X-XSRF-TOKEN, since it is not typically in the Access-Control-Allow-Headers list.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using? 2.4.1
  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-ui:1.5.1
  • Provide with a sample code (HelloController) or Test that reproduces the problem:
new OpenAPI()
    .addSecurityItem(new SecurityRequirement()
        .addList("keycloak")
    )
    .components(new Components()
        .addSecuritySchemes("keycloak", new SecurityScheme()
            .type(SecurityScheme.Type.OAUTH2)
            .flows(new OAuthFlows()
                .authorizationUrl("http://<keycloakUrl>/auth/realms/<realm>/protocol/openid-connect/auth")
                .tokenUrl("http://<keycloakUrl>/auth/realms/<realm>/protocol/openid-connect/token")
            )
        )
    );
springdoc:
  swagger-ui:
    csrf:
      enabled: true

Expected behavior
Swagger UI should not include X-XSRF-TOKEN for OAuth2 token url requests.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions