{"record":{"id":"fa4869daa872d71f","repo":"siyuan-note/siyuan","slug":"argon2id-iterations-too-low-minimum-3","errorCode":null,"errorMessage":"Argon2id Iterations too low (minimum 3)","messagePattern":"Argon2id Iterations too low \\(minimum 3\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/kdf.go","lineNumber":74,"sourceCode":"\t\tParallelism: 4,\n\t\tKeyLength:   32,\n\t}\n}\n\n// ValidateArgon2Params 校验 Argon2id 参数是否在合理范围内，防止恶意备份设置极大内存导致 OOM，\n// 或过弱参数降低安全性。\nfunc ValidateArgon2Params(p Argon2Params) (Argon2Params, error) {\n\tif p.KeyLength != 32 {\n\t\treturn p, errors.New(\"Argon2id KeyLength must be 32\")\n\t}\n\tif p.Memory < 64*1024 {\n\t\treturn p, errors.New(\"Argon2id Memory too low (minimum 64 MB)\")\n\t}\n\tif p.Memory > 256*1024 {\n\t\treturn p, errors.New(\"Argon2id Memory too high (maximum 256 MB)\")\n\t}\n\tif p.Iterations < 3 {\n\t\treturn p, errors.New(\"Argon2id Iterations too low (minimum 3)\")\n\t}\n\tif p.Iterations > 10 {\n\t\treturn p, errors.New(\"Argon2id Iterations too high (maximum 10)\")\n\t}\n\tif p.Parallelism == 0 || p.Parallelism > 16 {\n\t\treturn p, errors.New(\"Argon2id Parallelism must be between 1 and 16\")\n\t}\n\treturn p, nil\n}\n\n// DeriveKey 用 Argon2id 从密码派生密钥。同一 password+salt+params 多次调用结果一致。\nfunc DeriveKey(password string, salt []byte, p Argon2Params) []byte {\n\treturn argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)\n}\n\n// Encrypt 用 AES-256-GCM 加密。每次调用生成随机 nonce，因此同一明文多次加密结果不同。\n// 返回格式：magic(4B) || spec(1B) || algorithm(1B) || nonceLength(1B) || nonce || ciphertext || GCM tag(16B)。\nfunc Encrypt(key, plaintext []byte) ([]byte, error) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/kdf.go#L56-L92","documentation":"Raised by ValidateArgon2Params when p.Iterations < 3. Three passes is the enforced minimum matching the OWASP-2023 default; fewer would weaken the KDF. Caught during unlock/setup/change-password.","triggerScenarios":"KDFParams.Iterations is loaded as 0, 1, or 2 from an edited/imported notebook crypto config.","commonSituations":"Hand-editing conf JSON to make unlock faster; a third-party backup writer using a lower iteration count; a deserialization default of 0 when the field is absent.","solutions":["Set KDFParams.Iterations to at least 3 (DefaultArgon2Params uses 3).","Regenerate params through the official change-password flow.","Treat a zero-value Iterations field as missing and replace it with the default before validating."],"exampleFix":"// before\nparams := util.Argon2Params{Memory: 64 * 1024, Iterations: 1, Parallelism: 4, KeyLength: 32}\n\n// after\nparams := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}","handlingStrategy":"validation","validationCode":"if p.Iterations < 3 {\n    p.Iterations = 3\n}\nif _, err := util.ValidateArgon2Params(p); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default Iterations to 3 when the field is missing/zero.","Always validate after deserialization.","Avoid lowering iterations to speed up unlock."],"tags":["crypto","argon2","encryption","validation","notebook-crypto"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}