Signed-off-by: dawn dawn@tangled.org
+1
-1
appview/serververify/verify.go
+1
-1
appview/serververify/verify.go
+1
-1
knotmirror/knotstream/slurper.go
+1
-1
knotmirror/knotstream/slurper.go
+1
-1
knotmirror/xrpc/xrpc.go
+1
-1
knotmirror/xrpc/xrpc.go
-51
util/netutil/ssrf.go
-51
util/netutil/ssrf.go
···
1
-
package netutil
2
-
3
-
import (
4
-
"fmt"
5
-
"net"
6
-
"net/http"
7
-
"net/url"
8
-
9
-
"github.com/bluesky-social/indigo/util/ssrf"
10
-
"github.com/gorilla/websocket"
11
-
)
12
-
13
-
// SSRFDialer returns a net.Dialer that refuses non-public IPs.
14
-
func SSRFDialer(dev bool) *net.Dialer {
15
-
if dev {
16
-
return &net.Dialer{}
17
-
}
18
-
return ssrf.PublicOnlyDialer()
19
-
}
20
-
21
-
// SSRFTransport returns an http.Transport that refuses non-public IPs.
22
-
func SSRFTransport(dev bool) *http.Transport {
23
-
if dev {
24
-
return &http.Transport{}
25
-
}
26
-
return ssrf.PublicOnlyTransport()
27
-
}
28
-
29
-
// SSRFWebsocketDialer returns a websocket.Dialer that refuses non-public IPs.
30
-
func SSRFWebsocketDialer(dev bool) *websocket.Dialer {
31
-
dialer := *websocket.DefaultDialer
32
-
dialer.NetDialContext = SSRFDialer(dev).DialContext
33
-
return &dialer
34
-
}
35
-
36
-
func EnforceWSSURL(rawURL string, dev bool) (*url.URL, error) {
37
-
u, err := url.Parse(rawURL)
38
-
if err != nil {
39
-
return nil, fmt.Errorf("invalid url: %w", err)
40
-
}
41
-
switch u.Scheme {
42
-
case "wss":
43
-
case "ws":
44
-
if !dev {
45
-
return nil, fmt.Errorf("insecure scheme %q is prohibited in production; use wss://", u.Scheme)
46
-
}
47
-
default:
48
-
return nil, fmt.Errorf("unsupported websocket scheme %q", u.Scheme)
49
-
}
50
-
return u, nil
51
-
}
-17
util/netutil/ssrf_test.go
-17
util/netutil/ssrf_test.go
···
1
-
package netutil
2
-
3
-
import (
4
-
"testing"
5
-
6
-
"github.com/gorilla/websocket"
7
-
)
8
-
9
-
func TestSSRFWebsocketDialerPreservesHandshakeTimeout(t *testing.T) {
10
-
dialer := SSRFWebsocketDialer(false)
11
-
if dialer.HandshakeTimeout != websocket.DefaultDialer.HandshakeTimeout {
12
-
t.Fatalf("HandshakeTimeout = %v, want %v", dialer.HandshakeTimeout, websocket.DefaultDialer.HandshakeTimeout)
13
-
}
14
-
if dialer.NetDialContext == nil {
15
-
t.Fatal("NetDialContext is nil; public-only dialing is not enforced")
16
-
}
17
-
}
+51
netutil/ssrf.go
+51
netutil/ssrf.go
···
1
+
package netutil
2
+
3
+
import (
4
+
"fmt"
5
+
"net"
6
+
"net/http"
7
+
"net/url"
8
+
9
+
"github.com/bluesky-social/indigo/util/ssrf"
10
+
"github.com/gorilla/websocket"
11
+
)
12
+
13
+
// SSRFDialer returns a net.Dialer that refuses non-public IPs.
14
+
func SSRFDialer(dev bool) *net.Dialer {
15
+
if dev {
16
+
return &net.Dialer{}
17
+
}
18
+
return ssrf.PublicOnlyDialer()
19
+
}
20
+
21
+
// SSRFTransport returns an http.Transport that refuses non-public IPs.
22
+
func SSRFTransport(dev bool) *http.Transport {
23
+
if dev {
24
+
return &http.Transport{}
25
+
}
26
+
return ssrf.PublicOnlyTransport()
27
+
}
28
+
29
+
// SSRFWebsocketDialer returns a websocket.Dialer that refuses non-public IPs.
30
+
func SSRFWebsocketDialer(dev bool) *websocket.Dialer {
31
+
dialer := *websocket.DefaultDialer
32
+
dialer.NetDialContext = SSRFDialer(dev).DialContext
33
+
return &dialer
34
+
}
35
+
36
+
func EnforceWSSURL(rawURL string, dev bool) (*url.URL, error) {
37
+
u, err := url.Parse(rawURL)
38
+
if err != nil {
39
+
return nil, fmt.Errorf("invalid url: %w", err)
40
+
}
41
+
switch u.Scheme {
42
+
case "wss":
43
+
case "ws":
44
+
if !dev {
45
+
return nil, fmt.Errorf("insecure scheme %q is prohibited in production; use wss://", u.Scheme)
46
+
}
47
+
default:
48
+
return nil, fmt.Errorf("unsupported websocket scheme %q", u.Scheme)
49
+
}
50
+
return u, nil
51
+
}
+17
netutil/ssrf_test.go
+17
netutil/ssrf_test.go
···
1
+
package netutil
2
+
3
+
import (
4
+
"testing"
5
+
6
+
"github.com/gorilla/websocket"
7
+
)
8
+
9
+
func TestSSRFWebsocketDialerPreservesHandshakeTimeout(t *testing.T) {
10
+
dialer := SSRFWebsocketDialer(false)
11
+
if dialer.HandshakeTimeout != websocket.DefaultDialer.HandshakeTimeout {
12
+
t.Fatalf("HandshakeTimeout = %v, want %v", dialer.HandshakeTimeout, websocket.DefaultDialer.HandshakeTimeout)
13
+
}
14
+
if dialer.NetDialContext == nil {
15
+
t.Fatal("NetDialContext is nil; public-only dialing is not enforced")
16
+
}
17
+
}
History
9 rounds
0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
3/3 success
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
3/3 success
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
2/3 success, 1/3 failed
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
3/3 success
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
3/3 success
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
3/3 success
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
2/3 success, 1/3 failed
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>
2/3 success, 1/3 failed
Expand
Collapse
Expand 0 comments
1 commit
Expand
Collapse
netutil: extract common SSRF and secure-scheme guards
Signed-off-by: dawn <dawn@tangled.org>