{"record":{"id":"ef11b80c39a3477e","repo":"siyuan-note/siyuan","slug":"argon2id-memory-too-high-maximum-256-mb","errorCode":null,"errorMessage":"Argon2id Memory too high (maximum 256 MB)","messagePattern":"Argon2id Memory too high \\(maximum 256 MB\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/kdf.go","lineNumber":71,"sourceCode":"\treturn Argon2Params{\n\t\tMemory:      64 * 1024,\n\t\tIterations:  3,\n\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","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/kdf.go#L53-L89","documentation":"Raised by ValidateArgon2Params when p.Memory > 256*1024 (KiB), i.e. above the 256 MB ceiling. The cap exists to stop a malicious backup from specifying enormous memory and forcing an out-of-memory condition during key derivation. Default is 64 MB.","triggerScenarios":"A notebook crypto config (possibly from an imported/malicious backup) sets Memory above 256*1024 KiB; ValidateArgon2Params is invoked during unlock/import and rejects it before argon2.IDKey allocates.","commonSituations":"Importing a backup crafted to OOM the kernel; a user-raised memory value to harden KDF but exceeding the cap; a unit confusion (entering bytes or MiB).","solutions":["Lower KDFParams.Memory to <= 256*1024 KiB (256 MB); DefaultArgon2Params uses 64*1024.","Do not import crypto configs from untrusted backups; if you must, clamp Memory to the valid range first.","Confirm the value is in KiB (256*1024 KiB == 256 MB)."],"exampleFix":"// before: exceeds the 256 MB DoS cap\nparams := util.Argon2Params{Memory: 512 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}\n\n// after: within range\nparams := util.Argon2Params{Memory: 256 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}","handlingStrategy":"validation","validationCode":"if p.Memory > 256*1024 {\n    return fmt.Errorf(\"rejecting crypto config: Memory %d exceeds the 256 MB DoS cap\", p.Memory)\n}\nif _, err := util.ValidateArgon2Params(p); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not import crypto configs from untrusted backups without clamping Memory.","Treat any Memory > 256*1024 KiB as a potential DoS payload.","Regenerate params via change-password rather than editing JSON."],"tags":["crypto","argon2","encryption","validation","notebook-crypto","dos-mitigation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}