-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngCookies): support sameSite option #16544
Conversation
164d546
to
cbf09b3
Compare
cbf09b3
to
284ea94
Compare
src/ngCookies/cookieWriter.js
Outdated
@@ -14,6 +14,11 @@ | |||
function $$CookieWriter($document, $log, $browser) { | |||
var cookiePath = $browser.baseHref(); | |||
var rawDocument = $document[0]; | |||
var sameSiteValidValues = ['lax', 'strict']; |
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.
How big is the chance that another option is added to this? This validation would prevent us from supporting this seemlessly.
src/ngCookies/cookieWriter.js
Outdated
@@ -33,6 +38,7 @@ function $$CookieWriter($document, $log, $browser) { | |||
str += options.domain ? ';domain=' + options.domain : ''; | |||
str += expires ? ';expires=' + expires.toUTCString() : ''; | |||
str += options.secure ? ';secure' : ''; | |||
str += (options.SameSite && isSameSiteValueValid(options.SameSite)) ? ';SameSite=' + options.SameSite : ''; |
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.
If the option is invalid we should probably throw - otherwise you get a false sense of security. Based on my comment above, I would simply skip the validation, but add a note to the docs that as time of writing, "lax" and "strict" are allowed values.
284ea94
to
83e1b3e
Compare
83e1b3e
to
1249c3b
Compare
1249c3b
to
3c8b926
Compare
@Narretz also I have add more information to the docs. |
3c8b926
to
10c24b3
Compare
10c24b3
to
84609bd
Compare
Hi @m-amr can you please make the following two final changes:
|
hi @Narretz Thanks for your feedback. regards to this point if we change so to use camelCase we need to edit the name = (name === "SameCase")?'sameCase': name;
lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1)); what do you think ? |
84609bd
to
3073055
Compare
3073055
to
de8d8c1
Compare
de8d8c1
to
2304e2e
Compare
Hi @m-amr you are right, that is a pickle. However I realized just now that the domain names are case-insensitive (that's why the other keys are lowercase). So we should simply lowercase everything - the property name in options object, and the string that is actually written to the cookie |
2304e2e
to
56bd612
Compare
56bd612
to
f05af0e
Compare
@Narretz please review it again. |
Hi @m-amr, almost there. Just change |
f05af0e
to
c211b52
Compare
Hi @Narretz , Thanks |
Closes angular#16543 Closes angular#16544 Closes angular#16544
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feature for issue #16543
What is the current behavior? (You can also link to an open issue here)
What is the new behavior (if this is a feature change)?
support sameSite option for ngCookie
Does this PR introduce a breaking change?
no
Please check if the PR fulfills these requirements
Other information: