diff options
author | crupest <crupest@outlook.com> | 2020-06-02 19:07:27 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-02 19:07:27 +0800 |
commit | 25bc15ab02b89d913772409a752cdfe40f70e4c3 (patch) | |
tree | 9d433f9a9b8ccea4e23601bd0415aa88bd9e77ed | |
parent | e90546391cc784ba9a0b0252590ec0f4d91cca68 (diff) | |
download | timeline-25bc15ab02b89d913772409a752cdfe40f70e4c3.tar.gz timeline-25bc15ab02b89d913772409a752cdfe40f70e4c3.tar.bz2 timeline-25bc15ab02b89d913772409a752cdfe40f70e4c3.zip |
fix: not recognize forwarded https protocal.
-rw-r--r-- | Dockerfile | 1 | ||||
-rw-r--r-- | Timeline/Startup.cs | 16 |
2 files changed, 14 insertions, 3 deletions
@@ -5,5 +5,6 @@ RUN dotnet publish Timeline/Timeline.csproj --configuration Release --output ./T FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app +ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED true COPY --from=build /timeline-app/Timeline/publish . ENTRYPOINT ["dotnet", "Timeline.dll"] diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 09281551..5dbc99e6 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -97,10 +97,20 @@ namespace Timeline // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
- app.UseForwardedHeaders(new ForwardedHeadersOptions
+ if (string.Equals(System.Environment.GetEnvironmentVariable("ASPNETCORE_FORWARDEDHEADERS_ENABLED"), "true", StringComparison.OrdinalIgnoreCase))
{
- ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
- });
+ var options = new ForwardedHeadersOptions
+ {
+ ForwardedHeaders = ForwardedHeaders.XForwardedFor |
+ ForwardedHeaders.XForwardedProto
+ };
+ // Only loopback proxies are allowed by default.
+ // Clear that restriction because forwarders are enabled by explicit
+ // configuration.
+ options.KnownNetworks.Clear();
+ options.KnownProxies.Clear();
+ app.UseForwardedHeaders(options);
+ }
app.UseRouting();
|