mirror of https://github.com/abpframework/eventhub
20 changed files with 197 additions and 44 deletions
@ -1,6 +1,6 @@ |
|||||
apiVersion: v2 |
apiVersion: v2 |
||||
name: eventhub |
name: eventhub |
||||
appVersion: "1.0" |
appVersion: "1.0" |
||||
description: Eventhub application chart |
description: EventHub solution |
||||
version: 1.0.0 |
version: 1.0.0 |
||||
type: application |
type: application |
||||
|
|||||
@ -1 +0,0 @@ |
|||||
containerImage: "eventhub.account" |
|
||||
@ -1 +0,0 @@ |
|||||
containerImage: "eventhub.api" |
|
||||
@ -1,5 +1,5 @@ |
|||||
apiVersion: v2 |
apiVersion: v2 |
||||
name: migrator |
name: dbmigrator |
||||
appVersion: "1.0" |
appVersion: "1.0" |
||||
description: EventHub Migrator Application |
description: EventHub Migrator Application |
||||
version: 1.0.0 |
version: 1.0.0 |
||||
|
|||||
@ -1 +0,0 @@ |
|||||
containerImage: eventhub.dbmigrator |
|
||||
@ -1 +0,0 @@ |
|||||
containerImage: eventhub.www |
|
||||
@ -0,0 +1,71 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
|
namespace EventHub.Admin.Utils |
||||
|
{ |
||||
|
public static class SameSiteCookiesServiceCollectionExtensions |
||||
|
{ |
||||
|
public static IServiceCollection AddSameSiteCookiePolicy(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); |
||||
|
}); |
||||
|
|
||||
|
return services; |
||||
|
} |
||||
|
|
||||
|
private static void CheckSameSite(HttpContext httpContext, CookieOptions options) |
||||
|
{ |
||||
|
if (options.SameSite == SameSiteMode.None) |
||||
|
{ |
||||
|
var userAgent = httpContext.Request.Headers["User-Agent"].ToString(); |
||||
|
if (!httpContext.Request.IsHttps || DisallowsSameSiteNone(userAgent)) |
||||
|
{ |
||||
|
// For .NET Core < 3.1 set SameSite = (SameSiteMode)(-1)
|
||||
|
options.SameSite = SameSiteMode.Unspecified; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static bool DisallowsSameSiteNone(string userAgent) |
||||
|
{ |
||||
|
// Cover all iOS based browsers here. This includes:
|
||||
|
// - Safari on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// - Chrome on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// All of which are broken by SameSite=None, because they use the iOS networking stack
|
||||
|
if (userAgent.Contains("CPU iPhone OS 12") || userAgent.Contains("iPad; CPU OS 12")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Cover Mac OS X based browsers that use the Mac OS networking stack. This includes:
|
||||
|
// - Safari on Mac OS X.
|
||||
|
// This does not include:
|
||||
|
// - Chrome on Mac OS X
|
||||
|
// Because they do not use the Mac OS networking stack.
|
||||
|
if (userAgent.Contains("Macintosh; Intel Mac OS X 10_14") && |
||||
|
userAgent.Contains("Version/") && userAgent.Contains("Safari")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Cover Chrome 50-69, because some versions are broken by SameSite=None,
|
||||
|
// and none in this range require it.
|
||||
|
// Note: this covers some pre-Chromium Edge versions,
|
||||
|
// but pre-Chromium Edge does not require SameSite=None.
|
||||
|
if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,21 +1,14 @@ |
|||||
{ |
{ |
||||
"App": { |
|
||||
"CorsOrigins": "https://*.openeventhub.com,https://localhost:44307,https://localhost:44308", |
|
||||
"WebAppUrl": "https://eh-st-www" |
|
||||
}, |
|
||||
"ConnectionStrings": { |
"ConnectionStrings": { |
||||
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" |
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432" |
||||
}, |
}, |
||||
"Redis": { |
"Redis": { |
||||
"Configuration": "127.0.0.1" |
"Configuration": "localhost" |
||||
}, |
}, |
||||
"AuthServer": { |
"AuthServer": { |
||||
"Authority": "https://localhost:44313", |
"Authority": "https://localhost:44313", |
||||
"RequireHttpsMetadata": "true", |
"RequireHttpsMetadata": "true", |
||||
"SwaggerClientId": "EventHub_Swagger", |
"SwaggerClientId": "EventHub_Swagger", |
||||
"SwaggerClientSecret": "1q2w3e*" |
"SwaggerClientSecret": "1q2w3e*" |
||||
}, |
|
||||
"StringEncryption": { |
|
||||
"DefaultPassPhrase": "TxVIZFPxK33czbbv" |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,7 +1,8 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
using Microsoft.AspNetCore.Builder; |
||||
using Microsoft.AspNetCore.Http; |
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
namespace Microsoft.Extensions.DependencyInjection |
namespace EventHub.Utils |
||||
{ |
{ |
||||
public static class SameSiteCookiesServiceCollectionExtensions |
public static class SameSiteCookiesServiceCollectionExtensions |
||||
{ |
{ |
||||
@ -1,7 +1,8 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
using Microsoft.AspNetCore.Builder; |
||||
using Microsoft.AspNetCore.Http; |
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
namespace Microsoft.Extensions.DependencyInjection |
namespace EventHub.Utils |
||||
{ |
{ |
||||
public static class SameSiteCookiesServiceCollectionExtensions |
public static class SameSiteCookiesServiceCollectionExtensions |
||||
{ |
{ |
||||
@ -0,0 +1,71 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
|
namespace EventHub.Web.Utils |
||||
|
{ |
||||
|
public static class SameSiteCookiesServiceCollectionExtensions |
||||
|
{ |
||||
|
public static IServiceCollection AddSameSiteCookiePolicy(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); |
||||
|
}); |
||||
|
|
||||
|
return services; |
||||
|
} |
||||
|
|
||||
|
private static void CheckSameSite(HttpContext httpContext, CookieOptions options) |
||||
|
{ |
||||
|
if (options.SameSite == SameSiteMode.None) |
||||
|
{ |
||||
|
var userAgent = httpContext.Request.Headers["User-Agent"].ToString(); |
||||
|
if (!httpContext.Request.IsHttps || DisallowsSameSiteNone(userAgent)) |
||||
|
{ |
||||
|
// For .NET Core < 3.1 set SameSite = (SameSiteMode)(-1)
|
||||
|
options.SameSite = SameSiteMode.Unspecified; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static bool DisallowsSameSiteNone(string userAgent) |
||||
|
{ |
||||
|
// Cover all iOS based browsers here. This includes:
|
||||
|
// - Safari on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// - Chrome on iOS 12 for iPhone, iPod Touch, iPad
|
||||
|
// All of which are broken by SameSite=None, because they use the iOS networking stack
|
||||
|
if (userAgent.Contains("CPU iPhone OS 12") || userAgent.Contains("iPad; CPU OS 12")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Cover Mac OS X based browsers that use the Mac OS networking stack. This includes:
|
||||
|
// - Safari on Mac OS X.
|
||||
|
// This does not include:
|
||||
|
// - Chrome on Mac OS X
|
||||
|
// Because they do not use the Mac OS networking stack.
|
||||
|
if (userAgent.Contains("Macintosh; Intel Mac OS X 10_14") && |
||||
|
userAgent.Contains("Version/") && userAgent.Contains("Safari")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// Cover Chrome 50-69, because some versions are broken by SameSite=None,
|
||||
|
// and none in this range require it.
|
||||
|
// Note: this covers some pre-Chromium Edge versions,
|
||||
|
// but pre-Chromium Edge does not require SameSite=None.
|
||||
|
if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6")) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue