-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore: Custom cooke resolver and logout on session invalidation #39695
Merged
+58
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...er/src/main/java/com/appsmith/server/configurations/CustomCookieWebSessionIdResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.appsmith.server.configurations; | ||
|
||
import com.appsmith.server.configurations.ce.CustomCookieWebSessionIdResolverCE; | ||
|
||
/** | ||
* This class is a custom implementation of the CookieWebSessionIdResolver class. | ||
* It allows us to set the SameSite attribute of the session cookie based on | ||
* the organization configuration for cross site embedding. | ||
*/ | ||
public class CustomCookieWebSessionIdResolver extends CustomCookieWebSessionIdResolverCE {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...c/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.appsmith.server.configurations.ce; | ||
|
||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.session.CookieWebSessionIdResolver; | ||
|
||
import java.time.Duration; | ||
|
||
import static java.time.temporal.ChronoUnit.DAYS; | ||
|
||
/** | ||
* This class is a custom implementation of the CookieWebSessionIdResolver class. | ||
* It allows us to set the SameSite attribute of the session cookie based on | ||
* the organization configuration for cross site embedding. | ||
*/ | ||
public class CustomCookieWebSessionIdResolverCE extends CookieWebSessionIdResolver { | ||
|
||
public static final String LAX = "Lax"; | ||
|
||
public CustomCookieWebSessionIdResolverCE() { | ||
// Set default cookie attributes | ||
|
||
// Setting the max age to 30 days so that the cookie doesn't expire on browser close | ||
// If the max age is not set, some browsers will default to deleting the cookies on session close. | ||
this.setCookieMaxAge(Duration.of(30, DAYS)); | ||
this.addCookieInitializer((builder) -> builder.path("/")); | ||
} | ||
|
||
@Override | ||
public void setSessionId(ServerWebExchange exchange, String id) { | ||
addCookieInitializers(); | ||
super.setSessionId(exchange, id); | ||
} | ||
|
||
protected void addCookieInitializers() { | ||
// Add the appropriate SameSite attribute based on the exchange attribute | ||
addCookieInitializer((builder) -> builder.sameSite(LAX).secure(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
❓ Verification inconclusive
Inconsistency between implementation and documentation
The method comment suggests the SameSite attribute should be based on an exchange attribute, but the implementation hard-codes it to "Lax". Either:
Additionally, consider adding a comment explaining why "Lax" was chosen over "Strict" or "None" as it has security implications.
Action: Update the method documentation to reflect the deliberate use of a fixed SameSite value.
📝 Committable suggestion