BigPizzaV3/CodexPlusPlus · error

invalid user script key

Error message

invalid user script key

What it means

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.

Solutions

  1. 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
  2. If the script actually lives in a subdirectory, move/flatten it into the user scripts directory so it has a flat file name key
  3. For market or builtin scripts, use the dedicated metadata/builtin delete flow instead of delete_user_script

Example fix

// before
manager.delete_user_script("user:sub/backup.js")?;
// after
let file = std::path::Path::new("sub/backup.js").file_name().unwrap().to_str().unwrap();
manager.delete_user_script(&format!("user:{file}"))?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_user_key(key: &str) -> bool {
    match key.strip_prefix("user:") {
        Some(f) => !f.is_empty() && !f.contains(['/', '\\']) && f != "." && f != "..",
        None => false,
    }
}

Type guard

fn valid_user_script_key(key: &str) -> Option<&str> {
    key.strip_prefix("user:").filter(|f| !f.is_empty() && !f.contains(['/', '\\']) && *f != "." && *f != "..")
}

Try / catch

match manager.delete_user_script(key) {
    Err(e) if e.to_string() == "invalid user script key" => eprintln!("key must be 'user:<flat-file-name>'"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling delete_user_script with a key whose file_name part contains '/' or '\\' (e.g. 'user:sub/dir.js') or equals '.' or '..'.

Common situations: 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.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/74814a78330eb451. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/user_scripts.rs:153

        config.enabled = enabled;
        self.save_config_unlocked(&config)?;
        Ok(config)
    }

    pub fn set_script_enabled(&self, key: &str, enabled: bool) -> anyhow::Result<UserScriptConfig> {
        let _guard = self.config_lock.lock().unwrap();
        let mut config = self.load_config_unlocked();
        config.scripts.insert(key.to_string(), enabled);
        self.save_config_unlocked(&config)?;
        Ok(config)
    }

    pub fn delete_user_script(&self, key: &str) -> anyhow::Result<UserScriptConfig> {
        let Some(file_name) = key.strip_prefix("user:").filter(|value| !value.is_empty()) else {
            anyhow::bail!("only user scripts can be deleted");
        };
        if file_name.contains(['/', '\\']) || file_name == "." || file_name == ".." {
            anyhow::bail!("invalid user script key");
        }
        let path = self.user_dir.join(file_name);
        let canonical_user_dir = self
            .user_dir
            .canonicalize()
            .or_else(|_| {
                fs::create_dir_all(&self.user_dir)?;
                self.user_dir.canonicalize()
            })
            .with_context(|| {
                format!(
                    "failed to resolve user script directory {}",
                    self.user_dir.display()
                )
            })?;
        if path.exists() {
            let canonical_path = path
                .canonicalize()

View on GitHub (pinned to b1ed92e5e4)