Skip to content

[NET-4897] net/http host header is now verified and request.host that contains socked now error#18129

Merged
jmurret merged 14 commits intomainfrom
jm/req-host-val
Jul 14, 2023
Merged

[NET-4897] net/http host header is now verified and request.host that contains socked now error#18129
jmurret merged 14 commits intomainfrom
jm/req-host-val

Conversation

@jmurret
Copy link
Copy Markdown
Member

@jmurret jmurret commented Jul 13, 2023

Description

This is related to #18124 where we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity, including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used, but we need valid and meaningful hostname. Prior versions go Go would clean the host header, and strip slashes in the process, but go1.20.6 and go1.19.11 no longer do, and reject the host header. Around the community we are seeing that others are intercepting the req.host and if it starts with a slash or ends with .sock, they changing the host to localhost or another dummy value.

client: define a "dummy" hostname to use for local connections by thaJeztah · Pull Request #45942 · moby/moby

Testing & Reproduction steps

Check CI tests.

Links

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/contributing Additions and enhancements to community contributing materials type/ci Relating to continuous integration (CI) tooling for testing or releases labels Jul 13, 2023
@jmurret jmurret added pr/no-changelog PR does not need a corresponding .changelog entry backport/1.13 backport/1.15 This release series is no longer active on CE. Use backport/ent/1.15. backport/1.16 This release series is no longer active on CE. Use backport/ent/1.16. labels Jul 13, 2023
@jmurret jmurret marked this pull request as ready for review July 13, 2023 21:32
Copy link
Copy Markdown
Contributor

@dhiaayachi dhiaayachi left a comment

Choose a reason for hiding this comment

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

Thank you @jmurret !
I left a comment about the go version change, other than that LGTM!

Copy link
Copy Markdown
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

This PR seems fine as a mitigation for the Go team breaking functionality.

Is the Go team expected to fix this in the future release. It seems like the net/http code that is handling the host header knows about the URLs scheme for the request and could more intelligently handle host headers that look like unix sockets or pipes.

}

