Skip to content
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

Cookies and CORS #8096

Open
axi92 opened this issue Jul 15, 2022 · 0 comments
Open

Cookies and CORS #8096

axi92 opened this issue Jul 15, 2022 · 0 comments

Comments

@axi92
Copy link

axi92 commented Jul 15, 2022

Q&A (please complete the following information)

  • OS: ubuntu 20.04
  • Browser: firefox
  • Version: 102
  • Method of installation: dist assets
  • Swagger-UI version: I guess the newest, where can I see that?
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

We have a modified swagger-initializer.js that is working accept the cookies are not sent with the requests to those subdomains:

window.onload = function() {
  //<editor-fold desc="Changeable Configuration Block">

  // the following lines will be replaced by docker/configurator, when it runs in a docker-container
  window.ui = SwaggerUIBundle({
    urls: [ 
      { url: "https://inventum.domain.com/apidocs.json", name: "Inventum API"},
      { url: "https://releases.domain.com/apidocs.json", name: "SFW Releases API" } 
    ],
    validatorUrl: 'none',
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",
    useJQuery: true,
    withCredentials: true
  });
  $('.topbar-wrapper > a > img').attr('src', 'logo.svg');
  $('#swagger-ui > section > div.topbar > div > div > form > label > span').text('API Definition');
console.log(document.cookie); // we tried to print the cookies to see if they are set but as the cookies got HttpOnly set to true you are not able to print those with JS
  //</editor-fold>
};

Now the problem is the requests that are made are sent without the cookies. I can see the cookies are set and if I open the url in a new tab and request the same url the cookies are sent. So my guess is that it has something to do with CORS.
Is there a way to tell swagger it has to send to cookies in that request?
It is the same domain, only different subdomains.
Those are the cookie settings:
grafik
Domain: ".domain.com"
It works for every other service that we use, only swagger does not send the cookies on CORS requests.

Withou those cookies set in the request to the openapi.json swagger won't get there.
Swagger/OpenAPI definition:

# your YAML here

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
})
?yourQueryStringConfig

Screenshots

There you can see, swagger never gets he openapi.json definition because the cookies are no sent with this request.
grafik

How can we help?

I need swagger to send the cookies with every request to those servers where it loads the *.json openapi definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant