Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address more private network leakage scenarios #89

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions besticon/besticon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func TestFetchIcons(t *testing.T) {

// kicktipp.de
{"http://kicktipp.de", []testFetchIcon{
{"http://info.kicktipp.de/assets/img/jar_cb333387130/assets/img/logos/apple-touch-icon-57x57-precomposed.png", 57, "png"},
{"http://www.kicktipp.de/apple-touch-icon-precomposed.png", 57, "png"},
{"http://www.kicktipp.de/apple-touch-icon.png", 57, "png"},
{"http://www.kicktipp.de/favicon.ico", 32, "gif"},
{"http://info.kicktipp.de/assets/img/jar_cb1652512069/assets/img/logos/favicon.png", 16, "png"},
{"https://www.kicktipp.de/assets/apple-touch-icon.0879fba1.png", 180, "png"},
{"https://www.kicktipp.de/assets/favicon.5368f953.ico", 48, "ico"},
{"https://www.kicktipp.de/favicon.ico", 48, "ico"},
{"https://www.kicktipp.de/assets/favicon-32x32.cfcd6069.png", 32, "png"},
{"https://www.kicktipp.de/assets/favicon-16x16.932c575d.png", 16, "png"},
}},

// netflix - has cookie redirects
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestIconInSizeRange(t *testing.T) {
{"http://car2go.com", SizeRange{80, 120, 200}, ""},
{"http://daringfireball.net", SizeRange{20, 80, 500}, "http://daringfireball.net/graphics/apple-touch-icon.png"},
{"http://eat24.com", SizeRange{120, 150, 500}, ""},
{"http://kicktipp.de", SizeRange{20, 80, 500}, "http://info.kicktipp.de/assets/img/jar_cb333387130/assets/img/logos/apple-touch-icon-57x57-precomposed.png"},
{"http://kicktipp.de", SizeRange{20, 80, 500}, "https://www.kicktipp.de/assets/apple-touch-icon.0879fba1.png"},

// https://github.com/mat/besticon/issues/28
{"https://random.org", SizeRange{16, 32, 64}, "https://www.random.org/favicon.ico"},
Expand Down
15 changes: 10 additions & 5 deletions besticon/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func (b *Besticon) Get(urlstring string) (*http.Response, error) {
return nil, e
}

if isPrivateIP(u.Host) {
ipAddr, e := net.ResolveIPAddr("ip", u.Host)
if e != nil {
return nil, e
}

if isPrivateIP(ipAddr) {
return nil, errors.New("private ip address disallowed")
}

Expand All @@ -74,12 +79,12 @@ func (b *Besticon) Get(urlstring string) (*http.Response, error) {
return resp, err
}

func isPrivateIP(host string) bool {
ip := net.ParseIP(host)
if ip == nil {
func isPrivateIP(ipAddr *net.IPAddr) bool {
if ipAddr == nil {
return false
}
return ip.IsPrivate()

return ipAddr.IP.IsLoopback() || ipAddr.IP.IsPrivate()
}

func (b *Besticon) GetBodyBytes(r *http.Response) ([]byte, error) {
Expand Down
Binary file modified besticon/testdata/kicktipp.de.vcr
Binary file not shown.
Loading