LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
fix(fs): reject relative write paths
Dongmin, Yuc98fccb39502
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rsindex 2dff8d9a..75afcb15 100644--- a/src-tauri/src/commands/fs.rs+++ b/src-tauri/src/commands/fs.rs@@ -22,6 +22,17 @@ const MEDIA_EXTS: &[&str] = &[];const LEGACY_DOC_EXTS: &[&str] = &["ppt", "pages", "numbers", "key", "epub"];+fn require_absolute_path(operation: &str, path: &str) -> Result<(), String> {+ if Path::new(path).is_absolute() {+ Ok(())+ } else {+ Err(format!(+ "{operation} requires an absolute path; got relative path '{}'",+ path+ ))+ }+}+#[tauri::command]pub async fn read_file(path: String, extract_images: Option<bool>) -> Result<String, String> {// `spawn_blocking` is REQUIRED, not a perf nicety. The body does@@ -941,6 +952,7 @@ fn extract_odf_text(archive: &mut zip::ZipArchive<fs::File>) -> Result<String, Spub async fn write_file(path: String, contents: String) -> Result<(), String> {tauri::async_runtime::spawn_blocking(move || {run_guarded("write_file", || {+ require_absolute_path("write_file", &path)?;let p = Path::new(&path);if let Some(parent) = p.parent() {fs::create_dir_all(parent)@@ -961,6 +973,7 @@ pub async fn write_file(path: String, contents: String) -> Result<(), String> {pub async fn write_file_atomic(path: String, contents: String) -> Result<(), String> {tauri::async_runtime::spawn_blocking(move || {run_guarded("write_file_atomic", || {+ require_absolute_path("write_file_atomic", &path)?;let p = Path::new(&path);if let Some(parent) = p.parent() {fs::create_dir_all(parent)@@ -1365,6 +1378,7 @@ fn collect_related_pages(pub async fn create_directory(path: String) -> Result<(), String> {tauri::async_runtime::spawn_blocking(move || {run_guarded("create_directory", || {+ require_absolute_path("create_directory", &path)?;fs::create_dir_all(&path).map_err(|e| format!("Failed to create directory '{}': {}", path, e))})@@ -1921,6 +1935,27 @@ mod tests {dir}+ #[test]+ fn reject_relative_write_paths_before_touching_cwd() {+ assert!(require_absolute_path("write_file", "wiki/sources/stray.md").is_err());+ assert!(require_absolute_path("write_file", "./wiki/sources/stray.md").is_err());+ }++ #[test]+ fn allow_absolute_write_paths() {+ assert!(require_absolute_path("write_file", "/tmp/project/wiki/sources/page.md").is_ok());+ #[cfg(windows)]+ {+ assert!(require_absolute_path("write_file", "C:/project/wiki/sources/page.md").is_ok());+ assert!(+ require_absolute_path("write_file", r"C:\project\wiki\sources\page.md").is_ok()+ );+ assert!(+ require_absolute_path("write_file", r"\\server\share\wiki\sources\page.md").is_ok()+ );+ }+ }+/// Pull the inner sync `copy_recursive` body out from/// `copy_directory` so the test doesn't need to spin up a/// tokio runtime just to exercise file-system recursion.diff --git a/src/commands/fs.test.ts b/src/commands/fs.test.tsnew file mode 100644index 00000000..f16a4131--- /dev/null+++ b/src/commands/fs.test.ts@@ -0,0 +1,50 @@+import { beforeEach, describe, expect, it, vi } from "vitest"++const mocks = vi.hoisted(() => ({+ invoke: vi.fn(),+}))++vi.mock("@tauri-apps/api/core", () => ({+ invoke: mocks.invoke,+}))++import { createDirectory, writeFile, writeFileAtomic } from "./fs"++describe("fs command path guards", () => {+ beforeEach(() => {+ mocks.invoke.mockReset()+ })++ it("rejects relative write paths before invoking Tauri", async () => {+ await expect(writeFile("wiki/sources/stray.md", "content")).rejects.toThrow(+ /absolute path/i,+ )++ expect(mocks.invoke).not.toHaveBeenCalled()+ })++ it("rejects relative atomic write paths before invoking Tauri", async () => {+ await expect(writeFileAtomic("wiki/sources/stray.md", "content")).rejects.toThrow(+ /absolute path/i,+ )++ expect(mocks.invoke).not.toHaveBeenCalled()+ })++ it("rejects relative directory paths before invoking Tauri", async () => {+ await expect(createDirectory("wiki/sources")).rejects.toThrow(/absolute path/i)++ expect(mocks.invoke).not.toHaveBeenCalled()+ })++ it("allows absolute write paths", async () => {+ mocks.invoke.mockResolvedValue(undefined)++ await writeFile("/tmp/project/wiki/sources/page.md", "content")++ expect(mocks.invoke).toHaveBeenCalledWith("write_file", {+ path: "/tmp/project/wiki/sources/page.md",+ contents: "content",+ })+ })+})diff --git a/src/commands/fs.ts b/src/commands/fs.tsindex 93ca9b47..f42338fb 100644--- a/src/commands/fs.ts+++ b/src/commands/fs.ts@@ -1,6 +1,7 @@import { invoke } from "@tauri-apps/api/core"import type { FileNode, WikiProject } from "@/types/wiki"import { ensureProjectId, upsertProjectInfo } from "@/lib/project-identity"+import { isAbsolutePath } from "@/lib/path-utils"/** Raw shape returned by the Rust commands — id is attached client-side. */interface RawProject {@@ -19,10 +20,12 @@ export async function readFile(}export async function writeFile(path: string, contents: string): Promise<void> {+ assertAbsoluteFsPath("writeFile", path)return invoke<void>("write_file", { path, contents })}export async function writeFileAtomic(path: string, contents: string): Promise<void> {+ assertAbsoluteFsPath("writeFileAtomic", path)return invoke<void>("write_file_atomic", { path, contents })}@@ -60,6 +63,7 @@ export async function findRelatedWikiPages(}export async function createDirectory(path: string): Promise<void> {+ assertAbsoluteFsPath("createDirectory", path)return invoke<void>("create_directory", { path })}@@ -79,6 +83,12 @@ export async function getFileMd5(path: string): Promise<string> {return invoke<string>("get_file_md5", { path })}+function assertAbsoluteFsPath(operation: string, path: string): void {+ if (!isAbsolutePath(path)) {+ throw new Error(`${operation} requires an absolute path: ${path}`)+ }+}+/** Mirror of `commands::fs::FileBase64` (Rust side). */export interface FileBase64 {base64: string