Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f5a69de0a0 | |||
| 40a5f94941 | |||
| fc4db32f20 | |||
| 9cb4b8264d | |||
| ddd823afab |
@@ -60,6 +60,8 @@ public static class Api
|
|||||||
.ProtectKeysWithCertificate(certificate)
|
.ProtectKeysWithCertificate(certificate)
|
||||||
.SetApplicationName("LiteCharmsApp");
|
.SetApplicationName("LiteCharmsApp");
|
||||||
|
|
||||||
|
services.ConfigureCookieOidcSameSiteSupport();
|
||||||
|
|
||||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||||
|
|
||||||
var authOptions = new LiteCharmsSettings();
|
var authOptions = new LiteCharmsSettings();
|
||||||
@@ -124,6 +126,30 @@ public static class Api
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ConfigureCookieOidcSameSiteSupport(this IServiceCollection services) =>
|
||||||
|
services.Configure<CookiePolicyOptions>(options =>
|
||||||
|
{
|
||||||
|
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
|
||||||
|
options.OnAppendCookie = cookieContext => CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
|
||||||
|
options.OnDeleteCookie = cookieContext => CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
private static void CheckSameSite(HttpContext httpContext, CookieOptions options)
|
||||||
|
{
|
||||||
|
if (options.SameSite == SameSiteMode.None)
|
||||||
|
{
|
||||||
|
bool isSecure = httpContext.Request.IsHttps;
|
||||||
|
|
||||||
|
if (!isSecure && httpContext.Request.Headers.TryGetValue("X-Forwarded-Proto", out var proto))
|
||||||
|
isSecure = string.Equals(proto, "https", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
if (!isSecure && httpContext.Request.Headers.TryGetValue("Forwarded", out var forwarded))
|
||||||
|
isSecure = forwarded.ToString().Contains("proto=https", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
if (!isSecure) options.SameSite = SameSiteMode.Unspecified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddLiteCharmsApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddLiteCharmsApiSecurity(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
|
||||||
|
|||||||
Reference in New Issue
Block a user