Skip to content

fix: correctly handle empty host#5764

Merged
gurgunday merged 7 commits into
mainfrom
hostname-fix
Oct 24, 2024
Merged

fix: correctly handle empty host#5764
gurgunday merged 7 commits into
mainfrom
hostname-fix

Conversation

@gurgunday

@gurgunday gurgunday commented Oct 24, 2024

Copy link
Copy Markdown
Member

So I took another look but the original PR seems like the best way to fix this issue

Because node's http server does have a setting to disable the host header requirement, both host and authority can be undefined, and we need to take those configurations into account in Fastify

And if host exists but is empty and authority is undefined (valid request), we should handle that correctly as well

@gurgunday gurgunday added the bugfix Issue or PR that should land as semver patch label Oct 24, 2024
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 24, 2024
Comment thread test/request-header-host.test.js
Comment thread lib/request.js
// now fall back to port from host/:authority header
const portFromHeader = parseInt((this.headers.host || this.headers[':authority']).split(':').slice(-1)[0])
let host = (this.headers.host ?? this.headers[':authority'])
if (this.server.server.requireHostHeader === false) host ??= ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using the http.Server for checking the properties, it is better because it may exists in http, https or http2 options. It should be always the same when we use multiple server instance.

@Eomm Eomm mentioned this pull request Oct 24, 2024
Comment thread lib/request.js

@Uzlopak Uzlopak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RSLGTM

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice!

Thanks @climba03003 for taking over, really short on time currently 😄

@gurgunday gurgunday merged commit d6f0b0b into main Oct 24, 2024
@gurgunday gurgunday deleted the hostname-fix branch October 24, 2024 18:09
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Issue or PR that should land as semver patch documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants