A plugin's package.json icon, an import link's icon= and the library's market icons sit on hosts their authors pick. magpie fetched each straight from there, so an author could log the IP of everyone who opened Discover or the library. The owner asked for icons to keep showing without that. - site/worker.js: /api/icon?url=<https URL> fetches the picture from Cloudflare with only Accept: image/* and its own User-Agent, follows redirects, caps it at 1 MB (the app's MaxIcon), passes on only PNG, JPEG, GIF, WebP, ICO or SVG (by bytes, as StoreIcon), and counts and keeps nothing. It refuses http, userinfo, a non-443 port and usemagpie.ai itself; 404s are cached 5 minutes, 5xx not at all. - internal/iconproxy: URL(u) is the proxied address (MAGPIE_ICON_PROXY for tests); a picture already on usemagpie.ai is asked for as it is. - provider.FetchIcon (plugin, import link and partner icons) and library.fetchImage (market icons, avatars) fetch through it. The import link's checks (https, public host) still come first; there is no direct fallback. provider.FaviconFor still reads the user's own provider's site directly: they already send it their requests. - Privacy text in README en/zh, docs/reference.md and site docs start/import in en/zh/ja says so. Ran: - node --test site/*.test.mjs: 28 pass. The new test asks with Cookie, UA, X-Forwarded-For and CF-Connecting-IP and checks only accept and user-agent go upstream; 415/413/502/400 cases; its fetch stub throws instead of reaching the network. With the usemagpie.ai refusal removed by hand it goes red (27/1). - TestFetchIconGoesThroughTheProxy and TestIconGoesThroughTheProxy (author host is .invalid; an httptest server stands in for the proxy): with the proxy taken out by hand both go red (provider: lookup author.invalid; library: the proxy was never asked), green restored. - go test ./internal/iconproxy ./internal/provider ./internal/library ./internal/gui: ok. gofmt -l clean; go vet darwin (those four), linux (iconproxy, provider, library), windows (all four): clean.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package library
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A market icon is asked for through usemagpie.ai's icon proxy, never from
|
|
// the host its author picked, which would see the user's IP.
|
|
func TestIconGoesThroughTheProxy(t *testing.T) {
|
|
h := sandbox(t)
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
png := []byte("\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR")
|
|
var asked []string
|
|
proxy := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
|
asked = append(asked, r.URL.Query().Get("url"))
|
|
rw.Header().Set("Content-Type", "image/png")
|
|
rw.Write(png)
|
|
}))
|
|
defer proxy.Close()
|
|
t.Setenv("MAGPIE_ICON_PROXY", proxy.URL+"/api/icon")
|
|
|
|
// a server the registry showed, its icon on its author's host; .invalid
|
|
// never resolves, so reaching it straight fails the test
|
|
const avatar = "https://author.invalid/logo.png?v=2"
|
|
seenServers.Lock()
|
|
seenServers.m["io.example/proxy-test"] = MarketServer{Icon: avatar}
|
|
seenServers.Unlock()
|
|
t.Cleanup(func() {
|
|
seenServers.Lock()
|
|
delete(seenServers.m, "io.example/proxy-test")
|
|
seenServers.Unlock()
|
|
})
|
|
b, ct, err := Icon(avatar)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(b) != string(png) || ct != "image/png" {
|
|
t.Fatalf("Icon = %q %q", b, ct)
|
|
}
|
|
if len(asked) != 1 || asked[0] != avatar {
|
|
t.Fatalf("the proxy was asked for %q, want [%s]", asked, avatar)
|
|
}
|
|
}
|