Skip to content

Conversation

@torcolvin
Copy link
Collaborator

[4.0.0.2 backport] CBG-4965 create cookie with SameSite=None if CORS enabled

clean cherry-pick of 30ee4fe

@torcolvin torcolvin requested a review from adamcfraser October 29, 2025 19:48
Copilot AI review requested due to automatic review settings October 29, 2025 19:48
@github-actions
Copy link

Redocly previews

Copy link
Contributor

Copilot AI left a 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 SameSite attribute, defaulting to None when CORS is enabled
  • Added unsupported_options.same_site_cookie configuration option with validation for "Lax", "Strict", "None", and "Default" values
  • Updated MakeSessionCookie function signature to accept a sameSite parameter

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)
Copy link

Copilot AI Oct 29, 2025

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
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.
Copy link

Copilot AI Oct 29, 2025

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'.

Suggested change
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.

Copilot uses AI. Check for mistakes.
@adamcfraser adamcfraser merged commit 01df412 into release/4.0.0.2 Oct 29, 2025
63 of 64 checks passed
@adamcfraser adamcfraser deleted the CBG-4965 branch October 29, 2025 21:55
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