-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fixes CORS headers needed by Elastic clients #85791
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
Conversation
Updates the default value for the `http.cors.allow-headers` setting to include headers used by Elastic client libraries. Also adds the `access-control-expose-headers` header to responses to CORS requests so that clients can successfully perform their product check.
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Hi @swallez, I've created a changelog YAML for you. |
@@ -110,9 +110,16 @@ Which methods to allow. Defaults to `OPTIONS, HEAD, GET, POST, PUT, DELETE`. | |||
// tag::http-cors-allow-headers-tag[] | |||
`http.cors.allow-headers` {ess-icon}:: | |||
(<<static-cluster-setting,Static>>) | |||
Which headers to allow. Defaults to `X-Requested-With, Content-Type, Content-Length`. | |||
Which headers to allow. Defaults to `X-Requested-With, Content-Type, Content-Length, Authorization, Accept, User-Agent, X-Elastic-Client-Meta`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it strange that we default access-control-allow-headers
to include Authorization
but access-control-allow-credentials
to false
?
Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is intentional:
access-control-allow-headers
, in a response to a preflight request, defines what headers (outside of the safelist) are allowed in CORS requests. Since clients set theAuthorization
header in their requests, it has to be allowed by the server in preflight responses.- Defaulting
access-control-allow-credentials
tofalse
forbids the use of browser-level credentials by clients, and thus requires clients to be provided with credential information that is then set in theAuthorization
header.
CORS is sometimes confusing 😅
@tvernum I'm reviving this old PR. Can you please have look at my reply to your comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but we should check whether @rjernst still wants to review.
I don't have any thoughts here. |
💔 Backport failed
You can use sqren/backport to manually backport by running |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
* Fixes CORS headers needed by Elastic clients Updates the default value for the `http.cors.allow-headers` setting to include headers used by Elastic client libraries. Also adds the `access-control-expose-headers` header to responses to CORS requests so that clients can successfully perform their product check. (cherry picked from commit 484d3f4)
* Fixes CORS headers needed by Elastic clients Updates the default value for the `http.cors.allow-headers` setting to include headers used by Elastic client libraries. Also adds the `access-control-expose-headers` header to responses to CORS requests so that clients can successfully perform their product check. (cherry picked from commit 484d3f4)
This PR updates the default values for CORS headers so that Elasticsearch client libraries that can run in a web browser (e.g. JavaScript client, Go & Rust clients compiled to WebAssembly) work out of the box by just enabling
http.cors.enabled: true
and settinghttp.cors.allow-origin
.It adds the following headers to
http.cors.allow-headers
's default value:Authorization
for webapp-level authentication,Accept
, andUser-Agent
andX-Elastic-Client-Meta
that are useful for telemetry.Additionally, a new
http.cors.expose-headers
setting allows configuring headers that are exposed to the code in the browser, defaulting toX-elastic-product
which allows clients to successfully run product checks.See also elastic/elasticsearch-rs#200