Skip to content

🐛 fix(xonsh): preserve values across codecs - #3717

Closed
gaborbernat wants to merge 38 commits into
pypa:mainfrom
gaborbernat:fix/y91-xonsh-utf7
Closed

gaborbernat wants to merge 38 commits into
pypa:mainfrom
gaborbernat:fix/y91-xonsh-utf7

Conversation

@gaborbernat

Copy link
Copy Markdown
Contributor

At the merge base, Xonsh activation embedded prompt and destination values using ascii(). Xonsh's source command decodes the generated script with $XONSH_ENCODING before parsing Python syntax. Under UTF-7, decoded prompt text could become syntax when a user sourced an environment created from a lower-trust prompt. The renderer now constructs affected characters from code points. This addresses draft advisory ANT-2026-Y91OJFTQ.

Source decoding could change the literal

The template substitution inserts quoted values into executable Xonsh assignments. ascii() kept non-ASCII characters out of those assignments, but left printable punctuation that some source codecs reinterpret. The new quote function emits an ordinary literal for unaffected ASCII values and an expression built from code points for characters that source codecs can reinterpret.

sequenceDiagram
    participant P as Prompt supplier
    participant V as virtualenv
    participant F as activate.xsh
    participant X as Xonsh source
    P->>+V: Provide prompt text
    rect rgb(255, 214, 214)
    V->>+F: Before: write punctuation in a literal
    F->>+X: Decode source as UTF-7
    X-->>X: Decoded text changes Python syntax
    end
    rect rgb(216, 243, 220)
    V->>F: Now: write expression from code points
    F->>X: Decode source as UTF-7
    X-->>X: Reconstruct original prompt value
    end
    deactivate X
    deactivate F
    deactivate V
Loading

Behavior changes

Xonsh preserves prompt and destination values containing characters that UTF-7 could reinterpret when it sources a regenerated script. Ordinary ASCII values still use Python literals; affected values make the generated script longer. Existing environments need their activation scripts regenerated. This change does not address the separate legacy activate_this.py loader described in the report.

Reported by oss-scanner: ANT-2026-Y91OJFTQ.

Replaces #3668 after its merge was reverted.

gaborbernat and others added 30 commits November 19, 2026 22:36
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Pin the pre-commit hook to [simplint
0.14.2](https://github.com/gaborbernat/simplint/releases/tag/0.14.2).
This release starts larger files earlier during parallel checks and
sizes cache reads to the archive on disk.

Give bare `Final` annotations explicit types across virtualenv,
maintenance tasks and tests. The wheel installer also declares its lazy
`posixpath` import. Refresh the CodeQL mutant patches for the new
annotations.

The macOS GraalPy reseeding test timed out while uninstalling pip.
Collect each package directory once when cleaning up files from pip's
RECORD. The test also uses the existing fixture that keeps coverage out
of pip's subprocesses.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Complete the cache creation fix from pypa#3642.
Preserve Tcl and Tk paths across UTF-7 Xonsh activation.
EnvBuilder writes activation scripts before virtualenv applies the selected
activators. A fresh environment could therefore retain an unselected script
that sources destination path text as shell code. Remove the stdlib scripts
before writing virtualenv's selected scripts.
An interrupt could let session cleanup remove temporary app-data while a
seed worker still used it. Wait for active lookups and installations before
propagating the interrupt so cleanup runs after they finish.

Fixes pypa#3636
Delayed expansion in cmd.exe changed literal exclamation marks in saved PATH
entries. Read and restore those values according to the shell mode at each
activation step so entries round-trip if the mode changes.

Fixes pypa#3617
site.addsitedir executes environment .pth hooks before the old script moved
environment paths ahead of host paths. Put interpreter and environment paths
first while those hooks run, then retain their path additions after activation.

Fixes pypa#3623
CPython 3.14 searches upward from a copied libpython for its standard library.
A writable sibling library directory could redirect startup in a private
copy-mode environment. Check that search location before copying the library
and keep the copy needed by relative loader paths.
Without HOME or a passwd entry, platformdirs can leave the default home path
unresolved. Configuration and cache lookup then use paths under the invoking
tree. Skip the default configuration and use temporary app-data when no
absolute default cache path exists. An explicit path remains available.
A migrated default cache could expose group-writable wheel files through a
traversable root. Restrict the root before moving or copying its descendants.
Setgid caches retain group access while other accounts lose access.
Under a non-UTF-8 POSIX locale, seeded pip launchers could spell the
interpreter path with different bytes and fail to start. Use an ASCII shell
wrapper with octal escapes when the path's filesystem bytes differ from UTF-8;
keep direct shebangs otherwise.

Fixes pypa#3632
Xonsh can decode an activation script with UTF-7, which interprets
printable plus sequences before Python parses the generated values.
Represent affected characters by code point so the source decoder
cannot change a value into syntax.
A Xonsh session can bind chr or map before sourcing the script, which
would stop activation for values that need a code-point expression.
Resolve both through builtins. Keep ascii() for plain values so the
existing CodeQL quote rule still recognizes the safe branch.
The Tcl and Tk test assumed every generated value remained a literal.
Windows Unicode paths now use code point expressions. Execute the
rendered assignments and compare their resulting values.
@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
gaborbernat added a commit to gaborbernat/virtualenv that referenced this pull request Nov 20, 2026
Tcl library paths and Xonsh activation values could change when a script
was sourced under a different text or filesystem codec. Check recorded
Tcl bytes, emit encoding-independent Xonsh source, and refuse path text
that cannot round-trip through the active filesystem codec.

Refs pypa#3743
Refs pypa#3708
Refs pypa#3709
Refs pypa#3729
Refs pypa#3717
@gaborbernat
gaborbernat deleted the fix/y91-xonsh-utf7 branch November 23, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug security Fixes a vulnerability or hardens the supply chain, CI or release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants