{"record":{"id":"74814a78330eb451","repo":"BigPizzaV3/CodexPlusPlus","slug":"invalid-user-script-key","errorCode":null,"errorMessage":"invalid user script key","messagePattern":"invalid user script key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/user_scripts.rs","lineNumber":153,"sourceCode":"        config.enabled = enabled;\n        self.save_config_unlocked(&config)?;\n        Ok(config)\n    }\n\n    pub fn set_script_enabled(&self, key: &str, enabled: bool) -> anyhow::Result<UserScriptConfig> {\n        let _guard = self.config_lock.lock().unwrap();\n        let mut config = self.load_config_unlocked();\n        config.scripts.insert(key.to_string(), enabled);\n        self.save_config_unlocked(&config)?;\n        Ok(config)\n    }\n\n    pub fn delete_user_script(&self, key: &str) -> anyhow::Result<UserScriptConfig> {\n        let Some(file_name) = key.strip_prefix(\"user:\").filter(|value| !value.is_empty()) else {\n            anyhow::bail!(\"only user scripts can be deleted\");\n        };\n        if file_name.contains(['/', '\\\\']) || file_name == \".\" || file_name == \"..\" {\n            anyhow::bail!(\"invalid user script key\");\n        }\n        let path = self.user_dir.join(file_name);\n        let canonical_user_dir = self\n            .user_dir\n            .canonicalize()\n            .or_else(|_| {\n                fs::create_dir_all(&self.user_dir)?;\n                self.user_dir.canonicalize()\n            })\n            .with_context(|| {\n                format!(\n                    \"failed to resolve user script directory {}\",\n                    self.user_dir.display()\n                )\n            })?;\n        if path.exists() {\n            let canonical_path = path\n                .canonicalize()","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/user_scripts.rs#L135-L171","documentation":"delete_user_script only accepts keys of the form 'user:<file_name>' where file_name is a plain file name. This error is thrown when the stripped file name contains a path separator ('/' or '\\\\') or is '.' or '..', since such keys would escape or name no concrete script file in the user scripts directory.","triggerScenarios":"Calling delete_user_script with a key whose file_name part contains '/' or '\\\\' (e.g. 'user:sub/dir.js') or equals '.' or '..'.","commonSituations":"Frontend passes a full relative path or a market/builtin script key through the delete API; stored script keys were constructed by joining directory components; older inventories stored keys with subdirectories before validation was added.","solutions":["Ensure the key passed is exactly 'user:<plain-file-name>' with no separators — e.g. strip directory parts or look the correct key up in the user_scripts inventory before calling delete_user_script","If the script actually lives in a subdirectory, move/flatten it into the user scripts directory so it has a flat file name key","For market or builtin scripts, use the dedicated metadata/builtin delete flow instead of delete_user_script"],"exampleFix":"// before\nmanager.delete_user_script(\"user:sub/backup.js\")?;\n// after\nlet file = std::path::Path::new(\"sub/backup.js\").file_name().unwrap().to_str().unwrap();\nmanager.delete_user_script(&format!(\"user:{file}\"))?;","handlingStrategy":"validation","validationCode":"fn is_valid_user_key(key: &str) -> bool {\n    match key.strip_prefix(\"user:\") {\n        Some(f) => !f.is_empty() && !f.contains(['/', '\\\\']) && f != \".\" && f != \"..\",\n        None => false,\n    }\n}","typeGuard":"fn valid_user_script_key(key: &str) -> Option<&str> {\n    key.strip_prefix(\"user:\").filter(|f| !f.is_empty() && !f.contains(['/', '\\\\']) && *f != \".\" && *f != \"..\")\n}","tryCatchPattern":"match manager.delete_user_script(key) {\n    Err(e) if e.to_string() == \"invalid user script key\" => eprintln!(\"key must be 'user:<flat-file-name>'\"),\n    other => other?,\n}","preventionTips":["Always take keys from the inventory returned by the manager rather than constructing them","Normalize/flatten any path to its file_name before forming 'user:<name>' keys","Distinguish market/builtin keys from user keys before calling delete"],"tags":["validation","path","invalid-argument"],"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"}