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

Add a guideline on SameSite #16

Merged
merged 3 commits into from
Mar 25, 2025
Merged

Conversation

wbamberg
Copy link
Collaborator

Fixes #14.

Adds a guideline on SameSite.

@wbamberg
Copy link
Collaborator Author

Perhaps this is too detailed, compared with the other guidelines in this document?

@@ -48,6 +48,29 @@ A CSP helps mitigate [cross-site scripting (XSS)](https://developer.mozilla.org/
- [Content Security Policy Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html) (OWASP)
- [Strict CSP guide](https://web.dev/articles/strict-csp) (web.dev)

### Set the SameSite attribute on sensitive cookies

The [`SameSite`]() cookie attribute is a defense in depth against a variety of attacks, including [clickjacking](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/Clickjacking), [CSRF](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF) and various [cross-site leaks](https://xsleaks.dev/). It takes one of three values: `Strict`, `Lax`, or `None`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is [`SameSite`]() supposed to have a link?

Copy link

@ctcpip ctcpip Mar 25, 2025

Choose a reason for hiding this comment

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

it has one:

https://github.com/w3c-cg/swag/pull/16/files#diff-3cab2860020a2955db57c967979a7709716481b5c4b03c0ed6f394bfcc0007bbR70

but the empty parens need to be removed. I added a suggestion for that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I missed this, but didn't intend to make it a reference link. I will push an update to fix it.

- `Lax` for cookies that you will use to decide if a logged-in user should be shown a page
- `Strict` for cookies that you will use to authorize requests that carry out some sensitive action, such as transferring money or changing the user's settings.

Note that `Lax` is the default value in some but not all browsers, and in those browsers, the implementation of `Lax` when it is the default is more permissive than the normal implementation of `Lax`. This means that you should actively set `Lax`, and not rely on it being the default.
Copy link
Collaborator

Choose a reason for hiding this comment

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

default value in some but not all browsers

Do we know whether this is likely to change in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For Firefox, this is the best I could find: https://bugzilla.mozilla.org/show_bug.cgi?id=1617609#c26. Short answer, no, not in the forseeable future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See also mdn/content#36931.

As a general guide, then, you should try to use `Strict` for some cookies and `Lax` for others:

- `Lax` for cookies that you will use to decide if a logged-in user should be shown a page
- `Strict` for cookies that you will use to authorize requests that carry out some sensitive action, such as transferring money or changing the user's settings.
Copy link
Collaborator

Choose a reason for hiding this comment

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

some sensitive action

I wonder whether we should mention that a good rule-of-thumb for this sensitivity is whether the action is "state-changing" (which is exactly what you're implying in the examples you've cited)!

@@ -48,6 +48,29 @@ A CSP helps mitigate [cross-site scripting (XSS)](https://developer.mozilla.org/
- [Content Security Policy Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html) (OWASP)
- [Strict CSP guide](https://web.dev/articles/strict-csp) (web.dev)

### Set the SameSite attribute on sensitive cookies

The [`SameSite`]() cookie attribute is a defense in depth against a variety of attacks, including [clickjacking](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/Clickjacking), [CSRF](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF) and various [cross-site leaks](https://xsleaks.dev/). It takes one of three values: `Strict`, `Lax`, or `None`.
Copy link

Choose a reason for hiding this comment

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

Suggested change
The [`SameSite`]() cookie attribute is a defense in depth against a variety of attacks, including [clickjacking](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/Clickjacking), [CSRF](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF) and various [cross-site leaks](https://xsleaks.dev/). It takes one of three values: `Strict`, `Lax`, or `None`.
The [`SameSite`] cookie attribute is a defense in depth against a variety of attacks, including [clickjacking](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/Clickjacking), [CSRF](https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF) and various [cross-site leaks](https://xsleaks.dev/). It takes one of three values: `Strict`, `Lax`, or `None`.

@wbamberg wbamberg merged commit fc2a071 into w3c-cg:main Mar 25, 2025
1 check passed
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.

New guideline on SameSite?
3 participants