Settings › Allowed addresses in the desktop app refused a list with "that allow list would shut out 192.0.2.1, the address this page is open from" (Mathresearcher on Discord). The window's requests reach the API through Wails' asset server, which has no peer address and fills in 192.0.2.1:1234 (TEST-NET-1; assetserver_webview.go in wails v3 beta.24). KeepsOut took that for the page's address. The asset handler handed to Wails is now wrapped in ownWindow, which marks its requests as loopback: only the webview reaches it, never the network. magpie web (web.go, AllowGuard) is unchanged and still judges the real peer. Run: - TestAllowIPsFromTheAppWindow (new): posts ["10.0.0.0/8"] with RemoteAddr 192.0.2.1:1234 through ownWindow(Handler). With ownWindow's rewrite taken out it fails (refused, saved []); with it, passes. - go test -tags nogui -run TestAllowIPs ./internal/gui: ok. - gofmt -l, go vet (darwin), GOOS=linux -tags nogui and GOOS=windows vet of internal/gui and internal/gateway; go build for all three. Not tried: saving the list in a real desktop window (not launched).
17 lines
611 B
Go
17 lines
611 B
Go
package gui
|
|
|
|
import "net/http"
|
|
|
|
// ownWindow serves the app's own windows. Wails hands their requests over
|
|
// with no RemoteAddr and fills in 192.0.2.1:1234 (TEST-NET-1), so the
|
|
// allow list took the desktop window for a computer at 192.0.2.1 and
|
|
// asked for that address to be added (Mathresearcher on Discord). Only
|
|
// the webview reaches this handler, never the network, so its requests
|
|
// come from this computer: loopback.
|
|
func ownWindow(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r.RemoteAddr = "127.0.0.1:0"
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|