Repository navigation
Description
Xonsh activation can prepend a different directory to PATH when an environment created in a UTF-8 session has a non-ASCII path and is later activated under ISO-8859-1. Activation succeeds, but python and other commands may resolve outside the environment.
Affected code
At the reported commit 8e09166ddfbdaed3a5dbccc216d38ff1d3dbb4c2, XonshActivator.quote writes the destination as a text literal, and activate.xsh uses it for VIRTUAL_ENV and PATH. The same assignment remains at upstream ebe06113.
Mechanism
The generated script preserves the Unicode spelling of the destination. When Xonsh sources it, VIRTUAL_ENV becomes that text and its bin path becomes the first PATH entry. On POSIX, Python encodes string paths with the current process's filesystem encoding. Thus caf\xc3\xa9 created under UTF-8 becomes caf\xe9 when the Xonsh session uses ISO-8859-1; those bytes name different directories. The creation-time codec check passes in the UTF-8 session and cannot check the later sourcing session. This differs from #3412, which addressed a codec mismatch during creation.
Reproduction
On Linux with virtualenv, Xonsh, and the en_US.ISO-8859-1 locale installed, run this from a UTF-8 shell:
work=$(mktemp -d)
mkdir -p "$work/$(printf 'caf\303\251')"
cd "$work/$(printf 'caf\303\251')"
LC_ALL=C.UTF-8 virtualenv --no-periodic-update .venv
PYTHONUTF8=0 LC_ALL=en_US.ISO-8859-1 xonsh --no-rc -c 'source .venv/bin/activate.xsh
import os
print(os.fsencode(__xonsh__.env["PATH"][0]))'The report reproduced this at 8e09166d with CPython 3.14.10 and Xonsh 0.25.0. Its ISO-8859-1 Xonsh run selected a path ending in caf\xe9/.venv/bin; UTF-8 Xonsh and ISO-8859-1 Bash controls selected caf\xc3\xa9/.venv/bin. The reporter's full reproducer printed BUG when a file in the byte-spelled sibling ran. The first PATH entry should retain the created directory's caf\xc3\xa9 bytes in every session.
Impact
This requires Xonsh in a legacy locale, a non-ASCII destination, and an environment created under UTF-8. Reproducibility is moderate because those settings are needed but no race is involved. Real-world exposure is unlikely because the three conditions must coincide. A planted sibling requires write access to the destination ancestor, which is outside the project's security threat model; the demonstrated defect is incorrect activation.
Credits
Reported by oss-scanner as ANT-2026-PQW92I38.
Activity
🐛 fix(xonsh): keep environment path bytes
🐛 fix(xonsh): keep environment path bytes
🐛 fix(xonsh): keep environment path bytes
🐛 fix(xonsh): keep environment path bytes
🐛 fix(xonsh): retain environment path bytes