Skip to content

Commit a99618e

Browse files
authored
Don't log invalid certificates (#1116)
1 parent 8e94eb9 commit a99618e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

LOGGING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ l.WithError(err).
3333
WithField("vpnIp", IntIp(hostinfo.hostId)).
3434
WithField("udpAddr", addr).
3535
WithField("handshake", m{"stage": 1, "style": "ix"}).
36-
WithField("cert", remoteCert).
3736
Info("Invalid certificate from host")
3837
```

examples/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ tun:
244244
# TODO
245245
# Configure logging level
246246
logging:
247-
# panic, fatal, error, warning, info, or debug. Default is info
247+
# panic, fatal, error, warning, info, or debug. Default is info and is reloadable.
248+
#NOTE: Debug mode can log remotely controlled/untrusted data which can quickly fill a disk in some
249+
# scenarios. Debug logging is also CPU intensive and will decrease performance overall.
250+
# Only enable debug logging while actively investigating an issue.
248251
level: info
249252
# json or text formats currently available. Default is text
250253
format: text

handshake_ix.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ func ixHandshakeStage1(f *Interface, addr *udp.Addr, via *ViaSender, packet []by
9090

9191
remoteCert, err := RecombineCertAndValidate(ci.H, hs.Details.Cert, f.pki.GetCAPool())
9292
if err != nil {
93-
f.l.WithError(err).WithField("udpAddr", addr).
94-
WithField("handshake", m{"stage": 1, "style": "ix_psk0"}).WithField("cert", remoteCert).
95-
Info("Invalid certificate from host")
93+
e := f.l.WithError(err).WithField("udpAddr", addr).
94+
WithField("handshake", m{"stage": 1, "style": "ix_psk0"})
95+
96+
if f.l.Level > logrus.DebugLevel {
97+
e = e.WithField("cert", remoteCert)
98+
}
99+
100+
e.Info("Invalid certificate from host")
96101
return
97102
}
98103
vpnIp := iputil.Ip2VpnIp(remoteCert.Details.Ips[0].IP)
@@ -372,9 +377,14 @@ func ixHandshakeStage2(f *Interface, addr *udp.Addr, via *ViaSender, hh *Handsha
372377

373378
remoteCert, err := RecombineCertAndValidate(ci.H, hs.Details.Cert, f.pki.GetCAPool())
374379
if err != nil {
375-
f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
376-
WithField("cert", remoteCert).WithField("handshake", m{"stage": 2, "style": "ix_psk0"}).
377-
Error("Invalid certificate from host")
380+
e := f.l.WithError(err).WithField("vpnIp", hostinfo.vpnIp).WithField("udpAddr", addr).
381+
WithField("handshake", m{"stage": 2, "style": "ix_psk0"})
382+
383+
if f.l.Level > logrus.DebugLevel {
384+
e = e.WithField("cert", remoteCert)
385+
}
386+
387+
e.Error("Invalid certificate from host")
378388

379389
// The handshake state machine is complete, if things break now there is no chance to recover. Tear down and start again
380390
return true

0 commit comments

Comments
 (0)