Fix concurrent authorization checks on cheat permissions page (#7844)
What changed, and why it matters
This commit fixes a concurrency bug in a developer-only 'cheat permissions' page. The page was running many permission checks in parallel, but the underlying authorization system writes to shared data (HttpContext.Items) that is not safe for concurrent access. The fix makes the checks run one after another instead. This is a defensive fix for a non-production diagnostic page; there is no direct evidence it was exploitable as a security vulnerability.
Treat as a hardening/defensive fix. Review whether any other controllers parallelize authorizationService.AuthorizeAsync calls against the same HttpContext. No urgent security response is indicated by the diff alone.
Security signals we found
Concurrency/thread-safety fix
Shared mutable state (HttpContext.Items) accessed from parallel tasks
Authorization logic changed
Diagnostic/administrative page affected
Evidence from the diff
The change converts parallel authorization calls using Task.WhenAll into sequential awaited calls. The commit message and added comment state that authorization handlers update HttpContext.Items, which is not thread-safe. The affected page (CheatPermissions) appears to be a diagnostic/debug view for listing effective permissions. The patch removes the concurrent execution and stores completed results directly rather than unwrapping tasks later.
Changed components
BTCPayServer/Controllers/UIAccountController.csCheatPermissions actionInspect captured patch +5 / −5
### BTCPayServer/Controllers/UIAccountController.cs
@@ -81,16 +81,16 @@ public async Task<IActionResult> CheatPermissions([FromServices] IAuthorizationS
{
var vm = new CheatPermissionsViewModel();
vm.StoreId = storeId;
- var results = new System.Collections.Generic.List<(string, Task<AuthorizationResult>)>();
+ var results = new List<(string, AuthorizationResult)>();
+ // Authorization handlers update HttpContext.Items, which is not thread-safe.
foreach (var p in permissionService.Definitions.Values)
{
- results.Add((p.Policy, authorizationService.AuthorizeAsync(User, storeId, new PolicyRequirement(p.Policy))));
- results.Add((p.Policy + ":", authorizationService.AuthorizeAsync(User, storeId, new PolicyRequirement(p.Policy, requireUnscoped: true))));
+ results.Add((p.Policy, await authorizationService.AuthorizeAsync(User, storeId, new PolicyRequirement(p.Policy))));
+ results.Add((p.Policy + ":", await authorizationService.AuthorizeAsync(User, storeId, new PolicyRequirement(p.Policy, requireUnscoped: true))));
}
- await Task.WhenAll(results.Select(r => r.Item2));
results = results.OrderBy(r => r.Item1).ToList();
- vm.Permissions = results.Select(r => (r.Item1, r.Item2.Result)).ToArray();
+ vm.Permissions = results.ToArray();
return View(vm);
}
Why this scored 35/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.