-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: use :authority header of http2 requests as host #1262
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1262 +/- ##
======================================
Coverage 100% 100%
======================================
Files 5 5
Lines 391 392 +1
======================================
+ Hits 391 392 +1
Continue to review full report at Codecov.
|
I think this should be feature not bug fix? |
cc @dead-horse |
@@ -252,6 +252,7 @@ module.exports = { | |||
get host() { | |||
const proxy = this.app.proxy; | |||
let host = proxy && this.get('X-Forwarded-Host'); | |||
if (this.req.httpVersionMajor >= 2) host = this.get(':authority'); |
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.
use this.req. authority
will be better.
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.
This seems to be an undocumented property. Is it save to use it and should koa use undocumented props?
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.
It's unsafe either way, at least this.req.authority
is a specific getter with a sane naming that conforms with the RFC headerfield.
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.
this.req.headers
is the documented way to access http headers and this.get
is using this way. And :authority
is the official header name from RFC 7540. So this way should not be unsafe.
Whereas this.req.authority
is not documented and therefore could change in a minor update and is considered an internal API (as described in the node COLLABORATOR_GUIDE).
But I agree that this.req.authority
should be part of the public API and I just created an issue in the node repo (nodejs/node#23825).
2.6.0 |
The requested change to keep x-forwarded values as host is not in? |
@panva The current order is...
(See |
Yeah, as requested in the review by @dead-horse
But the fact is :authority will overwrite what's in the x-forwarded-host if proxy is true (looking at master) It should be like this imho
|
I think this works for me, |
I agree, but the implementation takes :authority over x-forwarded-host. |
@panva I will release a bugfix version soon. |
@fengmk2 perfect! |
The now stable http2 api does not use the host header. The host can be found in the http2
:authority
header. Therefore koa should use this header instead.This fixes the
host
property and all properties that depend on it for http2 requests. These dependent properties include thehostname
, theorigin
and theURL
. This will also fix #1174.