Skip to content

fix: move cookie sameSite initializer to constructor to prevent OverflowError#41575

Open
wyattwalter wants to merge 1 commit intoreleasefrom
fix/sso-stackoverflow-cookie-initializer-leak
Open

fix: move cookie sameSite initializer to constructor to prevent OverflowError#41575
wyattwalter wants to merge 1 commit intoreleasefrom
fix/sso-stackoverflow-cookie-initializer-leak

Conversation

@wyattwalter
Copy link
Contributor

@wyattwalter wyattwalter commented Feb 24, 2026

addCookieInitializer() was called on every setSessionId() invocation, permanently chaining Consumer.andThen() on the singleton bean's initializer field. After enough session-setting requests, the chain depth exceeded the JVM stack size, crashing SSO login with a StackOverflowError.

Move the sameSite(Lax) initializer to the constructor so it's set once. Leave addCookieInitializers(exchange) as a no-op hook for EE subclasses.

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes
    • Improved session cookie configuration stability by consolidating SameSite attribute setup and preventing potential initialization accumulation issues.

…OverflowError

addCookieInitializer() was called on every setSessionId() invocation,
permanently chaining Consumer.andThen() on the singleton bean's initializer
field. After enough session-setting requests, the chain depth exceeded the
JVM stack size, crashing SSO login with a StackOverflowError.

Move the sameSite(Lax) initializer to the constructor so it's set once.
Leave addCookieInitializers(exchange) as a no-op hook for EE subclasses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the Bug Something isn't working label Feb 24, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Walkthrough

A cookie configuration refactoring in the session ID resolver moves SameSite(LAX) attribute initialization from per-request hooks to the constructor, converting the per-request method to an explicit no-op with documentation to prevent unbounded Consumer chaining.

Changes

Cohort / File(s) Summary
Cookie Configuration Consolidation
app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java
Moved SameSite(LAX) initialization to constructor. Converted addCookieInitializers to explicit no-op with Javadoc warnings against per-request initialization to prevent unbounded Consumer chaining.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🍪 Consolidate the cookie's crunch,
Move SameSite to the start,
No more chaining in a hunch,
One config plays its part!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: moving cookie sameSite initializer to constructor to fix StackOverflowError.
Description check ✅ Passed The description explains the root cause, solution, and design rationale well, but lacks an explicit issue reference link and the DevRel/Marketing checkbox is filled rather than left for template.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sso-stackoverflow-cookie-initializer-leak

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java (1)

35-46: Javadoc should clarify that per-request customization requires overriding setSessionId, not using the addCookieInitializers hook.

The hook is invoked before super.setSessionId() (line 31–32), but that's when response cookies are actually built and set. The Javadoc warns against calling addCookieInitializer here (correct), then says "Instead, modify cookies on the response after super.setSessionId() builds them" — but that action is impossible from within this hook. The guidance implicitly describes overriding setSessionId itself, which should be made explicit to prevent confusion.

EE currently does not override this hook, so no migration action is needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java`
around lines 35 - 46, The Javadoc is misleading about how to perform per-request
cookie customization: update the comment on
CustomCookieWebSessionIdResolverCE::addCookieInitializers to explicitly state
that per-request modifications must be done by overriding setSessionId (not by
calling addCookieInitializer here), because addCookieInitializers is invoked
before super.setSessionId() builds/sets response cookies and therefore cannot
modify the final response cookies; reference addCookieInitializer,
addCookieInitializers and setSessionId in the text so readers know which methods
to use.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java`:
- Around line 35-46: The Javadoc is misleading about how to perform per-request
cookie customization: update the comment on
CustomCookieWebSessionIdResolverCE::addCookieInitializers to explicitly state
that per-request modifications must be done by overriding setSessionId (not by
calling addCookieInitializer here), because addCookieInitializers is invoked
before super.setSessionId() builds/sets response cookies and therefore cannot
modify the final response cookies; reference addCookieInitializer,
addCookieInitializers and setSessionId in the text so readers know which methods
to use.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55ac824 and 21d0d71.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/ce/CustomCookieWebSessionIdResolverCE.java

* {@link StackOverflowError}. Instead, modify cookies on the response after
* {@code super.setSessionId()} builds them.
*/
protected void addCookieInitializers(ServerWebExchange exchange) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the EE pr this method has been completely removed. Might as well remove from here unless it needs to be overridden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants