From 6b923bf30e7c2aa0cdc775da134c71ab99b93e18 Mon Sep 17 00:00:00 2001 From: Taylor McIntyre Date: Fri, 20 Nov 2026 14:08:24 -0500 Subject: [PATCH] ipn/ipnlocal: guard on expired key when connected to exit node Signed-off-by: Taylor McIntyre --- ipn/ipnlocal/local.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index fbc207e19..73df39c8c 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -379,6 +379,7 @@ type LocalBackend struct { // hostinfo is mutated in-place while mu is held. hostinfo *tailcfg.Hostinfo // TODO(nickkhyl): move to nodeBackend nmExpiryTimer tstime.TimerController // for updating netMap on node expiry; can be nil; TODO(nickkhyl): move to nodeBackend + nmExpiryAt time.Time // wall time at which nmExpiryTimer should fire activeLogin string // last logged LoginName from netMap; TODO(nickkhyl): move to nodeBackend (or remove? it's in [ipn.LoginProfile]). engineStatus ipn.EngineStatus endpoints []tailcfg.Endpoint @@ -1249,6 +1250,14 @@ func (b *LocalBackend) linkChange(delta *netmon.ChangeDelta) { b.interfaceState = delta.CurrentState() + if delta.TimeJumped() && b.nmExpiryTimer != nil { + // The timer runs on monotonic time, which on most platforms + // does not advance while the device is asleep. Reschedule it + // against the wall clock so that a key that expired during + // sleep is handled now rather than a sleep's duration late. + b.nmExpiryTimer.Reset(max(0, b.nmExpiryAt.Sub(b.clock.Now()))) + } + b.pauseOrResumeControlClientLocked() prefs := b.pm.CurrentPrefs() if delta.RebindLikelyRequired && prefs.AutoExitNode().IsSet() { @@ -1983,6 +1992,9 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c nextExpiry := b.em.nextPeerExpiry(st.NetMap, now) if !nextExpiry.IsZero() { tmrDuration := nextExpiry.Sub(now) + 10*time.Second + // From time package's docs: "The canonical way to strip a + // monotonic clock reading is to use t = t.Round(0)." + b.nmExpiryAt = now.Add(tmrDuration).Round(0) b.nmExpiryTimer = b.clock.AfterFunc(tmrDuration, func() { b.handleNetmapExpiry(c, st, currCall, tmrDuration) }) @@ -2007,7 +2019,7 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c b.blockEngineUpdatesLocked(false) } - if st.LoggedIn && (wasBlocked || authWasInProgress) { + if st.LoggedIn && !b.keyExpired && (wasBlocked || authWasInProgress) { if wasBlocked { // Auth completed, unblock the engine b.blockEngineUpdatesLocked(false) @@ -2042,7 +2054,7 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c prefs.Persist = st.Persist.AsStruct() } } - if st.LoggedIn { + if st.LoggedIn && !b.keyExpired { if authWasInProgress { b.resetAuthURLLocked() // Interactive login finished successfully (URL visited).