Skip to content

Commit 57a9888

Browse files
Copilotstephentoub
andauthored
Fix IPv6 loopback detection and avoid exposing internal test type publicly
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/8a200407-8cc6-4c69-97e0-c9a6ad509b93 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 20e4dec commit 57a9888

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ private async Task PerformDynamicClientRegistrationAsync(
718718
private static bool IsLocalhostRedirectUri(Uri redirectUri)
719719
=> redirectUri.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)
720720
|| redirectUri.Host.Equals("127.0.0.1", StringComparison.Ordinal)
721-
|| redirectUri.Host.Equals("[::1]", StringComparison.Ordinal);
721+
|| redirectUri.Host.Equals("::1", StringComparison.Ordinal);
722722

723723
private string? GetScopeParameter(ProtectedResourceMetadata protectedResourceMetadata)
724724
{

tests/ModelContextProtocol.AspNetCore.Tests/OAuth/AuthTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ public async Task DynamicClientRegistration_SendsNativeApplicationType_ForLocalh
12841284
await using var client = await McpClient.CreateAsync(
12851285
transport, loggerFactory: LoggerFactory, cancellationToken: TestContext.Current.CancellationToken);
12861286

1287-
Assert.Equal("native", TestOAuthServer.LastRegistrationRequest?.ApplicationType);
1287+
Assert.Equal("native", TestOAuthServer.LastRegistrationApplicationType);
12881288
}
12891289

12901290
[Fact]
@@ -1309,7 +1309,7 @@ public async Task DynamicClientRegistration_SendsWebApplicationType_ForNonLocalh
13091309
await using var client = await McpClient.CreateAsync(
13101310
transport, loggerFactory: LoggerFactory, cancellationToken: TestContext.Current.CancellationToken);
13111311

1312-
Assert.Equal("web", TestOAuthServer.LastRegistrationRequest?.ApplicationType);
1312+
Assert.Equal("web", TestOAuthServer.LastRegistrationApplicationType);
13131313
}
13141314

13151315
[Fact]
@@ -1337,6 +1337,6 @@ public async Task DynamicClientRegistration_UsesExplicitApplicationType_WhenConf
13371337
await using var client = await McpClient.CreateAsync(
13381338
transport, loggerFactory: LoggerFactory, cancellationToken: TestContext.Current.CancellationToken);
13391339

1340-
Assert.Equal("web", TestOAuthServer.LastRegistrationRequest?.ApplicationType);
1340+
Assert.Equal("web", TestOAuthServer.LastRegistrationApplicationType);
13411341
}
13421342
}

tests/ModelContextProtocol.TestOAuthServer/ClientRegistrationRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ModelContextProtocol.TestOAuthServer;
55
/// <summary>
66
/// Represents a client registration request as defined in RFC 7591.
77
/// </summary>
8-
public sealed class ClientRegistrationRequest
8+
internal sealed class ClientRegistrationRequest
99
{
1010
/// <summary>
1111
/// Gets or sets the redirect URIs for the client.

tests/ModelContextProtocol.TestOAuthServer/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public Program(ILoggerProvider? loggerProvider = null, IConnectionListenerFactor
8282
public IReadOnlyCollection<string> MetadataRequests => _metadataRequests.ToArray();
8383

8484
/// <summary>
85-
/// Gets the most recent dynamic client registration request received by the server.
85+
/// Gets the application type from the most recent dynamic client registration request received by the server.
8686
/// </summary>
87-
public ClientRegistrationRequest? LastRegistrationRequest { get; private set; }
87+
public string? LastRegistrationApplicationType { get; private set; }
8888

8989
/// <summary>
9090
/// Entry point for the application.
@@ -506,7 +506,7 @@ IResult HandleMetadataRequest(HttpContext context, string? issuerPath = null)
506506
});
507507
}
508508

509-
LastRegistrationRequest = registrationRequest;
509+
LastRegistrationApplicationType = registrationRequest.ApplicationType;
510510

511511
// Validate redirect URIs are provided
512512
if (registrationRequest.RedirectUris.Count == 0)

0 commit comments

Comments
 (0)