Skip to content

Commit df0986d

Browse files
committed
Strip unnecessary headers.
Strip unnecessary headers keeping headers size under 4KB (libwebsockets default) if possible. Bug: b/339517891
1 parent 88695e5 commit df0986d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

frontend/src/liboperator/operator/devices.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"net/http/httputil"
2323
"net/url"
24+
"strings"
2425
"sync"
2526

2627
apiv1 "github.com/google/android-cuttlefish/frontend/src/liboperator/api/v1"
@@ -49,6 +50,19 @@ func newDevice(id string, conn *JSONUnix, port int, privateData interface{}) *De
4950
return nil
5051
}
5152
proxy := httputil.NewSingleHostReverseProxy(url)
53+
originalDirector := proxy.Director
54+
proxy.Director = func(req *http.Request) {
55+
originalDirector(req)
56+
// Strip unnecessary headers keeping headers size under 4KB (libwebsockets default) if possible.
57+
// https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-context-vhost.h?h=v3.1-stable#n339
58+
req.Header.Del("Cookie")
59+
req.Header.Del("Authorization")
60+
for v := range req.Header {
61+
if strings.HasPrefix(v, "X-") {
62+
req.Header.Del(v)
63+
}
64+
}
65+
}
5266
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
5367
log.Printf("request %q failed: proxy error: %v", r.Method+" "+r.URL.Path, err)
5468
w.Header().Add("x-cutf-proxy", "op-device")

0 commit comments

Comments
 (0)