From 8901267867d647775588dd325bef6fdedca6254f Mon Sep 17 00:00:00 2001 From: Muse Date: Thu, 22 Oct 2026 14:44:52 +0000 Subject: [PATCH] =?UTF-8?q?fix(agent)=EF=BC=9A=E7=AC=AC=2019=20=E6=9D=A1?= =?UTF-8?q?=20token=20=E5=9B=9E=E5=A1=AB=E5=AE=88=E5=8D=AB=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=20SQL=20NULL=20=E8=80=81=E8=A1=8C=EF=BC=88token=5Fpla?= =?UTF-8?q?in=20IS=20NULL=20OR=20=3D=20''=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/controller/agent.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/web/controller/agent.go b/internal/web/controller/agent.go index fb9be6d..a56af71 100644 --- a/internal/web/controller/agent.go +++ b/internal/web/controller/agent.go @@ -83,11 +83,16 @@ func (a *AgentController) findAgent(token string) (*model.AgentNode, bool) { // Item 19 backfill: the token has just passed the hash check, so for // rows created before plaintext storage existed, adopt the presented // token as the recoverable copy. The guarded update only fires while - // token_plain is empty — an authenticated request can never overwrite - // an already-stored token (only issuance writes a fresh one). + // token_plain is unset — an authenticated request can never overwrite + // an already-stored token (only issuance writes a fresh one). "Unset" + // must cover SQL NULL as well as '': AutoMigrate added the column to + // pre-existing rows as NULL, and NULL = '' is never true, so an + // equality-only guard silently matched zero legacy rows in + // production (the GORM-scanned value reads as "" either way, which is + // why the in-memory check above cannot distinguish them). if agent.TokenPlain == "" { if res := database.GetDB().Model(&model.AgentNode{}). - Where("id = ? AND token_plain = ''", agent.Id). + Where("id = ? AND (token_plain IS NULL OR token_plain = '')", agent.Id). Update("token_plain", token); res.Error == nil && res.RowsAffected > 0 { agent.TokenPlain = token }