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

Enable CSRF cookie to has secure flag enabled #2768

Merged
merged 3 commits into from
Jul 4, 2017
Merged

Enable CSRF cookie to has secure flag enabled #2768

merged 3 commits into from
Jul 4, 2017

Conversation

ChrisMcKee
Copy link
Contributor

Prerequisites

  • [:fire: ] I have written a descriptive pull-request title
  • [:fire: ] I have verified that there are no overlapping pull-requests open
  • [:fire: even used this. and feel unclean ] I have verified that I am following the Nancy code style guidelines
  • [-] I have provided test coverage for my change (where applicable)

Description

Adds optional bool to signature of Csrf.Enable(this.pipelines) to set the csrf cookies secure flag.
I've set it to false by default to avoid unintended activation.
Resolves #2649

@@ -26,7 +26,8 @@ public static class Csrf
/// <remarks>This is disabled by default.</remarks>
/// <param name="pipelines">The application pipelines.</param>
/// <param name="cryptographyConfiguration">The cryptography configuration. This is <see langword="null" /> by default.</param>
public static void Enable(IPipelines pipelines, CryptographyConfiguration cryptographyConfiguration = null)
/// <param name="csrfCookieSecureFlag">Set the CSRF cookie secure flag. This is <see langword="false"/> by default</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better named as just useSecureCookie

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -64,7 +65,7 @@ public static void Enable(IPipelines pipelines, CryptographyConfiguration crypto
var tokenString = GenerateTokenString(cryptographyConfiguration);

context.Items[CsrfToken.DEFAULT_CSRF_KEY] = tokenString;
context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, true));
context.Response.Cookies.Add(new NancyCookie(CsrfToken.DEFAULT_CSRF_KEY, tokenString, httpOnly: true, secure: csrfCookieSecureFlag));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really use named parameters anywhere else in this section of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a whore for clarity true, true requires intellisense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be true, true, it would be true, useSecureCookie

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true; but true still just means true 😉
Entirely up to you; your code base, I just occasionally have to touch it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of those changes are in

@thecodejunkie thecodejunkie added this to the 2.0-dangermouse milestone Jul 4, 2017
@thecodejunkie thecodejunkie merged commit 3156678 into NancyFx:master Jul 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants