Skip to content

Commit 407e7a2

Browse files
authored
Fix rare concurrency issue in back-office auth middleware (#19418)
1 parent 50172ce commit 407e7a2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Umbraco.Cms.Api.Management/Middleware/BackOfficeAuthorizationInitializationMiddleware.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ private async Task InitializeBackOfficeAuthorizationOnceAsync(HttpContext contex
6565
return;
6666
}
6767

68-
if (_knownHosts.Add($"{context.Request.Scheme}://{context.Request.Host}") is false)
68+
var host = $"{context.Request.Scheme}://{context.Request.Host}";
69+
if (_knownHosts.Contains(host))
6970
{
7071
return;
7172
}
7273

7374
await _firstBackOfficeRequestLocker.WaitAsync();
7475

76+
// NOTE: _knownHosts is not thread safe; check again after entering the semaphore
77+
if (_knownHosts.Add(host) is false)
78+
{
79+
_firstBackOfficeRequestLocker.Release();
80+
return;
81+
}
82+
7583
// ensure we explicitly add UmbracoApplicationUrl if configured (https://github.com/umbraco/Umbraco-CMS/issues/16179)
7684
if (_webRoutingSettings.UmbracoApplicationUrl.IsNullOrWhiteSpace() is false)
7785
{

0 commit comments

Comments
 (0)