{"record":{"id":"77a346cfda1642a4","repo":"BigPizzaV3/CodexPlusPlus","slug":"invalid-dream-skin-destination-name","errorCode":null,"errorMessage":"invalid Dream Skin destination name","messagePattern":"invalid Dream Skin destination name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin.rs","lineNumber":49,"sourceCode":"\npub fn import_dream_skin_image(source: &Path, state_dir: &Path) -> anyhow::Result<PathBuf> {\n    let managed_dir = state_dir.join(MANAGED_THEME_DIR);\n    let destination = prepare_dream_skin_image_for_directory(source, &managed_dir, \"current\")?;\n    remove_other_managed_images(&managed_dir, &destination)?;\n    Ok(destination)\n}\n\npub(crate) fn prepare_dream_skin_image_for_directory(\n    source: &Path,\n    destination_dir: &Path,\n    destination_stem: &str,\n) -> anyhow::Result<PathBuf> {\n    if destination_stem.is_empty()\n        || !destination_stem\n            .bytes()\n            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'))\n    {\n        bail!(\"invalid Dream Skin destination name\");\n    }\n    let metadata = std::fs::symlink_metadata(source)\n        .with_context(|| format!(\"failed to read image metadata {}\", source.display()))?;\n    if !metadata.file_type().is_file() || metadata.file_type().is_symlink() {\n        bail!(\"Dream Skin image is not a file\");\n    }\n    if metadata.len() == 0 {\n        bail!(\"Dream Skin image is empty\");\n    }\n    if metadata.len() > DREAM_SKIN_SOURCE_LIMIT {\n        bail!(\"Dream Skin source image exceeds 50 MiB\");\n    }\n\n    let extension = supported_image_extension(source)?;\n    std::fs::create_dir_all(destination_dir).with_context(|| {\n        format!(\n            \"failed to create Dream Skin theme directory {}\",\n            destination_dir.display()","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin.rs#L31-L67","documentation":"prepare_dream_skin_image_for_directory validates the destination stem before copying a Dream Skin theme image; it must be non-empty and contain only ASCII alphanumerics, '-' or '_'. This prevents unsafe filesystem names and path traversal. import_dream_skin_image is the caller.","triggerScenarios":"import_dream_skin_image is called with a destination_stem that is empty or contains characters outside [A-Za-z0-9_-] (e.g. spaces, CJK characters, dots, slashes, '../').","commonSituations":"User names an imported theme after the original image filename containing spaces or Chinese characters; UI passes the raw filename instead of a sanitized stem; an attempted path traversal ('../evil') is blocked.","solutions":["Sanitize the destination stem before calling: strip the extension and replace disallowed characters with '-' or '_'.","Use ASCII slugs for theme names; if the user name is non-ASCII, transliterate or hash it into [A-Za-z0-9_-].","Ensure the stem is non-empty after sanitization (fallback to a generated name like 'theme-<timestamp>')."],"exampleFix":"// before\nimport_dream_skin_image(source, dir, \"我的 主题.png\")?;\n// after\nlet stem: String = \"我的 主题.png\"\n    .chars()\n    .map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c } else { '-' })\n    .collect();\nimport_dream_skin_image(source, dir, stem.trim_matches('-'))?;","handlingStrategy":"validation","validationCode":"// TypeScript-side (Tauri frontend) pre-check before invoking import\nfunction isValidDreamSkinStem(stem: string): boolean {\n  return /^[A-Za-z0-9_-]+$/.test(stem);\n}\nif (!isValidDreamSkinStem(userProvidedStem)) throw new Error(\"theme name must be [A-Za-z0-9_-]\");","typeGuard":"fn is_safe_stem(stem: &str) -> bool {\n    !stem.is_empty()\n        && stem.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_'))\n}","tryCatchPattern":null,"preventionTips":["Slugify theme names in the UI before submitting them to the backend","Never pass raw filenames (with extension or spaces) as the stem","Always trim and validate the stem after user input, on both frontend and backend"],"tags":["validation","filename","path-safety"],"backgroundTag":"invalid-identifier-format","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"}