{"record":{"id":"3aaa7d81d7442147","repo":"jdx/mise","slug":"user-service-environment-value-for-key-con","errorCode":null,"errorMessage":"user service '{}': environment value for {key} contains {c:?}, which cmd.exe would reinterpret; set it inside the program instead","messagePattern":"user service '(.+?)': environment value for (.+?) contains (.+?), which cmd\\.exe would reinterpret; set it inside the program instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/scheduled_tasks.rs","lineNumber":220,"sourceCode":"/// change are rejected rather than passed through differently.\nfn exec_action(request: &ScheduledTaskRequest) -> Result<(String, String)> {\n    let (program, args) = split_command(&request.command);\n    if request.environment.is_empty() {\n        return Ok((program, args));\n    }\n    let mut sets = vec![];\n    for (key, value) in &request.environment {\n        if key.is_empty() || key.contains(['=', '\"', '%', '\\n', '\\r']) {\n            bail!(\n                \"user service '{}': environment key {key:?} cannot be set through cmd.exe\",\n                request.name\n            );\n        }\n        if let Some(c) = value\n            .chars()\n            .find(|c| matches!(c, '\"' | '%' | '&' | '|' | '<' | '>' | '^' | '\\n' | '\\r'))\n        {\n            bail!(\n                \"user service '{}': environment value for {key} contains {c:?}, which cmd.exe would reinterpret; set it inside the program instead\",\n                request.name\n            );\n        }\n        sets.push(format!(\"set \\\"{key}={value}\\\"\"));\n    }\n    // the command line goes through cmd.exe too: what it would split or\n    // chain is rejected the same way, rather than run differently\n    if let Some(c) = format!(\"{program} {args}\")\n        .chars()\n        .find(|c| matches!(c, '%' | '&' | '|' | '<' | '>' | '^' | '\\n' | '\\r'))\n    {\n        bail!(\n            \"user service '{}': the command contains {c:?}, which cmd.exe would reinterpret when `environment` is set; move it into a script\",\n            request.name\n        );\n    }\n    let program = if program.contains(char::is_whitespace) {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/scheduled_tasks.rs#L202-L238","documentation":"Environment VALUES for a user service are injected through `set \"key=value\"` inside cmd.exe. Characters cmd.exe reinterprets (quotes, percent expansion, chain operators, redirection, escapes, newlines) would change what actually gets set, so exec_action rejects any value containing them.","triggerScenarios":"render_xml -> exec_action on Windows with request.environment containing a value that includes '\"', '%', '&', '|', '<', '>', '^', '\\n', or '\\r'.","commonSituations":"Passwords or tokens containing '%' or '&' in env values; shell snippets pasted into env values; values with trailing CRLF read from a Windows text file.","solutions":["Remove or escape the offending character from the value","Set the variable inside the program itself (read from a protected file) instead of via the environment map","Point the value at a path/config without special characters"],"exampleFix":"// before\nenvironment: { \"TOKEN\": \"a%b&c\" }\n// after\nenvironment: { \"TOKEN_FILE\": \"C:\\\\secrets\\\\token.txt\" }","handlingStrategy":"validation","validationCode":"const bad = Object.entries(svc.environment).find(([, v]) => /[\"%&|<>^\\r\\n]/.test(v));\nif (bad) throw new Error(`env value for ${bad[0]} contains cmd.exe metacharacter`);","typeGuard":"function isCmdSafeValue(v) { return typeof v === 'string' && ![...v].some(c => '\"%&|<>^\\r\\n'.includes(c)); }","tryCatchPattern":"try { renderServiceXml(svc); } catch (e) { if (String(e).includes('cmd.exe would reinterpret')) { moveSecretsToFile(svc.environment); } else throw e; }","preventionTips":["Keep secrets and tokens with special characters in files read by the program, not env values","Strip CRLF when loading env values from Windows text files","Review env values for % (expansion) and & | < > ^ (operators) before saving"],"tags":["windows","cmd-exe","environment","escaping"],"backgroundTag":"invalid-argument-value","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}