[PR #27190] Enabled cross-subdomain console sessions by making the cookie domain configurable and aligning the frontend so it reads the shared CSRF cookie. #31710

Closed
opened 2026-02-21 20:49:59 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/27190

State: closed
Merged: Yes


Fixes #27189

Which enable Next.js running like dify.thape.com.cn and Backend running like diff-api.thape.com.cn

Summary

  • api/libs/token.py:32-159 now strips an optional COOKIE_DOMAIN, skips the __Host- prefix when it’s set, and applies the Domain attribute to every console/session cookie so they can flow between dify-api and dify.
  • api/configs/feature/__init__.py:340-343 exposes COOKIE_DOMAIN; see the usage notes added to api/.env.example:159-161 (and mirrored in web/.env.example:37-38) for deployment guidance.
  • api/tests/unit_tests/libs/test_token.py:30-58 adds regression coverage for both host-only and shared-domain cookie scenarios.
  • web/config/index.ts:147-151 respects NEXT_PUBLIC_COOKIE_DOMAIN, ensuring the browser now grabs the plain csrf_token cookie when you share it across subdomains.

Checklist

  • This change NOT requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • No need updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/27190 **State:** closed **Merged:** Yes --- Fixes #27189 Which enable Next.js running like dify.thape.com.cn and Backend running like diff-api.thape.com.cn ## Summary - api/libs/token.py:32-159 now strips an optional COOKIE_DOMAIN, skips the __Host- prefix when it’s set, and applies the Domain attribute to every console/session cookie so they can flow between dify-api and dify. - api/configs/feature/__init__.py:340-343 exposes COOKIE_DOMAIN; see the usage notes added to api/.env.example:159-161 (and mirrored in web/.env.example:37-38) for deployment guidance. - api/tests/unit_tests/libs/test_token.py:30-58 adds regression coverage for both host-only and shared-domain cookie scenarios. - web/config/index.ts:147-151 respects NEXT_PUBLIC_COOKIE_DOMAIN, ensuring the browser now grabs the plain csrf_token cookie when you share it across subdomains. ## Checklist - [x] This change *NOT* requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] No need updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:59 -05:00
yindo closed this issue 2026-02-21 20:49:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31710