-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP CORS headers not included. #21457
Comments
@sjaakd Thanks, what happens if you do:
? Would like to see if the system property replacement is a problem or not |
Just tried that locally. No effect. |
Furthermore, I do use 2 @RouteFilter
public void addResponse(RoutingContext rc) {
rc.response().headers().set( API_VERSION_HEADER, provider.version );
rc.next();
} @RouteFilter
public void modifyAcceptHeader(RoutingContext rc) {
String url = rc.normalizedPath();
if ( url.endsWith( "openapi.json" ) ) {
String acceptHeader = rc.request().headers().get( ACCEPT );
if ( acceptHeader != null && !acceptHeader.contains( "yaml" ) ) {
rc.request().headers().set( ACCEPT, "application/json" );
}
rc.reroute( url.substring( 0, url.lastIndexOf( '.' ) ) );
return;
}
else if ( url.endsWith( "openapi.yaml" ) ) {
rc.reroute( url.substring( 0, url.lastIndexOf( '.' ) ) );
return;
}
rc.next();
} could that somewhat be related? (did not find the time yet to investigate further and making a minimum reproducer). |
@sjaakd Looks like the problem is due to the fact the browser is not indicating it requires the CORS headers - it does not include |
That is true.. I test locally. But the headers are included if i change to And.. important: external verification fails on cors headers. Checkout: https://developer.overheid.nl/apis/minbzk-bro-grondwatermonitoringput-(gmw)-uitgifte/score-detail . Note: tonight this compliance test will (hopefully) pass again and I changed the application.properties this morning. EDIT: I added |
@sjaakd So looks like it is about |
An interesting observation: after a rerun of the test last night I noticed that another design rule is failing. The API-Version header (see |
Hi @sjaakd @sberyozkin - Happy to have a look. Please provide a small reproducer that I can run locally. Thanks :) |
Hi @phillip-kruger thanks.. I'll do my best to provide one as soon as possible (hopefully a bit later this week). |
@phillip-kruger , @sberyozkin : the reproducer can be found here. Thanks for looking into this!. |
I checked the latest release: 2.4.2.Final .. behavior is identical |
@sjaakd I had a look and in terms of CORS, everything seems to be OK. One issue that exist, is that your custom (API version) header gets removed when OpenAPI adds the default CORS (i.e when you do not have any CORS config in application.properties) Here the results from my investigation: When CORS is not configured:
gives this response headers:
Before my fix the API-Version was not included. Another thing that we potentially do it to only included this default if the origin request header is present. In fact I am not even sure why we need to add default headers at all... ? (This pre-date my involvement) When CORS config exist:
gives this response headers:
I'll do a PR for my fix soon, but that is not solving your issue. Please can you test the |
I can confirm. My observation is consistent with yours. I do get the headers this way.
That's interesting. It would be nice if the user would have some control over the headers regardless the
I noticed, when the |
I do not think it makes sense to have the header in the response if no origin is available ? (cross ORIGIN being the thing we are solving here) But, what I would suggest :
If you need the CORS header to be included always, maybe we can add another config that, when set to true, does not check for origin ? (@sberyozkin ?) |
@phillip-kruger .. Thanks for you quick answers. Just to clarify:
That would be great. I'm trying to do some reading up and found this on the swagger documentation. Are you suggestion a feature that CORS is handled automatically according this documentation? Does this (openapi) somehow deviates from the regular way that Quarkus supports CORS? You see: I'm a bit lost here on how this all fits together.
Are you referring to Anyway: both would be really cool. |
Quarkus OpenAPI already support CORS (that is the default I refer too), but it can be set by the client too. There are two scenarios here:
By default we make it very open (*), but you can override it by using the CORS config as defined in Quarkus: https://quarkus.io/guides/http-reference#cors-filter to narrow it to your domains.
The, w.r.t what I was referring to, both a and b :) |
Now I finally get it 😄 . So If I were to host a combined swagger page (I've later on multiple of these REST services, the CORS headers would be applicable if I host that combined page in a different domain. That is obviously not the case here. I therefore think that the implementer of the validation website (developers at the dutch government) have understood this particular aspect the wrong way.
Great! Do you want met to open 2 new feature requests for these (and refer to our dialogue here)? Is there something I can contribute? |
@sjaakd - So what we maybe can consider (@sberyozkin to comment) is to, with some config flag, always add the CORS headers (regardless of the origin request header). I am not too familiar with that part of the code (hence @sberyozkin to comment) so I am not sure if it's even possible. But if we can, then you can set the flag, and should pass the validation. Yes please open 2 issues as discussed, thanks :) |
Done.. My pleasure! |
That would solve my issue. But I can imagine this is not according the CORS specs. @sberyozkin to be the judge on that one. |
Can we close this ? |
@phillip-kruger I guess we did not receive a verdict from @sberyozkin on this matter. That's why I left it open. |
Ok I leave this for @sberyozkin to close :) |
Hi @phillip-kruger @sjaakd Sorry, looks like I've badly missed commenting on this issue. I've read through all of it and as far as I understand the reason it is still open is that an option of providing CORS headers without even the browsers requesting them with I believe Quarkus should not do it, it would not be CORS spec compliant and it is unclear what side-effects it may have. @sjaakd IMHO, the simplest option would be for your application to register a custom Vertx or even pre-match JAX-RS filter which would make sure the required CORS headers are reported even if they are not requested by the browser. Hope it makes sense, let me close this issue. Please create another more specific issue if you'd like to continue discussing an option of the CORS headers being pushed by Quarkus without thanks |
I agree.
That will not be needed. The validation service reporting these CORS issues has been fixed. Thanks for your answer! |
Describe the bug
We have the following settings in our
application properties
Expected behavior
CORS headers included
Actual behavior
CORS headers not included.
However, changing the configuration (strangly enough) to
Or omitting this setting altogether will trigger the headers.
which seems to be in conflict to the documentation
How to Reproduce?
Service with
quarkus.http.cors=false
:https://publiek.broservices.nl/gm/gmw-v1.1/openapi
Service with
https://publiek.broservices.nl/gm/gmn-v1.0/openapi
Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.3.1.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)mvn 3.6.3
Additional information
No response
The text was updated successfully, but these errors were encountered: