BigPizzaV3/CodexPlusPlus · error
refusing to delete script outside user script directory
Error message
refusing to delete script outside user script directory
What it means
Before removing a user script file, the manager canonicalizes the target path and verifies it still resolves inside the canonicalized user scripts directory. This error is thrown when the resolved path falls outside that directory — a symlink or alias pointing elsewhere — to prevent deleting arbitrary files.
Solutions
- Remove the symlink and place a real file with the script contents in the user scripts directory, then retry delete
- Verify the user scripts directory location and that the target file is a regular file inside it (not a link)
- If you intentionally keep external scripts via symlink, copy the script into the user dir and delete that copy instead
Example fix
// before
// user:my.js -> symlink to /etc/some.js => refused
// after
fs::remove_file("user_dir/my.js");
fs::write("user_dir/my.js", real_contents);
manager.delete_user_script("user:my.js")?; Defensive patterns
Strategy: validation
Validate before calling
let target = user_dir.join(file_name);
let meta = std::fs::symlink_metadata(&target)?;
if meta.file_type().is_symlink() { /* refuse or copy-before-delete */ } Type guard
fn is_regular_file_inside(p: &Path, dir: &Path) -> bool {
p.canonicalize().map(|c| c.starts_with(dir) && c.is_file()).unwrap_or(false)
} Try / catch
match manager.delete_user_script(key) {
Err(e) if e.to_string().contains("outside user script directory") => eprintln!("target is a symlink; remove it manually or replace with a real file"),
other => other?,
} Prevention
- Do not symlink scripts into the user scripts directory; copy them instead
- Periodically audit the scripts directory for links created by sync tools
- Pin/canonicalize the user_dir location so it does not move between runs
When it happens
Trigger: Calling delete_user_script with a 'user:<file_name>' key whose file exists but is a symlink (or junction/hardlink-resolved path) pointing outside the user scripts directory, so canonicalize() resolves it elsewhere.
Common situations: User replaced a script file with a symlink to a shared script elsewhere; backup/sync tools replaced files with links; the user_dir itself was relocated and canonical paths shifted.
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
- Dream Skin path must not be a symbolic link
- Dream Skin theme path is not a safe directory
- File is a reparse point
- Monitor lock is a reparse point
- Parent directory is a reparse point
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/e95803fc6a6719e6.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/user_scripts.rs:174
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()
.with_context(|| format!("failed to resolve user script {}", path.display()))?;
if !canonical_path.starts_with(&canonical_user_dir) {
anyhow::bail!("refusing to delete script outside user script directory");
}
fs::remove_file(&canonical_path).with_context(|| {
format!("failed to delete user script {}", canonical_path.display())
})?;
}
let _guard = self.config_lock.lock().unwrap();
let mut config = self.load_config_unlocked();
config.scripts.remove(key);
config.market.remove(key);
self.save_config_unlocked(&config)?;
Ok(config)
}
pub fn user_script_path_for_market_id(&self, id: &str) -> PathBuf {
self.user_dir.join(market_script_filename(id))
}
View on GitHub (pinned to b1ed92e5e4)