Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds secure, httponly, and SameSite=lax to cookies by default #341

Merged
merged 7 commits into from Jul 24, 2017

Conversation

anglinb
Copy link
Contributor

@anglinb anglinb commented Jul 14, 2017

Adds secure and httponly flags to cookies by default, targeting a 4.0 release tracked by #286.

/CC @stve @oreoshake

Outstanding Questions:

Should 4.0 also include SameSite=Lax?

- Default cookies to secure, httponly, samsite=lax

Suggested CHANGELOG entry

(I'm not sure if I should add this to the actual CHANGELOG file b/c I don't know which release this will get pulled into)

Adds secure and httponly flags to all cookies by default.

All Prs

  • Has tests
  • Documentation updated

@oreoshake
Copy link
Contributor

@stve you're the most familiar with this code. Can you take a look 👀?

Copy link
Contributor

@stve stve left a comment

Choose a reason for hiding this comment

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

@anglinb nice work!

I think this all looks good with one point we may need to discuss further.

Main question is how we want to handle a configuration that doesn't specify secure or httponly. If a custom configuration is used, do defaults still get applied or should a custom config supercede any defaults?

@oreoshake how is this handled elsewhere within the configuration?

@@ -5,37 +5,42 @@ module SecureHeaders
describe Cookie do
let(:raw_cookie) { "_session=thisisatest" }

it "does not tamper with cookies when unconfigured" do
cookie = Cookie.new(raw_cookie, {})
it "does not tamper with cookies when using OPT_OUT is used" do
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for adding support for SecureHeaders::OPT_OUT this was a HUGE miss on my part in the initial implementation.

@@ -16,6 +16,11 @@ def validate_config!(config)

def initialize(cookie, config)
@raw_cookie = cookie
unless config == SecureHeaders::OPT_OUT
config ||= {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would make sense to define the default as { secure: true, httponly: true} as opposed to checking for nil in the configuration.

I'm of the opinion that if a configuration is defined (even if it disables secure or httponly), you shouldn't have to opt-out of each configuration explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per #341 (comment), I think we should go with

config[:secure] = true unless config[:secure] == OPT_OUT
config[:httponly] = true unless config[:httponly] == OPT_OUT

@oreoshake
Copy link
Contributor

oreoshake commented Jul 17, 2017

Main question is how we want to handle a configuration that doesn't specify secure or httponly.

You should have to explicitly say secure: OPT_OUT and http_only: OPT_OUT in my mind.

@stve
Copy link
Contributor

stve commented Jul 17, 2017

You should have to explicitly say secure: OPT_OUT and http_only: OPT_OUT in my mind.

@anglinb can you add tests for when secure and httponly are set with OPT_OUT? After that I think we're good to merge.

@oreoshake
Copy link
Contributor

@anglinb sorry for not identifying the OPT_OUT stuff during 🍐. Do you have time to update this? I can take over if you're busy but I'm hoping to get 4.x out this week or next.

@anglinb
Copy link
Contributor Author

anglinb commented Jul 21, 2017

@oreoshake @stve Thanks for taking a look! I'll address your feedback this afternoon--totally missed these notifications 🙃

@oreoshake
Copy link
Contributor

While you're at it... let's default samesite to lax

/me ducks

Break all the things. I'll add a post-install message to broadcast this change (along with the others).

@anglinb
Copy link
Contributor Author

anglinb commented Jul 22, 2017

@oreoshake Sounds good. Will take care of the two changes:

  • Force users to explicitly opt out by supplying {http_only: OPT_OUT}
  • Add SameSite=Lax by default

I'm still going to allow the global, OPT_OUT. So if config = OPT_OUT is equivalent to config = {http_only: OPT_OUT, secure: OPT_OUT, same_site: OPT_OUT}. Does that make sense? @stve @oreoshake

@oreoshake
Copy link
Contributor

I'm still going to allow the global, OPT_OUT. So if config = OPT_OUT is equivalent to config = {http_only: OPT_OUT, secure: OPT_OUT, same_site: OPT_OUT}. Does that make sense?

👍

@anglinb
Copy link
Contributor Author

anglinb commented Jul 22, 2017

^ Just added SameSite=Lax. Please take a look when you have a sec. I think addressed all of the comments. 😄

@stve @oreoshake

Copy link
Contributor

@oreoshake oreoshake left a comment

Choose a reason for hiding this comment

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

Looks good at first glance ☎️ but I'll take a closer look on Monday 💻

@oreoshake oreoshake changed the title Adds secure and httponly to cookies by default Adds secure, httponly, and SameSite=lax to cookies by default Jul 24, 2017
@oreoshake oreoshake merged commit 5e93c58 into github:master Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants