{"record":{"id":"732f9b40ddc7e777","repo":"siyuan-note/siyuan","slug":"invalid-agent-session-id","errorCode":null,"errorMessage":"invalid Agent session ID","messagePattern":"invalid Agent session ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/todo.go","lineNumber":46,"sourceCode":")\n\ntype AgentTodoItem struct {\n\tContent string `json:\"content\"`\n\tStatus  string `json:\"status\"` // pending, in_progress, completed, cancelled\n}\n\ntype AgentTodoList struct {\n\tSessionID string          `json:\"sessionID\"`\n\tTodos     []AgentTodoItem `json:\"todos\"`\n}\n\nfunc agentTodosPath(sessionID string) string {\n\treturn filepath.Join(util.DataDir, \"storage\", \"ai\", \"agent\", \"sessions\", sessionID, \"todos.json\")\n}\n\nfunc SaveAgentTodos(sessionID string, todos []AgentTodoItem) error {\n\tif !ast.IsNodeIDPattern(sessionID) {\n\t\treturn errors.New(\"invalid Agent session ID\")\n\t}\n\tdir := filepath.Join(util.DataDir, \"storage\", \"ai\", \"agent\", \"sessions\", sessionID)\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn err\n\t}\n\n\tdata := AgentTodoList{\n\t\tSessionID: sessionID,\n\t\tTodos:     todos,\n\t}\n\n\tb, err := json.Marshal(data)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn filelock.WriteFile(agentTodosPath(sessionID), b)\n}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/todo.go#L28-L64","documentation":"SaveAgentTodos validates the Agent session ID against ast.IsNodeIDPattern (the SiYuan node-ID format) before using it to build a filesystem path. A session ID that is not a valid node ID is rejected so that arbitrary or hostile strings cannot traverse directories or create unexpected paths under storage/ai/agent/sessions/.","triggerScenarios":"Calling SaveAgentTodos with an empty string, a path-like string (e.g. \"../../x\"), a UUID, or any identifier not matching the node-ID pattern (format YYYYMMDDhhmmss-xxxxxxxx, 14 digits, dash, 7+ alphanumeric chars).","commonSituations":"Generating your own session IDs with uuid.NewString() instead of using SiYuan block IDs; passing a filename or session label from another system; older clients producing IDs in a legacy format.","solutions":["Obtain the session ID as a valid SiYuan node ID (ast.IsNodeIDPattern must accept it)","Replace custom UUID-based IDs with the node-ID format (timestamp-random suffix)","Sanitize/normalize the ID before calling SaveAgentTodos","Check the caller (todoWriteHandler) for where the ID originates and fix the producer"],"exampleFix":"// before\nSaveAgentTodos(uuid.NewString(), todos) // rejected\n// after\nid := treenode.CreateNodeID()\nSaveAgentTodos(id, todos)","handlingStrategy":"validation","validationCode":"if !ast.IsNodeIDPattern(sessionID) { return errors.New(\"bad session id\") }\nSaveAgentTodos(sessionID, todos)","typeGuard":"func validSessionID(id string) bool { return ast.IsNodeIDPattern(id) }","tryCatchPattern":"if err := SaveAgentTodos(sid, todos); err != nil && strings.Contains(err.Error(), \"invalid Agent session ID\") { /* regenerate ID */ }","preventionTips":["Generate session IDs with SiYuan node-ID generation, not uuid","Never pass user-supplied strings directly as session IDs","Keep a single ID-format helper used by all agent session code","Add a unit test asserting IDs match ast.IsNodeIDPattern"],"tags":["validation","identifier","agent"],"backgroundTag":"invalid-identifier-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}