@@ -35,20 +35,58 @@ public Startup(IConfiguration config, IWebHostEnvironment env)
35
35
36
36
private void CheckSameSite ( HttpContext httpContext , CookieOptions options )
37
37
{
38
- if ( options . SameSite > SameSiteMode . Unspecified )
38
+ if ( options . SameSite == SameSiteMode . None )
39
39
{
40
- var userAgent = httpContext . Request . Headers [ "User-Agent" ] ;
41
- // TODO: Use your User Agent library of choice here.
42
- if ( userAgent . Contains ( "CPU iPhone OS 12" ) // Also covers iPod touch
43
- || userAgent . Contains ( "iPad; CPU OS 12" )
44
- // Safari 12 and 13 are both broken on Mojave
45
- || userAgent . Contains ( "Macintosh; Intel Mac OS X 10_14" ) )
40
+ var userAgent = httpContext . Request . Headers [ "User-Agent" ] . ToString ( ) ;
41
+
42
+ if ( DisallowsSameSiteNone ( userAgent ) )
46
43
{
47
44
options . SameSite = SameSiteMode . Unspecified ;
48
45
}
49
46
}
50
47
}
51
48
49
+ // TODO: Use your User Agent library of choice here.
50
+ public static bool DisallowsSameSiteNone ( string userAgent )
51
+ {
52
+ if ( string . IsNullOrEmpty ( userAgent ) )
53
+ {
54
+ return false ;
55
+ }
56
+
57
+ // Cover all iOS based browsers here. This includes:
58
+ // - Safari on iOS 12 for iPhone, iPod Touch, iPad
59
+ // - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
60
+ // - Chrome on iOS 12 for iPhone, iPod Touch, iPad
61
+ // All of which are broken by SameSite=None, because they use the iOS networking stack
62
+ if ( userAgent . Contains ( "CPU iPhone OS 12" ) || userAgent . Contains ( "iPad; CPU OS 12" ) )
63
+ {
64
+ return true ;
65
+ }
66
+
67
+ // Cover Mac OS X based browsers that use the Mac OS networking stack. This includes:
68
+ // - Safari on Mac OS X.
69
+ // This does not include:
70
+ // - Chrome on Mac OS X
71
+ // Because they do not use the Mac OS networking stack.
72
+ if ( userAgent . Contains ( "Macintosh; Intel Mac OS X 10_14" ) &&
73
+ userAgent . Contains ( "Version/" ) && userAgent . Contains ( "Safari" ) )
74
+ {
75
+ return true ;
76
+ }
77
+
78
+ // Cover Chrome 50-69, because some versions are broken by SameSite=None,
79
+ // and none in this range require it.
80
+ // Note: this covers some pre-Chromium Edge versions,
81
+ // but pre-Chromium Edge does not require SameSite=None.
82
+ if ( userAgent . Contains ( "Chrome/5" ) || userAgent . Contains ( "Chrome/6" ) )
83
+ {
84
+ return true ;
85
+ }
86
+
87
+ return false ;
88
+ }
89
+
52
90
public void ConfigureServices ( IServiceCollection services )
53
91
{
54
92
JwtSecurityTokenHandler . DefaultInboundClaimTypeMap . Clear ( ) ;
0 commit comments