OpaqueRedirection doesn't respect HTTP/HTTPS scheme behind a load balancer. #57650
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I run my blazor hybrid app behind a load balancer. However, this causes NavigationManager.NavigateTo
to break, since it tries to redirect to an HTTP
scheme when my app is accessed through HTTPS
. Even after following instructions at Configure ASP.NET Core to work with proxy servers and load balancers, the http scheme is still not respected.
During redirection, the browser emits an error and does not redirect:
Mixed Content: The page at 'https://example.com/kanban' was loaded over HTTPS, but requested an insecure resource 'https://example.com/kanban/media'. This request has been blocked; the content must be served over HTTPS.
Refreshing the page redirect correctly since it doesn't use OpaqueRedirection.
Expected Behavior
The opaque redirector should honor the HTTPS/HTTPS scheme based on forwarded headers from a load balancer.
Steps To Reproduce
Clone my repo here: https://github.com/TrieBr/redirect-bug
- Generate and trust certificates for reverse proxy:
cd nginx
dotnet dev-certs https -ep ./OpaqueRedirectionBug.pfx -p password --trust
openssl pkcs12 -in OpaqueRedirectionBug.pfx -nocerts -out OpaqueRedirectionBug.key
Enter 'password' for all 3 prompts.
openssl pkcs12 -in OpaqueRedirectionBug.pfx -clcerts -nokeys -out OpaqueRedirectionBug.crt
Enter 'password'.
openssl rsa -in OpaqueRedirectionBug.key -out OpaqueRedirectionBug.key
Enter 'password'.
-
CD back into the root folder (
cd ../
), and rundocker-compose up
. -
visit
https://localhost
on your browser. -
Open developer tools.
-
Then click "Weather" on the left navigation.
-
Observe in the "network" tab, the fetch of something like
https://localhost/_framework/opaque-redirect?url=...
-
Observe that the returned header
Location
uses http and nothttps
.
On localhost, this isn't an issue, but on a real domain, the browser will throw an error: This request has been blocked; the content must be served over HTTPS
The returned Location
header should use the same http scheme in the request, honoring load balancer forwarded schemes.
Exceptions (if any)
No response
.NET Version
8.0.100
Anything else?
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.a7f084b6
Runtime Environment:
OS Name: Mac OS X
OS Version: 14.5
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.100/
.NET workloads installed:
Workload version: 8.0.100-manifests.a7f084b6
[wasm-tools]
Installation Source: SDK 8.0.100
Manifest Version: 8.0.3/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.workload.mono.toolchain.current/8.0.3/WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.4
Architecture: arm64
Commit: 2d7eea2529
.NET SDKs installed:
6.0.201 [/usr/local/share/dotnet/sdk]
6.0.402 [/usr/local/share/dotnet/sdk]
6.0.404 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
7.0.302 [/usr/local/share/dotnet/sdk]
8.0.100-rc.1.23463.5 [/usr/local/share/dotnet/sdk]
8.0.100-rc.2.23502.2 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
x64 [/usr/local/share/dotnet/x64]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download