Coder Social home page Coder Social logo

Comments (9)

spencergibb avatar spencergibb commented on May 26, 2024 2

Closing in favor of #3357

from spring-cloud-gateway.

abelsromero avatar abelsromero commented on May 26, 2024 1

If we remove the header before we dispatch the request in the circuit breaker filter we can avoid the CORS filter. At least that is the one solution I thought of.

Funny, we were discussing this with @spikymonkey before. In theory yes, but I assume you want those headers to be forwarded also to the fallback service. In case they want to validate CORS at that level too.

from spring-cloud-gateway.

ryanjbaxter avatar ryanjbaxter commented on May 26, 2024 1

Thats what I was wondering, but if the fallback URL is forward and the CORS has already been validated before the CB is tripped and we are therefore just forwarding the request to another endpoint in the gateway I don't think we need to validate CORS again.

from spring-cloud-gateway.

ryanjbaxter avatar ryanjbaxter commented on May 26, 2024

I took a look at this today, but I am unsure what the right path forward may be.

I am wondering if the Cors configuration should even come into play when the URI is forward:/ since we are forwarding the request to ourselves?

@spencergibb what do you think?

from spring-cloud-gateway.

abelsromero avatar abelsromero commented on May 26, 2024

From the top of my head, the CORS components come from spring-web and it's a Global Web Filter, not a SCG Filter. So I thought it could not be disabled per route.
I kind of expected the solution would be to resolve the forward:/ URL to avoid passing a relative value. Isn't it the case?

from spring-cloud-gateway.

ryanjbaxter avatar ryanjbaxter commented on May 26, 2024

Ah you are right about the CORS filter. When I was debugging the code I was not paying attention to the package and I just assumed it was handled by the Gateway.

Either way it seems like the CORS filter is based off the presence of the Origin header being present.
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java#L44

If we remove the header before we dispatch the request in the circuit breaker filter we can avoid the CORS filter. At least that is the one solution I thought of.

from spring-cloud-gateway.

spencergibb avatar spencergibb commented on May 26, 2024

I am wondering if the Cors configuration should even come into play when the URI is forward:/ since we are forwarding the request to ourselves?

Sounds right

I kind of expected the solution would be to resolve the forward:/ URL to avoid passing a relative value.

No, there's nothing to resolve. It's always relative, it can never be a full url.

from spring-cloud-gateway.

spencergibb avatar spencergibb commented on May 26, 2024

If we remove the header before we dispatch the request in the circuit breaker filter we can avoid the CORS filter.

I can't think of another solution than this. Modify ForwardRoutingFilter, I think.

from spring-cloud-gateway.

spencergibb avatar spencergibb commented on May 26, 2024

In fact, we already have a place to manipulate the request for forwarding

public static Mono<Void> handle(DispatcherHandler handler, ServerWebExchange exchange) {
// remove attributes that may disrupt the forwarded request
exchange.getAttributes().remove(GATEWAY_PREDICATE_PATH_CONTAINER_ATTR);
return handler.handle(exchange);
}

from spring-cloud-gateway.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.