Define script variables ahead of the script body - #52613
Draft
cdcme wants to merge 6 commits into
Draft
Conversation
cdcme
force-pushed
the
fix-script-variable-interpreter-escaping
branch
from
September 4, 2026 20:57
ddfbdfd to
1623971
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changing
Resolved
$FLEET_VAR_*values were interpolated into script contents without being escaped for the target interpreter, so characters that are meaningful to it weren't treated as literal text.Values are now delivered so the interpreter reads them as data. Shell and PowerShell get them defined ahead of the script body, with the
$FLEET_VAR_*token left in place. Python has no$VARexpansion, so its values are substituted in escaped form.No agent changes, so this works on hosts running today's fleetd.
Behavior changes
$FLEET_VAR_*inside single quotes or a quoted heredoc is no longer substituted and stays a literal token. Same for PowerShell'...'and here-strings.r"...") or bytes (b"...") literals.$HOMEprints$HOME.Checklist for submitter
changes/.Testing
Unit tests cover each escaper and the preamble placement rules. Exec tests run generated scripts through
/bin/sh,bash,zsh, andpython3and assert values round-trip byte-for-byte, including under a non-UTF-8 locale.Manual pass against a live server, 17/17 checks across shell, PowerShell, Python, and a
.pyscript-only package.Gaps: PowerShell was checked on 7.4 in Docker, not Windows PowerShell 5.1, so a real Windows pass is still needed. ConstrainedLanguage was simulated with
LanguageMode, not enforced by WDAC.