Skip to content

Conversation

@jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Mar 3, 2020

Fix #59045

Summary

The host header value is currently being overridden (always in console). This should not be the case and is a regression from 7.4 -> 7.5.

The regression was introduced here: #46200

Release Note

We fixed a bug in Console's proxy that would always override the "host" header.

Checklist

For maintainers

Copy the behaviour or Wreck.request from 7.4. This is a regression
for setting the Host header value.
@jloleysens jloleysens added Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v7.7.0 v7.6.0 labels Mar 3, 2020
@jloleysens jloleysens requested a review from cjcenizal March 3, 2020 13:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test locally but the code looks good to me overall. Had one suggestion for a way to possibly simplify things. Thanks for fixing this!

...finalUserHeaders,
'content-type': 'application/json',
'transfer-encoding': 'chunked',
host: hostname,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past, I've seen the spread object applied after defining default values, as a way to override the defaults with anything defined in the spread object. Would this work here? If so then we won't need finalUserHeaders or hasHostHeader.

    headers: {
      'content-type': 'application/json',
      'transfer-encoding': 'chunked',
      host: hostname,
      ...headers,
    },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That solution would work for some cases but unfortunately the override will only take affect if the header object entry name is the same - it could be Host or HoSt or etc.

In the latter case (as in the original issue) both Host and host would be in the headers passed to the endpoint.

@cjcenizal cjcenizal added v7.6.2 and removed v7.6.0 labels Mar 3, 2020
@cjcenizal
Copy link
Contributor

@jloleysens I removed the 7.6.0 label and added 7.6.2 since that's the next patch release we can ship this with (after 7.6.1 is released today).

@jloleysens jloleysens merged commit 5a21805 into elastic:master Mar 4, 2020
@jloleysens jloleysens deleted the console/fix/host-header-in-proxy branch March 4, 2020 07:43
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 4, 2020
* fix: only override hostname if none was provided

Copy the behaviour or Wreck.request from 7.4. This is a regression
for setting the Host header value.

* Refactor variable name

* [skip ci] Fix comment
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 4, 2020
* fix: only override hostname if none was provided

Copy the behaviour or Wreck.request from 7.4. This is a regression
for setting the Host header value.

* Refactor variable name

* [skip ci] Fix comment

# Conflicts:
#	src/plugins/console/server/lib/proxy_request.test.ts
#	src/plugins/console/server/lib/proxy_request.ts
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

jloleysens added a commit that referenced this pull request Mar 4, 2020
* fix: only override hostname if none was provided

Copy the behaviour or Wreck.request from 7.4. This is a regression
for setting the Host header value.

* Refactor variable name

* [skip ci] Fix comment

# Conflicts:
#	src/plugins/console/server/lib/proxy_request.test.ts
#	src/plugins/console/server/lib/proxy_request.ts
jloleysens added a commit that referenced this pull request Mar 4, 2020
* fix: only override hostname if none was provided

Copy the behaviour or Wreck.request from 7.4. This is a regression
for setting the Host header value.

* Refactor variable name

* [skip ci] Fix comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Console Dev Tools Console Feature Feature:Dev Tools release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v7.6.2 v7.7.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overriding Host header using elasticsearch.customHeaders doesn't seem to affect requests from dev tools console

4 participants