Summary
A quoting and encoding mismatch in virtualenv's POSIX xonsh activation script can allow attacker-influenced data to become executable statements. The risk arises when a generated UTF-8 script is sourced by xonsh using a legacy multibyte encoding that changes how escaped quotes are interpreted.
Affected context
The issue affects POSIX xonsh activation scripts generated by virtualenv when printable non-ASCII prompt or destination data is included. Risk depends on the generated script being read with a legacy multibyte codec, such as GBK or Big5, and then sourced by a user.
Exploit preconditions
- Attack surface: Generation and use of a POSIX xonsh activation script
- Required access: Ability to influence prompt or destination data written into the script
- Trigger point: A user sources the generated
activate.xshscript - Why exploitation is possible: The script is written as UTF-8, but xonsh may read it using a different encoding; under certain legacy multibyte codecs, a byte can consume an escaping backslash and change how a quote is parsed
Why this happens
The underlying issue is a mismatch between how data is quoted for the generated script and how that script is later decoded. Using repr() to produce a quoted value does not ensure that its escaping remains effective when UTF-8 output is interpreted using a different multibyte codec. This can let data alter the script's syntax, mapping to CWE-94: Improper Control of Generation of Code.
Potential impact
- Attacker-influenced statements could execute in the shell context of the user sourcing the script
- The user's shell session and accessible resources could be compromised
- Commands could run with the permissions available to that user
General mitigation guidance
Defensive patterns focus on keeping data separate from executable code and ensuring consistent encoding across script generation and consumption.
- Prefer activation mechanisms that do not embed variable data in executable scripts
- Where scripts must be generated, use context-appropriate quoting and encoding-aware handling
- Avoid treating user-influenced prompt or destination values as trusted input
- Use consistent, explicit encodings when writing and reading generated scripts
- Limit the permissions and resources available to processes that source activation scripts
How teams detect issues like this
- Use static analysis to flag generated shell code that interpolates data or relies on generic string representations for quoting
- Review script-generation paths for encoding mismatches between output and execution environments
- Check whether user-influenced values can reach executable activation scripts
- Enforce code-generation and encoding policies in review and CI workflows; automated review tools may help identify risky patterns

