Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3acfb49
Merged PR 61360: [internal/release/9.0] Update dependencies from dnce…
May 21, 2026
8d6e3b0
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 1, 2026
c83aa73
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 2, 2026
fe4c192
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 3, 2026
31d78d9
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 3, 2026
c1abf67
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 4, 2026
6bbd6cb
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 5, 2026
893da80
Merge from public
wtgodbe Jun 5, 2026
0feddce
Merged PR 61864: [release/9.0] Merge from public
wtgodbe Jun 5, 2026
57afd3f
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 6, 2026
8ce87ae
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 8, 2026
6707704
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 10, 2026
36f95de
Merged PR 61978: [release/9.0] Update to IdentityModel 8.19.2
wtgodbe Jun 10, 2026
af0f47f
Merged PR 61210: [release/9.0] Fix LdapAdapter query validation
DeagleGross Jun 11, 2026
914ddd6
Merge from public
wtgodbe Jun 11, 2026
4983220
Merged PR 62061: [release/9.0] Merge from public
wtgodbe Jun 11, 2026
5471f84
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 11, 2026
a3fa3b8
Merge commit 'dda719a4f6d24439ffdfb958f44270e5a1d50288'
Jun 11, 2026
aac80bd
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 12, 2026
6679cca
Merge commit '3454906f02e5432c0404c0e4d49936da1cac23dd'
Jun 15, 2026
e6052a8
Merged PR 61942: Html Encode incoming parameters to debug page
Jun 15, 2026
f379999
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 16, 2026
a83a813
Merge commit '7707bd2a075a74e45ec501daf71fc445d6347605'
Jun 16, 2026
491a976
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 16, 2026
f8834c1
Merged PR 61636: [internal/release/9.0] Update dependencies from dnce…
Jun 16, 2026
fe25243
Update dependencies from https://dev.azure.com/dnceng/internal/_git/d…
dotnet-bot Jun 17, 2026
c2c4206
Merged PR 62186: [internal/release/9.0] Update dependencies from dnce…
Jun 17, 2026
b8520b5
Merged PR 62260: Fix source-build poison leak from dotnet-user-jwts r…
Jun 19, 2026
a95d659
Merge commit '32779ae50595b2d073f348e49d668d3dcd2b4072'
Jun 23, 2026
b131c1c
Merge commit 'a95d6599f37762ec8394ba9ca01e8263b2e36a26' into internal…
dotnet-bot Jul 14, 2026
31f198c
Update SDK and dotnet version to 9.0.119
wtgodbe Jul 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<!-- Begin: Package sources from dotnet-extensions -->
<!-- End: Package sources from dotnet-extensions -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-d839c41" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-runtime-d839c41c/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-runtime -->
<!-- Begin: Package sources from dotnet-efcore -->
<add key="darc-int-dotnet-efcore-0d9843b" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-efcore-0d9843b8/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-efcore -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
Expand All @@ -30,8 +32,10 @@
<clear />
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from dotnet-efcore -->
<add key="darc-int-dotnet-efcore-0d9843b" value="true" />
<!-- End: Package sources from dotnet-efcore -->
<!-- Begin: Package sources from dotnet-runtime -->
<add key="darc-int-dotnet-runtime-d839c41" value="true" />
<!-- End: Package sources from dotnet-runtime -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
</disabledPackageSources>
Expand Down
326 changes: 163 additions & 163 deletions eng/Version.Details.xml

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions eng/Versions.props

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "9.0.118"
"version": "9.0.119"
},
"tools": {
"dotnet": "9.0.118",
"dotnet": "9.0.119",
"runtimes": {
"dotnet/x86": [
"$(MicrosoftNETCoreBrowserDebugHostTransportVersion)"
Expand Down
13 changes: 8 additions & 5 deletions src/Components/WebAssembly/Server/src/TargetPickerUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ public async Task Display(HttpContext context)
var debuggerTabsListUrl = $"{_browserHost}/json";
IEnumerable<BrowserTab> availableTabs;

var targetApplicationUrlEncoded = WebUtility.HtmlEncode(targetApplicationUrl.ToString());
var debuggerTabsListUrlEncoded = WebUtility.HtmlEncode(debuggerTabsListUrl);

try
{
availableTabs = await GetOpenedBrowserTabs();
Expand All @@ -280,17 +283,17 @@ public async Task Display(HttpContext context)
await context.Response.WriteAsync($@"
<h1>Unable to find debuggable browser tab</h1>
<p>
Could not get a list of browser tabs from <code>{debuggerTabsListUrl}</code>.
Could not get a list of browser tabs from <code>{debuggerTabsListUrlEncoded}</code>.
Ensure your browser is running with debugging enabled.
</p>
<h2>Resolution</h2>
<p>
<h4>If you are using Google Chrome or Chromium for your development, follow these instructions:</h4>
{GetLaunchChromeInstructions(targetApplicationUrl.ToString())}
{GetLaunchChromeInstructions(targetApplicationUrlEncoded)}
</p>
<p>
<h4>If you are using Microsoft Edge (80+) for your development, follow these instructions:</h4>
{GetLaunchEdgeInstructions(targetApplicationUrl.ToString())}
{GetLaunchEdgeInstructions(targetApplicationUrlEncoded)}
</p>
<strong>This should launch a new browser window with debugging enabled..</p>
<h2>Underlying exception:</h2>
Expand All @@ -316,8 +319,8 @@ Ensure your browser is running with debugging enabled.

var suffix = string.IsNullOrEmpty(targetApplicationUrl)
? string.Empty
: $" matching the URL {WebUtility.HtmlEncode(targetApplicationUrl)}";
await context.Response.WriteAsync($"<p>The list of targets returned by {WebUtility.HtmlEncode(debuggerTabsListUrl)} contains no entries{suffix}.</p>");
: $" matching the URL {targetApplicationUrlEncoded}";
await context.Response.WriteAsync($"<p>The list of targets returned by {debuggerTabsListUrlEncoded} contains no entries{suffix}.</p>");
await context.Response.WriteAsync("<p>Make sure your browser is displaying the target application.</p>");
}
else
Expand Down
95 changes: 81 additions & 14 deletions src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,32 @@ public static async Task RetrieveClaimsAsync(LdapSettings settings, ClaimsIdenti
{
var user = identity.Name!;
var userAccountNameIndex = user.IndexOf('@');
var userAccountName = userAccountNameIndex == -1 ? user : user.Substring(0, userAccountNameIndex);

// Without a realm in the name (no '@'), we cannot tell which directory the principal came from.
// The local part alone is not a safe LDAP lookup key — sAMAccountName is unique only within a single domain,
// so any same-named account in the configured domain would be returned.
if (userAccountNameIndex == -1)
{
logger.LogDebug(
"Skipping LDAP claim resolution for '{User}': its realm cannot be verified against the configured LDAP domain '{Domain}'.",
user, settings.Domain);

return;
}

// With a realm that doesn't match settings.Domain the principal authenticated through a foreign Kerberos realm
// should NOT be trusted by the application's realm.
var realm = user.AsSpan(userAccountNameIndex + 1);
if (!realm.Equals(settings.Domain.AsSpan(), StringComparison.OrdinalIgnoreCase))
{
logger.LogDebug(
"Skipping LDAP claim resolution for '{User}': principal realm does not match the configured LDAP domain '{Domain}'. Cross-domain claim resolution is not supported.",
user, settings.Domain);

return;
}

var userAccountName = user[..userAccountNameIndex];

if (settings.ClaimsCache == null)
{
Expand All @@ -41,7 +66,7 @@ public static async Task RetrieveClaimsAsync(LdapSettings settings, ClaimsIdenti
var distinguishedName = settings.Domain.Split('.').Select(name => $"dc={name}").Aggregate((a, b) => $"{a},{b}");
var retrievedClaims = new List<string>();

var filter = $"(&(objectClass=user)(sAMAccountName={userAccountName}))"; // This is using ldap search query language, it is looking on the server for someUser
var filter = $"(&(objectClass=user)(sAMAccountName={EscapeLdapFilterValue(userAccountName)}))"; // This is using ldap search query language, it is looking on the server for someUser
var searchRequest = new SearchRequest(distinguishedName, filter, SearchScope.Subtree);

Debug.Assert(settings.LdapConnection != null);
Expand Down Expand Up @@ -70,7 +95,7 @@ public static async Task RetrieveClaimsAsync(LdapSettings settings, ClaimsIdenti

if (!settings.IgnoreNestedGroups)
{
GetNestedGroups(settings.LdapConnection, identity, distinguishedName, groupCN, logger, retrievedClaims, new HashSet<string>());
GetNestedGroups(settings.LdapConnection, identity, distinguishedName, groupDN, groupCN, logger, retrievedClaims, new HashSet<string>());
}
else
{
Expand Down Expand Up @@ -98,23 +123,29 @@ public static async Task RetrieveClaimsAsync(LdapSettings settings, ClaimsIdenti
}
}

private static void GetNestedGroups(LdapConnection connection, ClaimsIdentity principal, string distinguishedName, string groupCN, ILogger logger, IList<string> retrievedClaims, HashSet<string> processedGroups)
private static void GetNestedGroups(LdapConnection connection, ClaimsIdentity principal, string distinguishedName, string groupDN, string groupCN, ILogger logger, IList<string> retrievedClaims, HashSet<string> processedGroups)
{
retrievedClaims.Add(groupCN);

var filter = $"(&(objectClass=group)(sAMAccountName={groupCN}))"; // This is using ldap search query language, it is looking on the server for someUser
var searchRequest = new SearchRequest(distinguishedName, filter, SearchScope.Subtree);
var searchResponse = (SearchResponse)connection.SendRequest(searchRequest);
// Look up the group entry by its distinguished name using base scope:
// a base-scope read against the DN is the only LDAP operation that
// returns exactly the intended group object.
var searchRequest = new SearchRequest(groupDN, "(objectClass=group)", SearchScope.Base);
SearchResponse searchResponse;
try
{
searchResponse = (SearchResponse)connection.SendRequest(searchRequest);
}
catch (DirectoryOperationException ex) when (ex.Response is SearchResponse r && r.ResultCode == ResultCode.NoSuchObject)
{
// Stale memberOf reference: group no longer exists. Stop traversal of this branch.
logger.LogDebug("Stale memberOf reference: group with distinguished name '{GroupDN}' no longer exists; stopping traversal.", groupDN);;
return;
}

if (searchResponse.Entries.Count > 0)
{
if (searchResponse.Entries.Count > 1 && logger.IsEnabled(LogLevel.Warning))
{
logger.LogWarning($"More than one response received for query: {filter} with distinguished name: {distinguishedName}");
}

var group = searchResponse.Entries[0]; // Get the object that was found on ldap
var groupDN = group.DistinguishedName;

processedGroups.Add(groupDN);

Expand All @@ -132,9 +163,45 @@ private static void GetNestedGroups(LdapConnection connection, ClaimsIdentity pr
return;
}

GetNestedGroups(connection, principal, distinguishedName, nestedGroupCN, logger, retrievedClaims, processedGroups);
GetNestedGroups(connection, principal, distinguishedName, nestedGroupDN, nestedGroupCN, logger, retrievedClaims, processedGroups);
}
}
}
}

/// <summary>
/// Escapes special characters in a value used in an LDAP search filter per RFC 4515
/// https://datatracker.ietf.org/doc/html/rfc4515#section-3
/// </summary>
// internal for testing
internal static string EscapeLdapFilterValue(string value)
{
var sb = new StringBuilder(value.Length);
foreach (var c in value)
{
switch (c)
{
case '\\':
sb.Append(@"\5c");
break;
case '*':
sb.Append(@"\2a");
break;
case '(':
sb.Append(@"\28");
break;
case ')':
sb.Append(@"\29");
break;
case '\0':
sb.Append(@"\00");
break;
default:
sb.Append(c);
break;
}
}

return sb.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Claims;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging.Abstractions;

namespace Microsoft.AspNetCore.Authentication.Negotiate.Test;

public class LdapAdapterTests
{
[Fact]
public async Task RetrieveClaimsAsync_ForeignRealm_SkipsLookupAndAddsNoClaims()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp"
};
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, "admin@foreign.corp")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

Assert.DoesNotContain(identity.Claims, c => c.Type == identity.RoleClaimType);
}

[Fact]
public async Task RetrieveClaimsAsync_ForeignRealm_DifferentCasing_SkipsLookup()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp",
};
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, "admin@FOREIGN.CORP")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

Assert.DoesNotContain(identity.Claims, c => c.Type == identity.RoleClaimType);
}

[Fact]
public async Task RetrieveClaimsAsync_BareUsernameNoRealm_SkipsLookup()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp",
};

// No '@' means we cannot verify which realm "admin" came from.
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, "admin")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

Assert.DoesNotContain(identity.Claims, c => c.Type == identity.RoleClaimType);
}

[Fact]
public async Task RetrieveClaimsAsync_DownLevelDomainUser_SkipsLookup()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp",
};
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, @"LOCAL\admin")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

Assert.DoesNotContain(identity.Claims, c => c.Type == identity.RoleClaimType);
}

[Fact]
public async Task RetrieveClaimsAsync_MatchingRealm_SameCasing_RetrievesCachedClaims()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp",
};
var roles = new[] { "Engineers", "Admins" };
var cache = new MemoryCache(new MemoryCacheOptions { SizeLimit = settings.ClaimsCacheSize });
cache.Set("alice@local.corp", (IEnumerable<string>)roles, new MemoryCacheEntryOptions().SetSize(64));
settings.ClaimsCache = cache;
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, "alice@local.corp")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

var roleClaims = identity.Claims
.Where(c => c.Type == identity.RoleClaimType)
.Select(c => c.Value)
.ToArray();
Assert.Equal(roles, roleClaims);
}

[Fact]
public async Task RetrieveClaimsAsync_MatchingRealm_DifferentCasing_RetrievesCachedClaims()
{
var settings = new LdapSettings
{
EnableLdapClaimResolution = true,
Domain = "local.corp",
};
var roles = new[] { "Engineers", "Admins" };
var cache = new MemoryCache(new MemoryCacheOptions { SizeLimit = settings.ClaimsCacheSize });
cache.Set("alice@LOCAL.CORP", (IEnumerable<string>)roles, new MemoryCacheEntryOptions().SetSize(64));
settings.ClaimsCache = cache;
var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, "alice@LOCAL.CORP")], "Negotiate");

