Skip to content

Commit 45643e3

Browse files
committed
fix(proxy): enforce deferred ask on direct-connect path for non-TLS protocols
SSH, plain TCP, and other non-MITM connections that go through the direct dial path now check the deferred per-request policy before connecting upstream. Without this, connections to ask destinations on non-TLS ports (e.g. SSH port 22) bypassed approval entirely.
1 parent 74155a3 commit 45643e3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

internal/proxy/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,22 @@ func (s *Server) dial(ctx context.Context, network, addr string) (net.Conn, erro
944944
}
945945

946946
// No credential binding or unsupported protocol: direct connection.
947+
// Check deferred ask policy before connecting. For TLS ports this is
948+
// handled by the MITM addon per-request, but for non-TLS (SSH, plain
949+
// TCP) this is the only checkpoint.
950+
if perReqChecker != nil {
951+
_, portStr, _ := net.SplitHostPort(addr)
952+
port, _ := strconv.Atoi(portStr)
953+
fqdn, _ := ctx.Value(ctxKeyFQDN).(string)
954+
if fqdn == "" {
955+
host, _, _ := net.SplitHostPort(addr)
956+
fqdn = host
957+
}
958+
if v, _ := perReqChecker.CheckAndConsume(fqdn, port); v != policy.Allow {
959+
log.Printf("[DIAL-DENY] %s deferred ask denied", addr)
960+
return nil, fmt.Errorf("connection denied by policy")
961+
}
962+
}
947963
d := &net.Dialer{Timeout: connectTimeout}
948964
conn, err := d.DialContext(ctx, network, addr)
949965
if err == nil {

0 commit comments

Comments
 (0)