-
Notifications
You must be signed in to change notification settings - Fork 46
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 setting httpOnly #194
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point actually. Is it even possible to set a HTTP-only cookie in the browser via document.cookie
though?
Also, it might make sense to replace the assertion with a debug log.
addon/services/cookies.js
Outdated
|
||
if ( !replaced ) { | ||
responseHeaders.append('set-cookie', serializedCookie); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what this change does. Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't really intend to put this in the same PR because I haven't added tests for it yet. So I can pull it out into a separate PR if you like.
But basically every time something writes a cookie right now it gets added to the header array, even if you've previously written a cookie of the same name. ember-simple-auth in particular does this several times during a fastboot request, which results in sending a bunch of redundant info to the client.
So if you do
cookies.write('key', 'value1');
cookies.write('key', 'value2');
The response headers are sent as
Set-Cookie: key=value1
Set-Cookie: key=value2
This change updates/replaces the existing header entry if there's already one for the name instead of always appending a new entry.
It does appear that you can't set |
874592b
to
45354e8
Compare
Updated to allow httpOnly only in fastboot, show the assert in a browser, test both sides appropriately, and pull out the redundant header stuff into a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 I'd just restructure the tests a bit for simplicity.
tests/unit/services/cookies-test.js
Outdated
expect(() => { | ||
this.subject().write(COOKIE_NAME, 'test', { httpOnly: true }); | ||
}).to.throw(); | ||
it('throws when the HTTP only option is set in a browser', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to minimize the change keeping the options checking in |
thanks 🎉 |
There is currently no support for setting
httpOnly
on cookies inwrite()
, with an explicit assert saying it's not useful.While what it says is true and you won't be able to read them from inside Ember, there are still useful reasons you might want to set a httpOnly cookie, e.g. if it is generated by the client but only needs to be readable by a backend service/API.
(If you prefer to keep the assert, it could instead be an option like
yesReallyHttpOnly
passed intowrite()
that causes it to allow writing one, I just need some way to do it)