-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
My application is running behind a reverse proxy with HTTPS termination: the reverse proxy receives requests in HTTPS and then forwards the requests to the .NET application over HTTP.
The .NET application is configured to take into account the header X-Forwarded-Proto in order to have Request.Scheme returning https.
It was working as expected with .NET 8.0.16 - returning https
But the bahavior has changed with .NET 8.0.017 - returning http
Reproduction Steps
- Configure headers forwarding in Program.cs
builder.Services.Configure<ForwardedHeadersOptions>(options =>
options.ForwardedHeaders = ForwardedHeaders.XForwardedProto);
app.UseForwardedHeaders();
- Create a controller that just returns
Request.Scheme
[ApiController]
[Route("[controller]")]
public class DisplayXForwardProtoController() : ControllerBase
{
[HttpGet(Name = "DisplayXForwardProto")]
public object DisplayXForwardProto() =>
new
{
requestScheme = Request.Scheme,
xForwardedProto = Request.Headers["X-Forwarded-Proto"]
};
}
- Running the application with Docker
# Base image that works as expected: FROM mcr.microsoft.com/dotnet/aspnet:8.0.16 AS base
# Base image causing issues: FROM mcr.microsoft.com/dotnet/aspnet:8.0.17 AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0.17 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["TestForwardProto/TestForwardProto.csproj", "TestForwardProto/"]
RUN dotnet restore "TestForwardProto/TestForwardProto.csproj"
COPY . .
WORKDIR "/src/TestForwardProto"
RUN dotnet build "./TestForwardProto.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./TestForwardProto.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestForwardProto.dll"]
- Calling the .NET endpoint with header X-Forwarded-Proto
curl --location 'http://127.0.0.1:8080/DisplayXForwardProto' --header 'X-Forwarded-Proto: https'
Please find enclosed the full minimal project to reproduce the issue: TestForwardProto.zip
Expected behavior
Request.Scheme
should return https
Actual behavior
Request.Scheme
returns http
Regression?
Yes, it was working on .NET 8.0.16
In the code provided, simply replace the base image in Dockerfile with mcr.microsoft.com/dotnet/aspnet:8.0.16 and it works.
Known Workarounds
No response
Configuration
No response
Other information
No response