{"record":{"id":"e34bc26325350515","repo":"BigPizzaV3/CodexPlusPlus","slug":"dream-skin-theme-path-is-not-a-safe-directory","errorCode":null,"errorMessage":"Dream Skin theme path is not a safe directory","messagePattern":"Dream Skin theme path is not a safe directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_library.rs","lineNumber":377,"sourceCode":"        let _ = remove_known_theme_directory(&staging);\n        return Err(error);\n    }\n    let stored = load_stored_dream_skin_theme(state_dir, &config.id)?;\n    Ok(summary_from_draft(&stored, false, false))\n}\n\npub fn load_stored_dream_skin_theme(\n    state_dir: &Path,\n    id: &str,\n) -> anyhow::Result<DreamSkinThemeDraft> {\n    if !valid_theme_id(id) {\n        bail!(\"invalid Dream Skin theme id\");\n    }\n    let directory = state_dir.join(THEMES_DIR).join(id);\n    let metadata = std::fs::symlink_metadata(&directory)\n        .with_context(|| format!(\"Dream Skin theme not found: {id}\"))?;\n    if !metadata.file_type().is_dir() || metadata.file_type().is_symlink() {\n        bail!(\"Dream Skin theme path is not a safe directory\");\n    }\n    let config_path = directory.join(THEME_CONFIG_FILE);\n    let metadata = std::fs::symlink_metadata(&config_path)\n        .with_context(|| format!(\"Dream Skin theme config not found: {id}\"))?;\n    if !metadata.file_type().is_file()\n        || metadata.file_type().is_symlink()\n        || metadata.len() > THEME_CONFIG_LIMIT\n    {\n        bail!(\"invalid Dream Skin theme config\");\n    }\n    let config: DreamSkinThemeConfig = serde_json::from_slice(&std::fs::read(&config_path)?)?;\n    if config.id != id {\n        bail!(\"Dream Skin theme id does not match directory\");\n    }\n    let image = find_theme_image(&directory)\n        .ok_or_else(|| anyhow::anyhow!(\"Dream Skin theme must contain exactly one image\"))?;\n    let draft = DreamSkinThemeDraft {\n        config,","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_library.rs#L359-L395","documentation":"After validating the id, load_stored_dream_skin_theme checks symlink_metadata of state_dir/themes/<id>: the entry must be a real directory and not a symlink. If it is a symlink or a non-directory (file, etc.), it bails with \"Dream Skin theme path is not a safe directory\" — a hardening check against symlink-based path escapes.","triggerScenarios":"The theme directory under themes/ is a symlink (manually created, restored from a backup tool, or left by malicious tampering), or the path exists but is a regular file rather than a directory.","commonSituations":"Backup/restore tools that replaced directories with symlinks; a user symlinking themes from another location (e.g. dotfile managers like stow/chezmoi); someone creating a file where the directory should be.","solutions":["Remove the symlink and place a real directory at themes/<id> (copy the actual content in)","If using a dotfile manager, exclude the themes directory from symlink management","Verify with `ls -la` that the entry is a directory (d...) and not a link (l...)","If a file occupies the path, delete that file and recreate the theme via the library API"],"exampleFix":"// before (unsafe state)\n// themes/my-theme -> /mnt/shared/theme  (symlink)\n// after\nrm themes/my-theme\ncp -r /mnt/shared/theme/ themes/my-theme/  # real directory","handlingStrategy":"validation","validationCode":"let md = std::fs::symlink_metadata(themes_dir.join(id))?;\nif !md.file_type().is_dir() || md.file_type().is_symlink() {\n    return Err(anyhow::anyhow!(\"themes/{id} must be a real directory, not a symlink or file\"));\n}","typeGuard":"fn is_safe_theme_dir(path: &std::path::Path) -> bool {\n    match std::fs::symlink_metadata(path) {\n        Ok(md) => md.file_type().is_dir() && !md.file_type().is_symlink(),\n        Err(_) => false,\n    }\n}","tryCatchPattern":"match load_stored_dream_skin_theme(&state_dir, &id) {\n    Ok(draft) => use(draft),\n    Err(e) if e.to_string().contains(\"not a safe directory\") => eprintln!(\"themes/{id} is a symlink or not a directory; restore a real directory\"),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Exclude the themes directory from dotfile managers (stow/chezmoi) that create symlinks","Prefer copying over symlinking when moving themes between machines","Periodically audit the themes directory for symlinked entries"],"tags":["symlink","security","path-validation"],"backgroundTag":"path-traversal-blocked","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}