Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 3156678

Browse files
Merge pull request #2768 from ChrisMcKee/master
Enable CSRF cookie to has secure flag enabled
2 parents c713573 + 46f9a30 commit 3156678

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Nancy/Security/Csrf.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static class Csrf
2626
/// <remarks>This is disabled by default.</remarks>
2727
/// <param name="pipelines">The application pipelines.</param>
2828
/// <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)
3031
{
3132
cryptographyConfiguration = cryptographyConfiguration ?? CsrfApplicationStartup.CryptographyConfiguration;
3233

@@ -44,7 +45,7 @@ public static void Enable(IPipelines pipelines, CryptographyConfiguration crypto
4445
context.Response.Cookies.Add(new NancyCookie(
4546
CsrfToken.DEFAULT_CSRF_KEY,
4647
(string)context.Items[CsrfToken.DEFAULT_CSRF_KEY],
47-
true));
48+
true, useSecureCookie));
4849

4950
return;
5051
}
@@ -64,7 +65,7 @@ public static void Enable(IPipelines pipelines, CryptographyConfiguration crypto
6465
var tokenString = GenerateTokenString(cryptographyConfiguration);
6566

6667
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));
6869
});
6970

7071
pipelines.AfterRequest.AddItemToEndOfPipeline(postHook);

0 commit comments

Comments
 (0)