From fe97600c886437731e64ec21cb724086be6cb5dd Mon Sep 17 00:00:00 2001 From: Mustafa Enes Batur Date: Thu, 5 Jun 2025 14:41:30 +0200 Subject: [PATCH] Add comment, improve error message --- hscontrol/noise.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hscontrol/noise.go b/hscontrol/noise.go index 9931a9cd..6e92ea7a 100644 --- a/hscontrol/noise.go +++ b/hscontrol/noise.go @@ -210,18 +210,19 @@ func (ns *noiseServer) NoisePollNetMapHandler( } node, err := ns.headscale.db.GetNodeByMachineKey(ns.machineKey) - if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { httpError(writer, NewHTTPError(http.StatusNotFound, "node not found", nil)) return } httpError(writer, err) + return } + // Ensure the NodeKey in the request matches the one associated with the machine key from the Noise session if node.NodeKey != mapRequest.NodeKey { - httpError(writer, NewHTTPError(http.StatusNotFound, "node does not belong to machine key", nil)) + httpError(writer, NewHTTPError(http.StatusNotFound, "node key in request does not match the one associated with this machine key", nil)) return } @@ -274,6 +275,7 @@ func (ns *noiseServer) NoiseRegistrationHandler( return ®Req, resp } else { } + return ®Req, regErr(err) }