Git Product home page Git Product logo

Comments (6)

graemerocher avatar graemerocher commented on June 24, 2024

this sounds like you have the filter ordering incorrect

from micronaut-core.

somitmittal avatar somitmittal commented on June 24, 2024

@graemerocher thanks for quick reply. Is Cors filter of highest precedence?

As per cors filter code in Micronaut. I believe it is returning a response decorated with preflight headers if status is < 400.
In this case, how can I specify cors filter to be of highest precedence?

@NonNull
    private Publisher<MutableHttpResponse<?>> handlePreflightRequest(@NonNull HttpRequest<?> request, @NonNull ServerFilterChain chain, @NonNull CorsOriginConfiguration corsOriginConfiguration) {
        Optional<HttpStatus> statusOptional = this.validatePreflightRequest(request, corsOriginConfiguration);
        if (statusOptional.isPresent()) {
            HttpStatus status = (HttpStatus)statusOptional.get();
            if (status.getCode() >= 400) {
                return Publishers.just(HttpResponse.status(status));
            } else {
                MutableHttpResponse<?> resp = HttpResponse.status(status);
                this.decorateResponseWithHeadersForPreflightRequest(request, resp, corsOriginConfiguration);
                this.decorateResponseWithHeaders(request, resp, corsOriginConfiguration);
                return Publishers.just(resp);
            }
        } else {
            return Publishers.then(chain.proceed(request), (respx) -> {
                this.decorateResponseWithHeadersForPreflightRequest(request, respx, corsOriginConfiguration);
                this.decorateResponseWithHeaders(request, respx, corsOriginConfiguration);
            });
        }
    }

Can cors filter ever proceed with chain request if options preflight request succeeded and land into custom authorization filter and still fail there?

from micronaut-core.

somitmittal avatar somitmittal commented on June 24, 2024

@graemerocher can you please suggest how can I fix the ordering so that cors filter runs first?

from micronaut-core.

yawkat avatar yawkat commented on June 24, 2024

Add an order to your own filter that is higher than that of the cors filter, which should be 9250

from micronaut-core.

somitmittal avatar somitmittal commented on June 24, 2024

@yawkat
Few findings:
On using
@order(Ordered.LOWEST_PRECEDENCE) on the custom filter, its not working.
It fails on OPTIONS request.

curl --location --request OPTIONS 'http://localhost:8080/v2/api' \
--header 'Origin: http://www.google.com' \
--header 'Access-Control-Request-Method: POST'

But overriding the method getOrder works

override fun getOrder(): Int {
        return Integer.MAX_VALUE
    }

from micronaut-core.

somitmittal avatar somitmittal commented on June 24, 2024

Hey any updates here?

from micronaut-core.

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.