Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(claude-code): only refuse custom env keys that change program lookup
James Dam9033c7564076
diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rsindex 649ebce54..4f6f10c3e 100644--- a/src-tauri/src/core/system/commands.rs+++ b/src-tauri/src/core/system/commands.rs@@ -336,9 +336,9 @@ fn is_valid_env_key(key: &str) -> bool {chars.all(|c| c.is_ascii_alphanumeric() || c == '_')}-/// Variables that change how shells and other programs start, or where-/// Windows resolves its system binaries. Jan writes custom variables into the-/// user's shell profile or Windows user environment, so these are refused.+/// Variables that change where programs are found, or where Windows resolves+/// its system binaries. Custom variables are typed by the user, so only keys+/// that change how Jan or the OS locate programs are refused.const RESERVED_ENV_KEYS: &[&str] = &["PATH","PATHEXT",@@ -346,17 +346,6 @@ const RESERVED_ENV_KEYS: &[&str] = &["SYSTEMROOT","WINDIR","SYSTEMDRIVE",- "PROMPT_COMMAND",- "BASH_ENV",- "ENV",- "ZDOTDIR",- "SHELLOPTS",- "BASHOPTS",- "IFS",- "PS4",- "NODE_OPTIONS",- "PYTHONSTARTUP",- "PERL5OPT",];/// Prefixes of reserved variable names: the dynamic loader's settings and@@ -384,8 +373,8 @@ fn validate_env_vars(env_vars: &[(String, String)]) -> Result<(), String> {}if is_reserved_env_key(key) {return Err(format!(- "Jan does not set {}: it changes how shells or programs start. Remove it \- from the custom environment variables.",+ "Jan does not set {}: it changes how Jan or the system finds programs. \+ Remove it from the custom environment variables.",key));}@@ -1396,22 +1385,11 @@ mod tests {"SystemRoot","windir","SystemDrive",- "PROMPT_COMMAND",- "BASH_ENV",- "ENV",- "ZDOTDIR",- "SHELLOPTS",- "BASHOPTS",- "IFS",- "PS4","LD_PRELOAD","LD_LIBRARY_PATH","LD_AUDIT","DYLD_INSERT_LIBRARIES","dyld_library_path",- "NODE_OPTIONS",- "PYTHONSTARTUP",- "PERL5OPT","JAN_DATA_FOLDER","jan_anything",] {@@ -1425,7 +1403,21 @@ mod tests {"OLD_LD_PRELOAD","JANET","ANTHROPIC_AUTH_TOKEN",+ "ANTHROPIC_BASE_URL","LD",+ // Typed by the user on purpose (e.g. a Claude Code tweak), so allowed.+ "NODE_OPTIONS",+ "node_options",+ "BASH_ENV",+ "ENV",+ "ZDOTDIR",+ "PROMPT_COMMAND",+ "SHELLOPTS",+ "BASHOPTS",+ "IFS",+ "PS4",+ "PYTHONSTARTUP",+ "PERL5OPT",] {assert!(validate_env_vars(&[kv(good, "v")]).is_ok(),@@ -1434,7 +1426,7 @@ mod tests {}let dir = tempdir().unwrap();let path = dir.path().join(".zshenv");- assert!(write_env_to_shell(path.to_str().unwrap(), &[kv("BASH_ENV", "/tmp/x")]).is_err());+ assert!(write_env_to_shell(path.to_str().unwrap(), &[kv("LD_PRELOAD", "/tmp/x")]).is_err());assert!(!path.exists());}