siyuan-note/siyuan · error

boxID mismatch: param=

Error message

boxID mismatch: param=%s, path=%s

What it means

writeAssetFile cross-validates the boxID passed by the caller against the boxID extracted from the target assets file path. If both are non-empty and differ, it refuses to write, preventing a caller from writing an asset into a different notebook (box) than declared — a cross-box write guard for the encrypted-notebook feature.

Solutions

  1. Pass the correct boxID matching the notebook that owns the assets path, or omit it (empty) so the path-derived boxID is used
  2. Verify the assetsDirPath is derived from the same box as the boxID parameter before calling
  3. Check that the docID/notebook was not renamed or recreated; re-resolve the box from the document ID

Example fix

// before
upload(boxID: "20240101120000-abc", assetsDirPath: "/data/20240201101010-xyz/assets", ...)
// after
upload(boxID: "20240201101010-xyz", assetsDirPath: "/data/20240201101010-xyz/assets", ...)
Defensive patterns

Strategy: validation

Validate before calling

func checkBoxPath(boxID, writePath string) error {
    pathBoxID := ExtractBoxIDFromAssetsPath(writePath)
    if boxID != "" && pathBoxID != "" && boxID != pathBoxID {
        return fmt.Errorf("boxID %s does not own path %s", boxID, writePath)
    }
    return nil
}

Try / catch

if err := writeAssetFile(writePath, src, boxID, name); err != nil {
    if strings.HasPrefix(err.Error(), "boxID mismatch") {
        // re-resolve boxID from the document/path and retry
    }
}

Prevention

When it happens

Trigger: Calling UploadAssets / InsertAssetBytes / insertLocalAssets / netAssets2LocalAssets0 / importSYAssets with an assetsDirPath resolved under one box's directory while passing a different non-empty boxID parameter (stale or wrong box id in the API payload).

Common situations: Plugin or frontend code caching an old boxID after a notebook was renamed/re-created; a docID belonging to box A combined with an assets path computed from box B; copy-pasted integration code passing the wrong box parameter to the upload API.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/bd78e10aae4ccca3. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/upload.go:600

				_ = os.MkdirAll(assets, 0755)
				return
			}
			assets = filepath.Join(util.DataDir, "assets")
		}
	}
	return
}

// writeAssetFile 把 src 的内容写入 writePath。从 writePath 反查真实 boxID 决定是否加密——
// 不轻信传入的 boxID(调用方可能未传,或 assetsDirPath 指向加密笔记本但 id 为空)。
// 加密笔记本必须已解锁(DEK 在内存)才写入;加密但未解锁返回错误(fail-closed,避免明文落盘)。
// 非加密笔记本按 reader 直接写(走 filelock.WriteFileByReader 原路径,保留锁语义)。
func writeAssetFile(writePath string, src io.Reader, boxID, originalName string) (err error) {
	// 从 writePath 反查真实 boxID,与传入 boxID 交叉校验
	pathBoxID := ExtractBoxIDFromAssetsPath(writePath)
	// 传入 boxID 与路径 box 都非空但不一致:路径指向另一个 box,拒绝(防跨 box 写入)
	if boxID != "" && pathBoxID != "" && boxID != pathBoxID {
		return fmt.Errorf("boxID mismatch: param=%s, path=%s", boxID, pathBoxID)
	}
	// 路径不在 box 下但传入的是加密 box:加密内容只能写 box 内,拒绝写全局 assets
	if pathBoxID == "" && boxID != "" && IsEncryptedBox(boxID) {
		return fmt.Errorf("encrypted box asset must be written inside the box directory, got global path: %s", writePath)
	}
	actualBoxID := pathBoxID
	if actualBoxID == "" {
		actualBoxID = boxID // 路径不在 box 下(如全局 assets),回退传入值
	}
	if actualBoxID != "" && IsEncryptedBox(actualBoxID) {
		HoldBoxReadLock(actualBoxID)
		defer ReleaseBoxReadLock(actualBoxID)
		dek, dekErr := GetDEKIfUnlocked(actualBoxID)
		if dekErr != nil {
			// 加密笔记本未解锁:拒绝写入,避免明文落盘(深度防御,见 issue #18034)
			return dekErr
		}
		// 已解锁的加密 box:全读 → 加密 → 落盘

View on GitHub (pinned to 9f775e8a12)