Variables.ps1 serializer does not escape quotes in variable values — corrupts the config file

A fix for this issue has been implemented in version 2026.2.3

Variables.ps1 serializer does not escape quotes in variable values — corrupts the config file

avatar


variables.ps1 serializer does not escape quotes in variable values — corrupts the config file

**Version:** Reproduced on 2026.2.2 and 2026.1.6 (Windows, IIS-hosted and self-hosted)

**Summary**
Creating a plain (non-vault) variable whose value contains a quote character serializes an unescaped value into `.universal\variables.ps1`, making the file syntactically invalid. PowerShell Universal keeps serving variables from the database, so nothing visibly breaks — until the next configuration reload or service restart, when the file fails to parse ("Invalid configuration: ...variables.ps1") and variables fail to load.

**Steps to reproduce**
1. Create a variable via the Admin UI or REST API:
- Name: `QuoteTest`
- Value: `conn"str'test;pwd=fake"x` (any value containing a single quote reproduces it)
2. Open `.universal\variables.ps1`.

**Actual result**
The serialized line is written with the embedded quote unescaped:

New-PSUVariable -Name "QuoteTest" -Value 'conn"str'test;pwd=fake"x'



The embedded `'` is not doubled, so the string terminates early and the file no longer parses (`TerminatorExpectedAtEndOfString`). Verify with:

$errs = $null
[System.Management.Automation.Language.Parser]::ParseInput(
    (Get-Content -Raw .\.universal\variables.ps1), [ref]$null, [ref]$errs) | Out-Null
$errs


**Expected result**
Values are escaped for single-quoted PowerShell literals (`'` doubled to `''`), keeping `variables.ps1` valid for any value.

**Impact / why this is nasty**
- The corruption is **silent**: runtime serves variables from the DB, so the broken file sits armed until a restart or config sync, then every variable in the file is at risk of failing to load at once.
- One bad value poisons quote-pairing for **every subsequent line**, so the parse errors point at unrelated variables many lines below the actual culprit, which makes diagnosis genuinely difficult.
- Realistic trigger: pasting a SQL connection string whose password contains a quote — which is exactly how we hit it in production.

**Workaround**
Store quote-bearing values as vault-backed secrets (no value is serialized into variables.ps1), or hand-repair the file line with proper `''` escaping.

All Comments (3)

avatar

@bkeck Thanks for the report. I've opened an issue in our backlog and we'll make sure to get this addressed in an upcoming version. I also appreciate you providing some workarounds for others that may run into this.

Adam Driscoll
PowerShell Expert and Developer at Devolutions

avatar

Hello,

Thank you for being so patient.

The fix has been implemented in the latest PowerShell Universal 2026.2.3.0 version.

Let us know if that works as expected.

Thank you for your collaboration.

Best regards,

Érica Poirier

avatar

Outstand work!

I can confirm — retested the original repro (conn"str'test;pwd=fake"x via the REST API) on 2026.2.3 and the embedded quote is now correctly doubled in variables.ps1, the file parses cleanly, and the value round-trips exactly. Thanks for the fix!

A fix for this issue has been implemented in version 2026.2.3