Fix store isolation and wallet policy enforcement (#7754)
What changed, and why it matters
This commit fixes several authorization and isolation bugs in BTCPay Server. The most important changes prevent a user from seeing other users' store apps, stop non-admins from creating cold wallets when the server policy forbids it, and prevent a malicious store's custom CSS from being loaded in the admin backend. It also fixes a few data-update bugs that could let a request change fields it shouldn't, and a cancellation-token leak.
Upgrade to the release containing this commit. Review API keys and logs for any GetAllApps access by non-admin users, and audit wallet creation events where non-admins created wallets. Verify server policies for hot/cold wallet creation are set as intended.
Security signals we found
Authorization bypass: GetAllApps returned apps across all stores the user owns instead of only authorized stores
Policy enforcement gap: cold-wallet creation by non-admins was not blocked even when server policy disallowed it
Cross-store data access: Crowdfund/PointOfSale update views used Model.StoreId from user input to look up forms
Mass-assignment-like risk: DbSet.Update marks all entity properties modified, potentially persisting attacker-controlled fields
Stored XSS / UI redressing vector: custom store CSS URL could be loaded in the admin backend
Resource leak / DoS: cancellation token not checked after WaitAny in UILNURLController
Evidence from the diff
The patch addresses multiple security-relevant issues: (1) GetAllApps in GreenfieldAppsController now filters apps to only those in stores the caller can access, closing a horizontal privilege-escalation/information-disclosure path. (2) Wallet generation now enforces the cold-wallet policy for non-admins, not just hot-wallet policy. (3) Crowdfund and Point-of-Sale update views now use the resolved store ID from the app rather than a user-supplied model value, preventing cross-store form-data lookups. (4) AppService and PaymentRequestRepository switch from DbSet.Update (which marks every property modified) to setting EntityState.Modified, reducing the risk of unintended field overwrites. (5) LayoutHead.cshtml strips CssUrl from backend branding to block custom store CSS from the admin backend. (6) UILNURLController now checks cancellationToken.ThrowIfCancellationRequested after a delay/event wait. Swagger docs are updated to reflect the new permission requirements.
Changed components
GreenfieldAppsController.GetAllAppsGreenfieldStoreOnChainPaymentMethodsController.GenerateOnChainWalletUICrowdfundController.UpdateCrowdfund / UpdateCrowdfund.cshtmlUIPointOfSaleController.UpdatePointOfSale / UpdatePointOfSale.cshtmlAppService.UpdateOrCreateAppPaymentRequestRepository.CreateOrUpdatePaymentRequestLayoutHead.cshtml backend brandingUILNURLController.WaitPayoutChangedInspect captured patch +21 / −10
### BTCPayServer.Tests/GreenfieldAPITests.cs
@@ -2863,7 +2863,7 @@ public async Task OnChainPaymentMethodAPITests()
await user.GrantAccessAsync(true);
await user2.GrantAccessAsync(false);
- var client = await user.CreateClient(Policies.CanModifyStoreSettings);
+ var client = await user.CreateClient(Policies.CanModifyStoreSettings, Policies.CanModifyServerSettings);
var client2 = await user2.CreateClient(Policies.CanModifyStoreSettings);
var viewOnlyClient = await user.CreateClient(Policies.CanViewStoreSettings);
var walletViewerClient = await user.CreateClient(WalletPolicies.CanViewWallet);
### BTCPayServer/Controllers/GreenField/GreenfieldAppsController.cs
@@ -161,9 +161,10 @@ public async Task<IActionResult> UpdatePointOfSaleApp(string appId, PointOfSaleA
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public async Task<IActionResult> GetAllApps()
{
+ var storeIds = HttpContext.GetStoresData().Select(s => s.Id).ToHashSet();
var apps = await _appService.GetAllApps(User.GetId(), includeArchived: true);
- return Ok(apps.Select(ToModel).ToArray());
+ return Ok(apps.Where(a => storeIds.Contains(a.StoreId)).Select(ToModel).ToArray());
}
[HttpGet("~/api/v1/stores/{storeId}/apps")]
### BTCPayServer/Controllers/UILNURLController.cs
@@ -257,6 +257,7 @@ private async Task WaitPayoutChanged(string payoutId, CancellationToken cancella
var payoutEvent = _eventAggregator.WaitNext<PayoutEvent>(o => o.Payout.Id == payoutId, cts.Token);
await Task.WhenAny(delay, payoutEvent);
cts.Cancel();
+ cancellationToken.ThrowIfCancellationRequested();
}
private BTCPayNetwork GetNetwork(string cryptoCode)
### BTCPayServer/Plugins/Crowdfund/Controllers/UICrowdfundController.cs
@@ -421,6 +421,7 @@ public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundVi
return NotFound();
vm.AppId = app.Id;
+ vm.StoreId = app.StoreDataId;
vm.TargetCurrency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.TargetCurrency);
if (currencies.GetCurrencyData(vm.TargetCurrency, false) == null)
ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
### BTCPayServer/Plugins/Crowdfund/Views/UpdateCrowdfund.cshtml
@@ -12,7 +12,7 @@
ViewData.SetLayoutModel(new LayoutModel($"{nameof(CrowdfundPlugin)}-{Model.AppId}", StringLocalizer["Update Crowdfund"]));
Csp.UnsafeEval();
var canUpload = await FileService.IsAvailable();
- var checkoutFormOptions = await FormDataService.GetSelect(Model.StoreId, Model.FormId);
+ var checkoutFormOptions = await FormDataService.GetSelect(Context.GetStoreData().Id, Model.FormId);
}
@section PageHeadContent {
### BTCPayServer/Plugins/PointOfSale/Controllers/UIPointOfSaleController.cs
@@ -697,6 +697,7 @@ public async Task<IActionResult> UpdatePointOfSale(string appId, UpdatePointOfSa
return NotFound();
vm.Id = app.Id;
+ vm.StoreId = app.StoreDataId;
if (!ModelState.IsValid)
return View("/Plugins/PointOfSale/Views/UpdatePointOfSale.cshtml", vm);
### BTCPayServer/Plugins/PointOfSale/Views/UpdatePointOfSale.cshtml
@@ -8,7 +8,7 @@
Layout = "_Layout";
ViewData.SetLayoutModel(new($"{nameof(PointOfSalePlugin)}-{Model.Id}",StringLocalizer["Update Point of Sale"]));
Csp.UnsafeEval();
- var checkoutFormOptions = await FormDataService.GetSelect(Model.StoreId, Model.FormId);
+ var checkoutFormOptions = await FormDataService.GetSelect(Context.GetStoreData().Id, Model.FormId);
var baseUrl = this.Context.Request.GetRequestBaseUrl().ToString();
}
### BTCPayServer/Plugins/Wallets/Controllers/GreenfieldStoreOnChainPaymentMethodsController.WalletGeneration.cs
@@ -48,6 +48,11 @@ public async Task<IActionResult> GenerateOnChainWallet(string storeId,
ModelState.AddModelError(nameof(request.SavePrivateKeys),
"This instance forbids non-admins from having a hot wallet for your store.");
}
+ if (!request.SavePrivateKeys && !canUseHotWallet.CanCreateColdWallet)
+ {
+ ModelState.AddModelError(nameof(request.SavePrivateKeys),
+ "This instance forbids non-admins from creating a cold wallet for your store.");
+ }
if (!ModelState.IsValid)
{
### BTCPayServer/Services/Apps/AppService.cs
@@ -462,7 +462,7 @@ public async Task UpdateOrCreateApp(AppData app, bool sendEvents)
}
else
{
- ctx.Apps.Update(app);
+ ctx.Entry(app).State = EntityState.Modified;
ctx.Entry(app).Property(data => data.Created).IsModified = false;
ctx.Entry(app).Property(data => data.Id).IsModified = false;
ctx.Entry(app).Property(data => data.AppType).IsModified = false;
### BTCPayServer/Services/PaymentRequests/PaymentRequestRepository.cs
@@ -48,7 +48,7 @@ public async Task<PaymentRequestData> CreateOrUpdatePaymentRequest(PaymentReques
}
else
{
- context.PaymentRequests.Update(entity);
+ context.Entry(entity).State = EntityState.Modified;
}
await context.SaveChangesAsync();
### BTCPayServer/Views/Shared/LayoutHead.cshtml
@@ -10,7 +10,9 @@
var isBackend = store != null && storeBranding == null;
if (isBackend && storeBlob.ApplyBrandColorToBackend)
{
- storeBranding = await StoreBrandingViewModel.CreateAsync(Context.Request, UriResolver, storeBlob);
+ var backendBranding = await StoreBrandingViewModel.CreateAsync(Context.Request, UriResolver, storeBlob);
+ backendBranding.CssUrl = null;
+ storeBranding = backendBranding;
}
}
<meta charset="utf-8" />
### BTCPayServer/wwwroot/swagger/v1/swagger.template.apps.json
@@ -617,8 +617,8 @@
"Apps"
],
"operationId": "Apps_GetAllApps",
- "summary": "Get basic app data for all apps for all stores for a user",
- "description": "Returns basic app data for all apps for all stores",
+ "summary": "Get basic app data for all authorized stores",
+ "description": "Returns basic app data for apps in stores where the caller has the `btcpay.store.canmodifystoresettings` permission. Store-scoped API keys only return apps from their authorized stores.",
"responses": {
"200": {
"description": "Array of basic app data object",
### BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json
@@ -630,7 +630,7 @@
"$ref": "#/components/parameters/PaymentMethodId"
}
],
- "description": "Generate a wallet and update the specified store's payment method to it",
+ "description": "Generate a wallet and update the specified store's payment method to it. Unless the server policies allow non-admins to create hot wallets (`savePrivateKeys` is `true`) or cold wallets (`savePrivateKeys` is `false`), this requires the `btcpay.server.canmodifyserversettings` permission.",
"requestBody": {
"x-name": "request",
"content": {Why this scored 65/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.