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

Why does the credentials CORS options accept only false? #4478

Closed
hamzahamidi opened this issue Feb 1, 2024 · 4 comments
Closed

Why does the credentials CORS options accept only false? #4478

hamzahamidi opened this issue Feb 1, 2024 · 4 comments
Labels
support Questions, discussions, and general support

Comments

@hamzahamidi
Copy link

Runtime

nodejs

Runtime version

v18.17.1

Module version

21.3.0

Used with

No response

Any other relevant information

No response

How can we help?

From the json schema here

   credentials: Validate.boolean().when('origin', { is: 'ignore', then: false }).default(false),

I'm trying to set the CORS credentials to true like:

      cors: {
        origin: ['*'],
        credentials: true,
        additionalHeaders: [
          'Accept',
          'Authorization',
          'Content-Type',
          'If-None-Match',
          'Access-Control-Allow-Credentials',
        ],
        additionalExposedHeaders: ['WWW-Authenticate', 'Server-Authorization', 'Access-Control-Allow-Credentials'],

Yet I get:

 '[1] "cors.credentials" must be one of [false]\x1B[0m',
@hamzahamidi hamzahamidi added the support Questions, discussions, and general support label Feb 1, 2024
@devinivy
Copy link
Member

devinivy commented Feb 1, 2024

Unfortunately CORS doesn't permit you to use the wildcard * for origins while also allowing credentials: browsers wont allow it. This is described in some more detail here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials

@hamzahamidi
Copy link
Author

Thanks for the info. However, when I change the origin to a specific url. Somehow the origin still equals to ignore.
image

@devinivy
Copy link
Member

devinivy commented Feb 1, 2024

If you could share some more code that would be useful! Are you configuring this on a route, or on the server?

@hamzahamidi
Copy link
Author

It's on the server side. It's coming from this line

   const settings = internals.config([core.settings.routes, handlerDefaults, realm.settings, rulesConfig, config]);

At some point the value is changed to ignore

   config = Hoek.applyToDefaults(config, item, { shallow: ['bind', 'validate.headers', 'validate.payload', 'validate.params', 'validate.query', 'validate.state'] });

I couldn't catch when because it's called hundred of times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

2 participants