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

allow disabling of http only cookies using strings #1428

Merged
merged 2 commits into from
Feb 9, 2018
Merged

allow disabling of http only cookies using strings #1428

merged 2 commits into from
Feb 9, 2018

Conversation

ccntrq
Copy link
Contributor

@ccntrq ccntrq commented Jan 20, 2018

I had some issues disabling http_only cookies for the session cookie.

session: YAML
engines:
    session:
        YAML:
            cookie_name: session.id
            is_http_only: 0

With a config like this the HttpOnly value would always get set in the cookie header string.
The HTTP::XSCookies module seems to handle strings different from numbers and does consider a string containing only '0' to be truthy. This can be fixed by forcing boolean context on the value before passing it to the module.

I added a fix for this and a test to make sure http_only can be disabled with a string.

@bigpresh
Copy link
Member

bigpresh commented Feb 4, 2018

Hmm. I would have expected a Moose/Moo Bool attribute to automatically do the sensible thing and coerce e.g. '0' into a false, but if it doesn't, is the cleaner solution not to add a coercion on the attribute to make sure it's always handled sensibly, not just where we pass it on here?

@ccntrq
Copy link
Contributor Author

ccntrq commented Feb 5, 2018

Hey. Thanks for your response.

I share your feeling that my solution is a little bit hacky. In my opinion the attribute does the sensible thing though without any coercions. As long as the value stays in perl code everything is handled as expected. In perl we expect

if("0") { print "oh noes" }
else { print "expected" }

And the value is handled exactly this way in the corresponding sub pp_to_header.

Using HTTP::XSCookie though we pass the value into C code and cannot rely on this behaviour anymore. It turns out the module takes a different approach at deciding wether to add these flags or not. I think the clean fix would be to change HTTP::XSCookie to match perls semantics for boolean values.

I took a quick approach implementing the suggested change.
https://github.com/ccntrq/http-xscookies/commit/1342e712b21fdb35eaf9bf776e9c799f946f8854

I have no experience with XS code and there are other things broken in the module so I didn't find the time to make it into a pr.

What's your opinion on this? I'd be fine with adding a coercion to the attribute too. As long as we can disable the option in our dancer apps I'm fine.

@bigpresh
Copy link
Member

bigpresh commented Feb 8, 2018

Right, I still think there's a better way to fix this - I commented on your work on HTTP::XSCookies, as that seems like the best fix - but, on the other hand, pragmatically, this PR does solve the problem at hand, so I don't object to it being merged as it is - it could always be reverted later and a dependency on an updated HTTP::XSCookies added instead, if that fix gets applied and released.

@ccntrq
Copy link
Contributor Author

ccntrq commented Feb 9, 2018

I think your proposed solution should be the way to go here. My main priority here is to get this fixed in Dancer and I'd be glad if we could merge it if there aren't any other objections.

I will be on vacation for a week now so I probably won't be very responsive on this. When I come back I will make some time to take a deeper dive into HTTP::XSCookies to fix the underlying issue there.
Thanks for looking into my work and taking your time on this.

@bigpresh
Copy link
Member

bigpresh commented Feb 9, 2018

Yeah, let's merge this as-is as it does the job, and if/when HTTP::XSCookies gets updated we can revisit it.

@bigpresh bigpresh merged commit 2acc43c into PerlDancer:master Feb 9, 2018
@gonzus
Copy link

gonzus commented Mar 7, 2018

Hello. Original author of HTTP::XSCookies here. I just pushed a fix and will cut a new release.

@gonzus
Copy link

gonzus commented Mar 7, 2018

Uploaded HTTP-XSCookies-0.000015.tar.gz. Cheers.

@ccntrq ccntrq deleted the pr/allow_disabling_of_http_only_cookies_using_strings branch August 27, 2020 20:07
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.

3 participants