await LdapAdapter.RetrieveClaimsAsync(settings, identity, NullLogger.Instance);

var roleClaims = identity.Claims
.Where(c => c.Type == identity.RoleClaimType)
.Select(c => c.Value)
.ToArray();
Assert.Equal(roles, roleClaims);
}

[Fact]
public void DistinguishedNameWithoutCommasSuccess()
{
Expand Down Expand Up @@ -36,4 +148,47 @@ public void DistinguishedNameWithEscapedBackslashAndNotEscapedCommaSuccess()

Assert.Equal(new[] { @"Testing group\\", "City" }, parts);
}

[Fact]
public void EscapeLdapFilterValue_PlainValue_ReturnsUnchanged()
{
Assert.Equal("JohnDoe", LdapAdapter.EscapeLdapFilterValue("JohnDoe"));
}

[Fact]
public void EscapeLdapFilterValue_Wildcard_IsEscaped()
{
Assert.Equal(@"\2a", LdapAdapter.EscapeLdapFilterValue("*"));
}

[Fact]
public void EscapeLdapFilterValue_Parentheses_AreEscaped()
{
Assert.Equal(@"John\28Dev\29", LdapAdapter.EscapeLdapFilterValue("John(Dev)"));
}

[Fact]
public void EscapeLdapFilterValue_Backslash_IsEscaped()
{
Assert.Equal(@"DOMAIN\5cUser", LdapAdapter.EscapeLdapFilterValue(@"DOMAIN\User"));
}

[Fact]
public void EscapeLdapFilterValue_NullChar_IsEscaped()
{
Assert.Equal(@"before\00after", LdapAdapter.EscapeLdapFilterValue("before\0after"));
}

[Fact]
public void EscapeLdapFilterValue_InjectionPayload_IsNeutralized()
{
var malicious = "x)(sAMAccountName=*";
Assert.Equal(@"x\29\28sAMAccountName=\2a", LdapAdapter.EscapeLdapFilterValue(malicious));
}

[Fact]
public void EscapeLdapFilterValue_EmptyString_ReturnsEmpty()
{
Assert.Equal(string.Empty, LdapAdapter.EscapeLdapFilterValue(string.Empty));
}
}
Loading
Loading