mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-09-19 02:29:45 +02:00
fix: out of bounds index when rewriting websocket headers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user