From 024ab86be63caaca11a912fcce2542305feb1e39 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 8 Jan 2025 10:47:40 +0100 Subject: [PATCH] [network] Verify connection NPN against negotiated NPN. --- netwerk/protocol/http/nsHttpConnection.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/netwerk/protocol/http/nsHttpConnection.cpp b/netwerk/protocol/http/nsHttpConnection.cpp index 706dba7e3b..d889d73971 100644 --- a/netwerk/protocol/http/nsHttpConnection.cpp +++ b/netwerk/protocol/http/nsHttpConnection.cpp @@ -323,7 +323,8 @@ nsHttpConnection::StartSpdy(uint8_t spdyVersion) if (!mTLSFilter) { mTransaction = mSpdySession; } else { - mTLSFilter->SetProxiedTransaction(mSpdySession); + rv = mTLSFilter->SetProxiedTransaction(mSpdySession); + NS_ENSURE_SUCCESS_VOID(rv); } if (mDontReuse) { mSpdySession->DontReuse(); @@ -355,6 +356,7 @@ nsHttpConnection::EnsureNPNComplete(nsresult &aOut0RTTWriteHandshakeValue, nsCOMPtr securityInfo; nsCOMPtr ssl; nsAutoCString negotiatedNPN; + nsAutoCString transactionNPN; GetSecurityInfo(getter_AddRefs(securityInfo)); if (!securityInfo) { @@ -373,6 +375,18 @@ nsHttpConnection::EnsureNPNComplete(nsresult &aOut0RTTWriteHandshakeValue, } rv = ssl->GetNegotiatedNPN(negotiatedNPN); + + // Check if the connection NPN matches negotiated NPN. + transactionNPN = mConnInfo->GetNPNToken(); + LOG(("negotiatedNPN: %s - transactionNPN: %s", negotiatedNPN.get(), + transactionNPN.get())); + if (!transactionNPN.IsEmpty() && negotiatedNPN != transactionNPN) { + LOG(("Resetting connection due to mismatched NPN token")); + DontReuse(); + mTransaction->Close(NS_ERROR_NET_RESET); + return true; + } + if (!m0RTTChecked && (rv == NS_ERROR_NOT_CONNECTED) && !mConnInfo->UsingProxy()) { // There is no ALPN info (yet!). We need to consider doing 0RTT. We