Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix: SSRF guards still allow 100.64.0.0/10 (CGNAT) destinations (#6256)
goingforstudying-ctrl8120a6cee030
diff --git a/internal/linkmeta/html_meta_test.go b/internal/linkmeta/html_meta_test.goindex 4aa8b20b8..25b8e99d2 100644--- a/internal/linkmeta/html_meta_test.go+++ b/internal/linkmeta/html_meta_test.go@@ -634,3 +634,55 @@ func (reader *countingReadCloser) Read(buffer []byte) (int, error) {func (*countingReadCloser) Close() error {return nil}++func TestIsInternalIP(t *testing.T) {+ tests := []struct {+ name string+ ip string+ internal bool+ }{+ {name: "loopback", ip: "127.0.0.1", internal: true},+ {name: "private 10", ip: "10.0.0.1", internal: true},+ {name: "private 172", ip: "172.16.0.1", internal: true},+ {name: "private 192", ip: "192.168.1.1", internal: true},+ {name: "link local imds", ip: "169.254.169.254", internal: true},+ {name: "unspecified", ip: "0.0.0.0", internal: true},+ {name: "cgnat lower bound", ip: "100.64.0.1", internal: true},+ {name: "cgnat alibaba metadata", ip: "100.100.100.200", internal: true},+ {name: "cgnat upper bound", ip: "100.127.255.255", internal: true},+ {name: "mapped ipv6 cgnat", ip: "::ffff:100.100.100.200", internal: true},+ {name: "ipv6 loopback", ip: "::1", internal: true},+ {name: "below cgnat", ip: "100.63.255.255", internal: false},+ {name: "above cgnat", ip: "100.128.0.0", internal: false},+ {name: "public dns", ip: "8.8.8.8", internal: false},+ {name: "public example", ip: "93.184.216.34", internal: false},+ {name: "ipv6 public", ip: "2606:4700:4700::1111", internal: false},+ }+ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ require.Equal(t, test.internal, isInternalIP(net.ParseIP(test.ip)))+ })+ }+}++func TestHTMLMetaFetcherGetRejectsResolvedCGNAT(t *testing.T) {+ originalLookupIPAddr := lookupIPAddr+ originalDialContext := dialContext+ t.Cleanup(func() {+ lookupIPAddr = originalLookupIPAddr+ dialContext = originalDialContext+ })++ lookupIPAddr = func(context.Context, string) ([]net.IPAddr, error) {+ return []net.IPAddr{{IP: net.ParseIP("100.100.100.200")}}, nil+ }+ var dialed atomic.Bool+ dialContext = func(context.Context, string, string) (net.Conn, error) {+ dialed.Store(true)+ return nil, errors.New("unexpected dial")+ }++ _, err := NewHTMLMetaFetcher().Get(context.Background(), "http://rebind.example/page")+ require.ErrorIs(t, err, ErrInternalIP)+ require.False(t, dialed.Load())+}diff --git a/internal/webhook/webhook_test.go b/internal/webhook/webhook_test.goindex 6b1607330..c4a9d2cea 100644--- a/internal/webhook/webhook_test.go+++ b/internal/webhook/webhook_test.go@@ -308,6 +308,38 @@ func TestPostWithoutSecretSetsNoSignatureHeaders(t *testing.T) {require.False(t, hasSignatureHeaders, "no signature headers should be set when no secret is configured")}+func TestIsReservedIP(t *testing.T) {+ tests := []struct {+ name string+ ip string+ reserved bool+ }{+ {name: "loopback", ip: "127.0.0.1", reserved: true},+ {name: "private 10", ip: "10.0.0.1", reserved: true},+ {name: "private 172", ip: "172.16.0.1", reserved: true},+ {name: "private 192", ip: "192.168.1.1", reserved: true},+ {name: "link local imds", ip: "169.254.169.254", reserved: true},+ {name: "cgnat lower bound", ip: "100.64.0.1", reserved: true},+ {name: "cgnat alibaba metadata", ip: "100.100.100.200", reserved: true},+ {name: "cgnat upper bound", ip: "100.127.255.255", reserved: true},+ {name: "mapped ipv6 cgnat", ip: "::ffff:100.100.100.200", reserved: true},+ {name: "ipv6 loopback", ip: "::1", reserved: true},+ {name: "below cgnat", ip: "100.63.255.255", reserved: false},+ {name: "above cgnat", ip: "100.128.0.0", reserved: false},+ {name: "public dns", ip: "8.8.8.8", reserved: false},+ }+ for _, test := range tests {+ t.Run(test.name, func(t *testing.T) {+ require.Equal(t, test.reserved, isReservedIP(net.ParseIP(test.ip)))+ })+ }+}++func TestValidateURLRejectsCGNAT(t *testing.T) {+ resetPrivateDestinationPolicy(t)+ require.Error(t, ValidateURL("http://100.100.100.200/hook"))+}+// TestPostRejectsUnspecifiedAddressDestination pins that a webhook URL pointing at the// unspecified address is refused at dial time, bcs the kernel treats it as the local host.func TestPostRejectsUnspecifiedAddressDestination(t *testing.T) {