@@ -26,7 +26,8 @@ public static class Csrf
26
26
/// <remarks>This is disabled by default.</remarks>
27
27
/// <param name="pipelines">The application pipelines.</param>
28
28
/// <param name="cryptographyConfiguration">The cryptography configuration. This is <see langword="null" /> by default.</param>
29
- public static void Enable ( IPipelines pipelines , CryptographyConfiguration cryptographyConfiguration = null )
29
+ /// <param name="useSecureCookie">Set the CSRF cookie secure flag. This is <see langword="false"/> by default</param>
30
+ public static void Enable ( IPipelines pipelines , CryptographyConfiguration cryptographyConfiguration = null , bool useSecureCookie = false )
30
31
{
31
32
cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup . CryptographyConfiguration ;
32
33
@@ -44,7 +45,7 @@ public static void Enable(IPipelines pipelines, CryptographyConfiguration crypto
44
45
context . Response . Cookies . Add ( new NancyCookie (
45
46
CsrfToken . DEFAULT_CSRF_KEY ,
46
47
( string ) context . Items [ CsrfToken . DEFAULT_CSRF_KEY ] ,
47
- true ) ) ;
48
+ true , useSecureCookie ) ) ;
48
49
49
50
return ;
50
51
}
@@ -64,7 +65,7 @@ public static void Enable(IPipelines pipelines, CryptographyConfiguration crypto
64
65
var tokenString = GenerateTokenString ( cryptographyConfiguration ) ;
65
66
66
67
context . Items [ CsrfToken . DEFAULT_CSRF_KEY ] = tokenString ;
67
- context . Response . Cookies . Add ( new NancyCookie ( CsrfToken . DEFAULT_CSRF_KEY , tokenString , true ) ) ;
68
+ context . Response . Cookies . Add ( new NancyCookie ( CsrfToken . DEFAULT_CSRF_KEY , tokenString , true , useSecureCookie ) ) ;
68
69
} ) ;
69
70
70
71
pipelines . AfterRequest . AddItemToEndOfPipeline ( postHook ) ;
0 commit comments