Merge pull request #7750 from btcpayserver/fix/vue-stored-template-xss
What changed, and why it matters
This merge commit appears to fix a stored cross-site scripting (XSS) issue in BTCPay Server's Vue.js templates. The changes prevent user-controlled text (wallet labels, form configuration JSON, and validation output) from being processed by Vue, which could otherwise allow an attacker to inject malicious JavaScript that runs in another user's browser. The patch uses the `v-pre` directive to tell Vue to skip certain HTML elements, and moves form configuration data out of a Vue-bound textarea into a plain JavaScript variable.
Review all remaining Razor/Vue views for similar patterns where user-controlled or stored text is placed inside Vue templates without `v-pre` or proper escaping. Audit the `Safe.Json` serializer to confirm it escapes forward slashes and HTML-special characters appropriately for JavaScript context. Consider adding automated tests or a lint rule that flags unescaped user content inside Vue templates.
Security signals we found
Branch name explicitly references 'vue-stored-template-xss'
Use of `v-pre` to prevent Vue compilation of user-controlled content
Migration of JSON config from Vue-bound textarea to a plain JS variable serialized with `Safe.Json`
Stored XSS context: labels and form config are persisted server-side and rendered to other users
Partial patch: only four files changed; other Vue templates may remain unreviewed
Evidence from the diff
The commit addresses stored template XSS in Vue.js views. In Default.cshtml and ReservedAddresses.cshtml, v-pre is added to elements rendering user-influenced label text so Vue does not compile them as templates. In Modify.cshtml, the form configuration JSON is moved from a v-model textarea into a separate initialConfig JavaScript variable via Safe.Json, and the validation span is marked v-pre. The companion form-editor.js now reads from initialConfig instead of the textarea value. This reduces the attack surface where attacker-controlled strings could be interpreted as Vue template expressions or directives.
Changed components
BTCPayServer/Components/WalletNav/Default.cshtmlBTCPayServer/Plugins/Forms/Views/Modify.cshtmlBTCPayServer/Plugins/Wallets/Views/UIWallets/ReservedAddresses.cshtmlBTCPayServer/wwwroot/js/form-editor.jsInspect captured patch +8 / −6
### BTCPayServer/Components/WalletNav/Default.cshtml
@@ -2,7 +2,7 @@
@inject DisplayFormatter DisplayFormatter
@model BTCPayServer.Components.WalletNav.WalletNavViewModel
-<a asp-area="Wallets" asp-controller="UIWallets" asp-action="WalletTransactions" asp-route-walletId="@Model.WalletId" class="unobtrusive-link">
+<a asp-area="Wallets" asp-controller="UIWallets" asp-action="WalletTransactions" asp-route-walletId="@Model.WalletId" class="unobtrusive-link" v-pre>
<h2 class="my-1">@Model.Label</h2>
<div class="text-muted fw-semibold" data-sensitive>
@DisplayFormatter.Currency(Model.Balance, Model.Network.CryptoCode)
### BTCPayServer/Plugins/Forms/Views/Modify.cshtml
@@ -193,6 +193,9 @@
<script src="~/vendor/vue-sanitize-directive/vue-sanitize-directive.umd.min.js" asp-append-version="true"></script>
<script src="~/vendor/vue-sortable/sortable.min.js" asp-append-version="true"></script>
<script src="~/vendor/vue-sortable/vue-sortable.js" asp-append-version="true"></script>
+ <script>
+ var initialConfig = @Safe.Json(Model.FormConfig);
+ </script>
<script src="~/js/form-editor.js" asp-append-version="true"></script>
<partial name="_ValidationScriptsPartial" />
}
@@ -275,8 +278,8 @@
</div>
<div class="tab-pane fade" id="CodeTabPane" role="tabpanel" aria-labelledby="CodeTabButton" tabindex="0">
<label asp-for="FormConfig" class="form-label" data-required text-translate="true">Form JSON</label>
- <textarea asp-for="FormConfig" class="form-control font-monospace" style="font-size:.85rem" rows="21" cols="21" v-model="configJSON" v-on:change="updateFromJSON"></textarea>
- <span asp-validation-for="FormConfig" class="text-danger"></span>
+ <textarea id="FormConfig" name="FormConfig" class="form-control font-monospace" style="font-size:.85rem" rows="21" cols="21" v-model="configJSON" v-on:change="updateFromJSON"></textarea>
+ <span asp-validation-for="FormConfig" class="text-danger" v-pre></span>
</div>
</div>
</div>
### BTCPayServer/Plugins/Wallets/Views/UIWallets/ReservedAddresses.cshtml
@@ -52,7 +52,7 @@
<span class="d-flex flex-wrap gap-2 align-items-center" not-permission="@WalletPolicies.CanManageWalletTransactions">
@foreach (var label in address.Labels)
{
- <span class="transaction-label" style="--label-bg:@label.Color;--label-fg:@label.TextColor">
+ <span class="transaction-label" style="--label-bg:@label.Color;--label-fg:@label.TextColor" v-pre>
<span>@label.Text</span>
@if (!string.IsNullOrEmpty(label.Link))
{
### BTCPayServer/wwwroot/js/form-editor.js
@@ -6,8 +6,7 @@ document.addEventListener('DOMContentLoaded', () => {
console.error('Error deserializing form config:', err)
}
}
- const $config = document.getElementById('FormConfig')
- let config = parseConfig($config.value) || {}
+ let config = parseConfig(initialConfig) || {}
const specialFieldTypeOptions = ['fieldset', 'textarea', 'select', 'mirror']
const inputFieldTypeOptions = ['text', 'number', 'password', 'email', 'url', 'tel', 'date', 'datetime-local', 'color', 'checkbox', 'hidden']Why this scored 75/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.