How to configure Antiforgery Cookie to be securely set when deployed behind reverse proxy, such as Træfik? #54955
Unanswered
aDisplayName
asked this question in
Q&A
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When Aspnet.core blazor app is deployed behind a level 7 reverse proxy, such as traefik, how to make sure the antiforgery cookie set in the client browser has the "SECURE" flag set?
In our setup - k3s cluster engine, Traefik is used as the reverse proxy to handle all the HTTPS and HTTP request from 443 and 90 ports. We deploy our .NET 8 Blazor server app into the same cluster. The HTTPS request from the browser at the user side, will be handled by Traefik first, which will terminate the HTTPS session and forward the plain HTTP request to our Blazor server app.
As the result, the antifogery cookies set by the response of the request to our Blazor server app does not have the "SECURE" flag set, and our IT Security team complains about it.
The traefik has already enabled the forwarded header with the X-Forwarded-Proto set to "https". The following flags were set after the blazor sever app was loaded in browser:
As we can see, the SEURE flag was not being set.
We have tried to use the following config in Program.cs
then after we redeploy the app, the following exception was thrown:
Traced it back to
aspnetcore/src/Antiforgery/src/Internal/DefaultAntiforgery.cs
Line 256 in e31f630
It seems the context.Request.IsHttps does not check the forwarded proto result.
My question is, is there a way for aspnet core app deployed behind a Level 7 reverse proxy still able to set the AntiForgery cookie with SECURE flag set?
Regards
Beta Was this translation helpful? Give feedback.
All reactions