Skip to content

Define script variables ahead of the script body - #52613

Draft
cdcme wants to merge 6 commits into
mainfrom
fix-script-variable-interpreter-escaping
Draft

Define script variables ahead of the script body#52613
cdcme wants to merge 6 commits into
mainfrom
fix-script-variable-interpreter-escaping

Conversation

@cdcme

@cdcme cdcme commented Sep 4, 2026

Copy link
Copy Markdown
Member

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 $VAR expansion, 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.
  • In Python, variables work inside string literals, but not inside raw (r"...") or bytes (b"...") literals.
  • Values are no longer re-expanded by the interpreter. A value of $HOME prints $HOME.

Checklist for submitter

  • Changes file added for user-visible changes in changes/.
  • Untrusted data interpolated into scripts is validated against interpreter metacharacters.

Testing

Unit tests cover each escaper and the preamble placement rules. Exec tests run generated scripts through /bin/sh, bash, zsh, and python3 and 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 .py script-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.

@cdcme
cdcme force-pushed the fix-script-variable-interpreter-escaping branch from ddfbdfd to 1623971 Compare September 4, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant