{"record":{"id":"f5e92c5d1b6e882e","repo":"BigPizzaV3/CodexPlusPlus","slug":"invalid-dream-skin-theme-id","errorCode":null,"errorMessage":"invalid Dream Skin theme id","messagePattern":"invalid Dream Skin theme id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_library.rs","lineNumber":371,"sourceCode":"    })();\n    if let Err(error) = staged {\n        let _ = remove_known_theme_directory(&staging);\n        return Err(error);\n    }\n    if let Err(error) = replace_theme_directory(&staging, &target, &suffix) {\n        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 {","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_library.rs#L353-L389","documentation":"load_stored_dream_skin_theme validates the theme id before touching the filesystem: if valid_theme_id(id) fails it bails with \"invalid Dream Skin theme id\". Because ids become directory names under state_dir/themes, this check blocks path traversal and other unsafe identifiers before any path is joined.","triggerScenarios":"Calling load_stored_dream_skin_theme (or any caller passing through it: save/rename/delete, create from image) with an id that fails valid_theme_id — e.g. containing '/' or '..', empty string, illegal characters, or excessive length.","commonSituations":"Passing raw user input or a URL-decoded name as the id; constructing an id by string concatenation including a path component; deserializing a config whose id field was tampered with; a caller passing a file path instead of an id.","solutions":["Sanitize the id before calling: use only the characters valid_theme_id accepts (alphanumeric/dash style) and trim whitespace","Reject empty ids at the UI/boundary layer before they reach the library","Never build ids from user-controlled paths; strip any '/' or '..' segments","Check upstream docs/tests for the exact valid_theme_id rules and validate input against them early"],"exampleFix":"// before\nload_stored_dream_skin_theme(&state_dir, &user_input)?;\n// after\nlet id = user_input.trim();\nanyhow::ensure!(valid_theme_id(id), \"invalid theme id\");\nload_stored_dream_skin_theme(&state_dir, id)?;","handlingStrategy":"validation","validationCode":"fn is_safe_theme_id(id: &str) -> bool {\n    !id.is_empty() && !id.contains(['/', '\\\\', '.', '..']) && id.len() <= 64\n}","typeGuard":"fn valid_theme_id(id: &str) -> bool {\n    !id.is_empty() && id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')\n}","tryCatchPattern":"match load_stored_dream_skin_theme(&state_dir, &id) {\n    Ok(draft) => use(draft),\n    Err(e) if e.to_string().contains(\"invalid Dream Skin theme id\") => eprintln!(\"'{}' is not a valid theme id\", id),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Validate ids at every boundary (UI input, JSON import, URL params) before calling the library","Generate ids programmatically (slugified names) instead of accepting raw user strings","Never construct ids by concatenating path fragments"],"tags":["path-traversal","invalid-identifier","validation"],"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"}