{"record":{"id":"01c040afafe2af93","repo":"siyuan-note/siyuan","slug":"invalid-notebook-id-01c040","errorCode":null,"errorMessage":"invalid notebook ID","messagePattern":"invalid notebook ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":823,"sourceCode":"\t\tfor _, boxEntry := range boxEntries {\n\t\t\tif !boxEntry.IsDir() || !ast.IsNodeIDPattern(boxEntry.Name()) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tencrypted, checkErr := isEncryptedHistoryBoxDir(filepath.Join(snapshotDir, boxEntry.Name()))\n\t\t\tif checkErr != nil {\n\t\t\t\treturn nil, checkErr\n\t\t\t}\n\t\t\tif encrypted {\n\t\t\t\tret = append(ret, filepath.Join(snapshotDir, boxEntry.Name()))\n\t\t\t}\n\t\t}\n\t}\n\treturn ret, nil\n}\n\nfunc hasEncryptedNotebookDeleteHistory(boxID string) (bool, error) {\n\tif !ast.IsNodeIDPattern(boxID) {\n\t\treturn false, errors.New(\"invalid notebook ID\")\n\t}\n\tentries, err := os.ReadDir(util.HistoryDir)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, fmt.Errorf(\"read history dir failed: %w\", err)\n\t}\n\n\tdeleteSuffix := \"-\" + HistoryOpDelete\n\tfor _, entry := range entries {\n\t\tif !entry.IsDir() || !strings.HasSuffix(entry.Name(), deleteSuffix) {\n\t\t\tcontinue\n\t\t}\n\t\tboxDir := filepath.Join(util.HistoryDir, entry.Name(), boxID)\n\t\tif !filelock.IsExist(boxDir) {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L805-L841","documentation":"hasEncryptedNotebookDeleteHistory checks whether any delete-op history snapshot exists for a given notebook ID before recovery proceeds. It validates the boxID with ast.IsNodeIDPattern first; if the ID is not a well-formed node ID (20-char alphanumeric pattern) the function refuses to scan and returns this sentinel error, protecting the filesystem scan from malformed input.","triggerScenarios":"Calling recoverMasterPasswordMigration (or the test path) with a boxID that is empty, contains path characters, or otherwise fails ast.IsNodeIDPattern — e.g. a corrupted conf entry, a user-typed ID, or a notebook directory name that is not a node ID.","commonSituations":"A hand-edited or legacy workspace where notebook directory names predate the node-ID convention; a bug passing a display name instead of an ID; a corrupted conf.json feeding an empty boxID into recovery.","solutions":["Verify the boxID passed to recovery is the notebook's actual node-style ID (read it from the notebook's conf.json or the notebook list API)","Sanitize/reject the source of the bad ID before invoking recovery; do not pass display names or paths","If the on-disk notebook dir name is not a node ID, re-create/normalize the notebook so its ID matches the expected pattern"],"exampleFix":"// before\nrecovered, err := hasEncryptedNotebookDeleteHistory(boxID)\n// after: validate before calling\nif !ast.IsNodeIDPattern(boxID) {\n    return fmt.Errorf(\"refusing recovery: boxID %q is not a valid node ID\", boxID)\n}\nrecovered, err = hasEncryptedNotebookDeleteHistory(boxID)","handlingStrategy":"validation","validationCode":"if boxID == \"\" || !ast.IsNodeIDPattern(boxID) {\n    return errors.New(\"boxID must be a valid node-style ID before recovery\")\n}","typeGuard":"func isValidBoxID(boxID string) bool {\n    return ast.IsNodeIDPattern(boxID)\n}","tryCatchPattern":"ok, err := hasEncryptedNotebookDeleteHistory(boxID)\nif err != nil && err.Error() == \"invalid notebook ID\" {\n    // re-resolve the correct boxID from notebook conf and retry\n    return err\n}","preventionTips":["Always take boxID from notebook conf.json or the API, never user input","Validate IDs with ast.IsNodeIDPattern at every boundary","Don't pass notebook names or paths where IDs are expected","Reject empty strings early in recovery flows"],"tags":["validation","identifier","notebook-id"],"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"}