fix: Request.protocol returns 'https' for HTTP/2 after RST_STREAM (#1736)#1944
Open
guoyangzhen wants to merge 2 commits intokoajs:masterfrom
Open
fix: Request.protocol returns 'https' for HTTP/2 after RST_STREAM (#1736)#1944guoyangzhen wants to merge 2 commits intokoajs:masterfrom
guoyangzhen wants to merge 2 commits intokoajs:masterfrom
Conversation
Fixes koajs#1746 The origin getter returned this.req.headers.origin (the CORS Origin header) which ignores the proxy flag. Changed to construct origin from protocol and host getters, which already respect X-Forwarded-Proto and X-Forwarded-Host when app.proxy is true.
…ajs#1736) When using koa with http2.createSecureServer, Request.secure could incorrectly return false after the client sends RST_STREAM. In HTTP/2, after a stream reset, req.socket may switch from TLSSocket to ServerHttp2Stream which lacks the encrypted property. This fix falls back to checking req.stream.session.socket.encrypted for HTTP/2 connections when the primary socket check fails.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1944 +/- ##
==========================================
- Coverage 99.90% 99.80% -0.10%
==========================================
Files 9 9
Lines 2094 2100 +6
==========================================
+ Hits 2092 2096 +4
- Misses 2 4 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1736
When using koa with
http2.createSecureServer,Request.securecould incorrectly returnfalseafter the client sendsRST_STREAM.Root Cause
In HTTP/2, after a stream reset,
req.socketmay switch fromTLSSockettoServerHttp2Stream, which lacks theencryptedproperty. Theprotocolgetter only checkedthis.socket.encrypted, so it fell through to'http'.Fix
When
this.socket.encryptedis falsy, fall back to checkingreq.stream.session.socket.encryptedfor HTTP/2 connections.