-
Notifications
You must be signed in to change notification settings - Fork 140
[4.0.0.2 backport] CBG-4965 create cookie with SameSite=None if CORS enabled #7844
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
Conversation
Redocly previews |
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.
Pull Request Overview
This PR implements support for setting the SameSite cookie attribute on session cookies, with automatic configuration based on CORS settings. By default, when CORS is enabled, session cookies will use SameSite=None to support cross-origin requests. The implementation also adds an unsupported_options.same_site_cookie configuration option to allow manual override of the default behavior.
Key Changes:
- Session cookies now include the
SameSiteattribute, defaulting toNonewhen CORS is enabled - Added
unsupported_options.same_site_cookieconfiguration option with validation for "Lax", "Strict", "None", and "Default" values - Updated
MakeSessionCookiefunction signature to accept asameSiteparameter
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| auth/session.go | Updated MakeSessionCookie to accept and apply SameSite parameter |
| auth/session_test.go | Updated test calls to MakeSessionCookie with default SameSite mode |
| db/database.go | Added SameSiteCookieMode field and GetSameSiteCookieMode validation function |
| rest/session_api.go | Modified session creation to pass SameSite mode to cookie creation |
| rest/server_context.go | Added logic to set SameSiteNoneMode when CORS is enabled, with override support |
| rest/config.go | Added validation for same_site_cookie configuration option |
| rest/config_test.go | Added comprehensive tests for same_site_cookie validation |
| rest/cors_test.go | Enhanced existing CORS test with SameSite attribute verification |
| rest/session_test.go | Added test coverage for SameSite behavior with and without CORS |
| docs/api/components/schemas.yaml | Added OpenAPI specification for same_site_cookie property |
| case "Default": | ||
| return http.SameSiteDefaultMode, nil | ||
| default: | ||
| return http.SameSiteDefaultMode, fmt.Errorf("unsupported_options.same_site_cookie option %q is not valid, choices are \"Lax\", \"Strict\", and \"None", *o.SameSiteCookie) |
Copilot
AI
Oct 29, 2025
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.
Corrected spelling of 'None' to 'None"' - missing closing quote in error message.
| return http.SameSiteDefaultMode, fmt.Errorf("unsupported_options.same_site_cookie option %q is not valid, choices are \"Lax\", \"Strict\", and \"None", *o.SameSiteCookie) | |
| return http.SameSiteDefaultMode, fmt.Errorf("unsupported_options.same_site_cookie option %q is not valid, choices are \"Lax\", \"Strict\", and \"None\"", *o.SameSiteCookie) |
| type: boolean | ||
| same_site_cookie: | ||
| description: |- | ||
| Override the session cookie SameSite behavior. By default, a session cookie will have SameSite:None if CORS is enabled, and will have no SameSite attribute if CORS is not enabled. Setting this property to`Default` will omit the SameSite attribute from the cookie. |
Copilot
AI
Oct 29, 2025
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.
Missing space between 'to' and backtick in 'toDefault' - should be 'to Default'.
| Override the session cookie SameSite behavior. By default, a session cookie will have SameSite:None if CORS is enabled, and will have no SameSite attribute if CORS is not enabled. Setting this property to`Default` will omit the SameSite attribute from the cookie. | |
| Override the session cookie SameSite behavior. By default, a session cookie will have SameSite:None if CORS is enabled, and will have no SameSite attribute if CORS is not enabled. Setting this property to `Default` will omit the SameSite attribute from the cookie. |
[4.0.0.2 backport] CBG-4965 create cookie with SameSite=None if CORS enabled
clean cherry-pick of 30ee4fe