spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Spring Cloud Gateway - CORS issue (preflight request and response is success but actual request's response is FORBIDDEN)

Open kumaritian opened this issue 3 years ago • 1 comments

Hello Together,

Below is my Global CORS configuration (i.e. in application.yml file) in the Spring Cloud API Gateway application and my preflight response is success. But then the actual graphql micro service request is failed with 403 FORBIDDEN error.

Please help to solve the issue.

Note:

  1. I didn't configure spring security (i.e. didn't add spring-boot-starter-security dependency) in both Spring cloud gateway application and graphql spring boot application (i.e. Micro service).
  2. Except graphql micro service other normal spring boot application request and response is success via Spring Cloud API Gateway.

Spring Boot Version : 2.7.2

global cors configuration

 globalcors:
    add-to-simple-url-handler-mapping: true
    cors-configurations:
      '[/**]':
        allowedOrigins: "*"
        allowedHeaders: "*"
        allowedMethods: "*"

Prelflight Request and Response: Response_To_Preflight_Request_is_SUCCESS

Actual Request and Response Response_To_Actual_Request_is_FAILED_FORBIDDEN

kumaritian avatar Aug 18 '22 01:08 kumaritian

Maybe U should add this dependency to U pom.xml:

<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

And some metadata in spring-autoconfigure-metadata.properties looks like :

org.springframework.cloud.util.ConditionalOnBootstrapDisabled$OnBootstrapDisabledCondition$OnBootstrapMarkerClassPresent=
org.springframework.cloud.util.ConditionalOnBootstrapDisabled$OnBootstrapDisabledCondition$OnBootstrapMarkerClassPresent.ConditionalOnClass=org.springframework.cloud.bootstrap.marker.Marker
org.springframework.cloud.util.ConditionalOnBootstrapEnabled$OnBootstrapEnabledCondition$OnBootstrapMarkerClassPresent=
org.springframework.cloud.util.ConditionalOnBootstrapEnabled$OnBootstrapEnabledCondition$OnBootstrapMarkerClassPresent.ConditionalOnClass=org.springframework.cloud.bootstrap.marker.Marker

in U classpath, then U yml configuration file will work

lgscofield avatar Sep 02 '22 01:09 lgscofield

@lgscofield : Hello Bro, Any other solution as I don't want to make changes in the Spring Boot components .

kumar-csice avatar Jan 13 '23 10:01 kumar-csice