if strings.HasPrefix(r.url.Host, "/") {
r.url.Host = "localhost"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So . or - may be accepted (see moby/moby#45942 (review)), but yeah, empty would've been most transparent.

Copy link
Copy Markdown
Collaborator

@nfi-hashicorp nfi-hashicorp left a comment

Choose a reason for hiding this comment

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

Some nits, but good enough to 🚢

@jmurret
Copy link
Copy Markdown
Member Author

jmurret commented Jul 14, 2023

Sorry for the late comment but I just noticed that we don't explicitly set the go-version in go-test-sdk-1-20. I think that we should be for consistency with the other jobs.

with:
directory: sdk
runs-on: ${{ needs.setup.outputs.compute-xl }}
repository-name: ${{ github.repository }}
go-tags: "${{ github.event.repository.name == 'consul-enterprise' && 'consulent consulprem consuldev' || '' }}"

This is fixed in 19634a4

@jmurret jmurret merged commit 5af7390 into main Jul 14, 2023
@jmurret jmurret deleted the jm/req-host-val branch July 14, 2023 20:53
jmurret added a commit that referenced this pull request Jul 14, 2023
… contains socked now error (#18129)

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
jmurret added a commit that referenced this pull request Jul 14, 2023
… contains socked now error (#18129)

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
jmurret added a commit that referenced this pull request Jul 14, 2023
… contains socked now error (#18129)

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
jmurret added a commit that referenced this pull request Jul 14, 2023
…st.host that contains socked now error into release/1.13.x (#18142)

## Backport

This PR is auto-generated from #18129 to be assessed for backporting due
to the inclusion of the label backport/1.13.


:rotating_light:
>**Warning** automatic cherry-pick of commits failed. If the first
commit failed,
you will see a blank no-op commit below. If at least one commit
succeeded, you
will see the cherry-picked commits up to, _not including_, the commit
where
the merge conflict occurred.

The person who merged in the original PR is:
@jmurret
This person should manually cherry-pick the original PR into a new
backport PR,
and close this one when the manual backport PR is merged in.

> merge conflict error: POST
https://api.github.com/repos/hashicorp/consul/merges: 409 Merge conflict
[]



The below text is copied from the body of the original PR.

---

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern


---

<details>
<summary> Overview of commits </summary>

- 747195f -
5164924 -
f4d6ca1 -
a474071 -
8c03b36 -
c50b17c -
cc8eaf8 -
ce10138 -
133c7ec -
b0bd440 -
8f22308 -
f8578b0 -
4452224 -
19634a4

</details>

---------

Co-authored-by: temp <[email protected]>
Co-authored-by: John Murret <[email protected]>
jmurret added a commit that referenced this pull request Jul 17, 2023
… contains socked now error (#18129)

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern
jmurret added a commit that referenced this pull request Jul 17, 2023
…st.host that contains socked now error into release/1.15.x (#18144)

## Backport

This PR is auto-generated from #18129 to be assessed for backporting due
to the inclusion of the label backport/1.15.


:rotating_light:
>**Warning** automatic cherry-pick of commits failed. If the first
commit failed,
you will see a blank no-op commit below. If at least one commit
succeeded, you
will see the cherry-picked commits up to, _not including_, the commit
where
the merge conflict occurred.

The person who merged in the original PR is:
@jmurret
This person should manually cherry-pick the original PR into a new
backport PR,
and close this one when the manual backport PR is merged in.

> merge conflict error: POST
https://api.github.com/repos/hashicorp/consul/merges: 409 Merge conflict
[]



The below text is copied from the body of the original PR.

---

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern


---

<details>
<summary> Overview of commits </summary>

- 747195f -
5164924 -
f4d6ca1 -
a474071 -
8c03b36 -
c50b17c -
cc8eaf8 -
ce10138 -
133c7ec -
b0bd440 -
8f22308 -
f8578b0 -
4452224 -
19634a4

</details>

---------

Co-authored-by: temp <[email protected]>
Co-authored-by: John Murret <[email protected]>
jmurret added a commit that referenced this pull request Jul 17, 2023
…st.host that contains socked now error into release/1.14.x (#18143)

## Backport

This PR is auto-generated from #18129 to be assessed for backporting due
to the inclusion of the label backport/1.14.


:rotating_light:
>**Warning** automatic cherry-pick of commits failed. If the first
commit failed,
you will see a blank no-op commit below. If at least one commit
succeeded, you
will see the cherry-picked commits up to, _not including_, the commit
where
the merge conflict occurred.

The person who merged in the original PR is:
@jmurret
This person should manually cherry-pick the original PR into a new
backport PR,
and close this one when the manual backport PR is merged in.

> merge conflict error: POST
https://api.github.com/repos/hashicorp/consul/merges: 409 Merge conflict
[]



The below text is copied from the body of the original PR.

---

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern


---

<details>
<summary> Overview of commits </summary>

- 747195f -
5164924 -
f4d6ca1 -
a474071 -
8c03b36 -
c50b17c -
cc8eaf8 -
ce10138 -
133c7ec -
b0bd440 -
8f22308 -
f8578b0 -
4452224 -
19634a4

</details>

---------

Co-authored-by: temp <[email protected]>
Co-authored-by: John Murret <[email protected]>
jmurret added a commit that referenced this pull request Jul 17, 2023
…st.host that contains socked now error into release/1.16.x (#18145)

* no-op commit due to failed cherry-picking

* [NET-4897] net/http host header is now verified and request.host that contains socked now error (#18129)

### Description

This is related to #18124 where
we pinned the go versions in CI to 1.20.5 and 1.19.10.

go 1.20.6 and 1.19.11 now validate request host headers for validity,
including the hostname cannot be prefixed with slashes.

For local communications (npipe://, unix://), the hostname is not used,
but we need valid and meaningful hostname. Prior versions go Go would
clean the host header, and strip slashes in the process, but go1.20.6
and go1.19.11 no longer do, and reject the host header. Around the
community we are seeing that others are intercepting the req.host and if
it starts with a slash or ends with .sock, they changing the host to
localhost or another dummy value.

[client: define a "dummy" hostname to use for local connections by
thaJeztah · Pull Request #45942 ·
moby/moby](moby/moby#45942)

### Testing & Reproduction steps

Check CI tests.

### Links
* [ ] updated test coverage
* [ ] external facing docs updated
* [ ] appropriate backport labels added
* [ ] not a security concern

---------

Co-authored-by: temp <[email protected]>
Co-authored-by: John Murret <[email protected]>