microsoft / microsoft/aspire

Service Discovery Erroneously Calling HTTP-Only Endpoints Using HTTPS Protocol

Open
#5,162 0 comments 1 reaction 0 assignees View on GitHub
area-service-discovery
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When a service is configured for service discovery with only an `http` config slice, then consumed with an `HttpClient` that specifies a URL starting with `https+http://...`, the client appears to try to connect to the HTTP-only service using HTTPS protocol, which then fails with the error:
```
System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.'
AuthenticationException: Cannot determine the frame size or a corrupted frame was received.
```
Since only `http` is provided in the config, SSL should not be in use, and certainly will not succeed.

### Expected Behavior

Since the only scheme provided in the config is `http`, and a request URL of `https+http://...` indicates a _preference_ for HTTPS but not a requirement, I would expect the request to be issued to the HTTP endpoint specified without the use of SSL/HTTPS, so that the request can succeed.

### Steps To Reproduce

https://github.com/jimnoble/ServiceDiscoverySchemeDefect

1. Create a simple HTTP-only service, e.g. the weather forecast asp.net template.
2. Create a console application to act as a client to the service. Arrange things like this:
```cs
var url = "https+http://myservice/weatherforecast";

var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary
{
["Services:myservice:http:0"] = $"localhost:5083" // your port here
})
.Build();

var serviceProvider = new ServiceCollection()
.AddSingleton(configuration)
.AddHttpClient()
.AddServiceDiscovery()
.ConfigureHttpClientDefaults(http =>
{
http.AddServiceDiscovery();
})
.BuildServiceProvider();

var httpClient = serviceProvider
.GetRequiredService()
.CreateClient();

var response = await httpClient.GetAsync(url);
```
Run both projects and have the client consume the service, whereupon it should produce the exception.

### Exceptions (if any)

System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception.'
AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

### .NET Version info

```
.NET SDK:
Version: 8.0.303
Commit: 29ab8e3268
Workload version: 8.0.300-manifests.34944930
MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.303\

.NET workloads installed:
[android]
Installation Source: VS 17.10.35027.167
Manifest Version: 34.0.95/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.95\WorkloadManifest.json
Install Type: FileBased

[maccatalyst]
Installation Source: VS 17.10.35027.167
Manifest Version: 17.2.8053/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8053\WorkloadManifest.json
Install Type: FileBased

[ios]
Installation Source: VS 17.10.35027.167
Manifest Version: 17.2.8053/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8053\WorkloadManifest.json
Install Type: FileBased

[maui-windows]
Installation Source: VS 17.10.35027.167
Manifest Version: 8.0.61/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.61\WorkloadManifest.json
Install Type: FileBased

[aspire]
Installation Source: VS 17.10.35027.167
Manifest Version: 8.0.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0\WorkloadManifest.json
Install Type: FileBased

Host:
Version: 8.0.7
Architecture: x64
Commit: 2aade6beb0

.NET SDKs installed:
8.0.303 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found
```

### Anything else?

Microsoft.Extensions.Configuration 8.0.0
Microsoft.Extensions.DependencyInjection 8.0.0
Microsoft.Extensions.Http 8.0.0
Microsoft.Extensions.ServiceDiscovery 8.1.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.