askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
sites.go · 1.6 KB · 49 lines
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/http/httputil" |
| 6 | "net/url" |
| 7 | "strings" |
| 8 | ) |
| 9 | |
| 10 | // sitesProxy serves the object server's published sites (/s/<name>/...) on |
| 11 | // the desk's public address, so a site made in Webmaster is at |
| 12 | // https://<desk>/s/<name>. Only /s/, only reading (GET, HEAD); the desk's |
| 13 | // login cookie and any credentials are removed first, so a site published as |
| 14 | // not public stays private, and nothing else of the object server is reached. |
| 15 | // The object server sends the pages sandboxed (CSP), which passes through. |
| 16 | func sitesProxy(target string) (http.Handler, error) { |
| 17 | u, err := url.Parse(target) |
| 18 | if err != nil { |
| 19 | return nil, err |
| 20 | } |
| 21 | p := httputil.NewSingleHostReverseProxy(u) |
| 22 | base := p.Director |
| 23 | p.Director = func(r *http.Request) { |
| 24 | base(r) |
| 25 | r.Header.Del("Cookie") |
| 26 | r.Header.Del("Authorization") |
| 27 | r.Header.Del("X-Forwarded-For") // the object server is not told to trust anyone |
| 28 | r.Host = u.Host |
| 29 | } |
| 30 | p.ModifyResponse = func(res *http.Response) error { |
| 31 | // a redirect to the object server's own address becomes a path here |
| 32 | if loc := res.Header.Get("Location"); strings.HasPrefix(loc, target) { |
| 33 | res.Header.Set("Location", strings.TrimPrefix(loc, strings.TrimRight(target, "/"))) |
| 34 | } |
| 35 | res.Header.Del("Set-Cookie") |
| 36 | return nil |
| 37 | } |
| 38 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 39 | if r.Method != http.MethodGet && r.Method != http.MethodHead { |
| 40 | http.Error(w, "read only", http.StatusMethodNotAllowed) |
| 41 | return |
| 42 | } |
| 43 | if !strings.HasPrefix(r.URL.Path, "/s/") || strings.Contains(r.URL.Path, "..") { |
| 44 | http.NotFound(w, r) |
| 45 | return |
| 46 | } |
| 47 | p.ServeHTTP(w, r) |
| 48 | }), nil |
| 49 | } |