Skip to content

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

Merged
gaborbernat merged 3 commits into
pypa:mainfrom
gaborbernat:fix/y91-xonsh-utf7
Nov 20, 2026
Merged

gaborbernat merged 3 commits into
pypa:mainfrom
gaborbernat:fix/y91-xonsh-utf7

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

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.

@gaborbernat gaborbernat added bug security Fixes a vulnerability or hardens the supply chain, CI or release labels Nov 20, 2026
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 marked this pull request as ready for review November 20, 2026 10:56
@gaborbernat
gaborbernat merged commit b3bc056 into pypa:main Nov 20, 2026
81 checks passed
@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