fix: out of bounds index when rewriting websocket headers

This commit is contained in:
Anthony Rubick
2025-08-01 02:12:50 -07:00
parent 4e32f31f0a
commit bd5d225a94
2 changed files with 8 additions and 0 deletions

View File

@@ -75,5 +75,9 @@ func SplitUpDownStreamHeaders(rewriteOptions *HeaderRewriteOptions) ([][]string,
downstreamHeaderCounter++
}
// Slice the arrays to only include the filled portions to prevent nil slice access
upstreamHeaders = upstreamHeaders[:upstreamHeaderCounter]
downstreamHeaders = downstreamHeaders[:downstreamHeaderCounter]
return upstreamHeaders, downstreamHeaders
}

View File

@@ -211,6 +211,10 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
UserDefinedHeaders: rewrittenUserDefinedHeaders,
})
for _, headerValuePair := range upstreamHeaders {
//Skip empty header pairs
if len(headerValuePair) < 2 {
continue
}
//Do not copy Upgrade and Connection headers, it will be handled by the upgrader
if strings.EqualFold(headerValuePair[0], "Upgrade") || strings.EqualFold(headerValuePair[0], "Connection") {
continue