Forbidden CSRF cookie not set. #4263

Closed
opened 2026-02-21 18:05:27 -05:00 by yindo · 2 comments
Owner

Originally created by @luisbrandao on GitHub (Jun 25, 2024).

Originally assigned to: @laipz8200 on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

"clean run of docker compose trows this error, nothing on the docs on how to disable this check.
i tried:

  - WEB_API_CORS_ALLOW_ORIGINS='*'
  - CONSOLE_CORS_ALLOW_ORIGINS='*'
  - COOKIE_HTTPONLY='true'
  - COOKIE_SAMESITE='Lax'
  - COOKIE_SECURE='false'

image

✔️ Expected Behavior

Docker composer up with the example docker compose should work out of the box.

Actual Behavior

No response

Originally created by @luisbrandao on GitHub (Jun 25, 2024). Originally assigned to: @laipz8200 on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce "clean run of docker compose trows this error, nothing on the docs on how to disable this check. i tried: - WEB_API_CORS_ALLOW_ORIGINS='*' - CONSOLE_CORS_ALLOW_ORIGINS='*' - COOKIE_HTTPONLY='true' - COOKIE_SAMESITE='Lax' - COOKIE_SECURE='false' ![image](https://github.com/langgenius/dify/assets/25795753/5ec3c27e-eed8-4feb-bca9-6c405d1c7b73) ### ✔️ Expected Behavior Docker composer up with the example docker compose should work out of the box. ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:05:27 -05:00
yindo closed this issue 2026-02-21 18:05:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 25, 2024):

Hello, @luisbrandao! I'm here to help with bug reports, answer questions, and assist you while waiting for a human maintainer. Let's work together to resolve the issue you're facing.

To resolve the "403 Forbidden" error with the message "Forbidden CSRF cookie not set" when running a clean instance of Dify version 0.6.11 using Docker Compose in a self-hosted environment, follow these steps:

  1. Check Environment Configuration: Ensure that your environment variables are correctly set up, especially those related to security and CSRF settings. For cross-origin support, you must use the HTTPS protocol and set the configuration to SameSite=None, Secure=true, HttpOnly=true.

    # CSRF Cookie settings
    # Controls whether a cookie is sent with cross-site requests,
    # providing some protection against cross-site request forgery attacks
    #
    # Default: `SameSite=Lax, Secure=false, HttpOnly=true`
    # This default configuration supports same-origin requests using either HTTP or HTTPS,
    # but does not support cross-origin requests. It is suitable for local debugging purposes.
    #
    # If you want to enable cross-origin support,
    # you must use the HTTPS protocol and set the configuration to `SameSite=None, Secure=true, HttpOnly=true`.
    
  2. Update Docker Compose Configuration: Make sure you are using the latest configuration from the Dify repository. Update your local repository and restart the services:

    cd dify/docker
    git pull origin main
    docker compose down
    docker compose pull
    docker compose up -d
    
  3. Verify CSRF Token Handling: Ensure that your frontend application is correctly handling CSRF tokens. The CSRF token should be included in the headers of your requests. If you are using a web browser, make sure it is not blocking cookies or headers.

  4. Check Nginx Configuration: If you are using Nginx as a reverse proxy, ensure that it is correctly configured to pass through the necessary headers:

    proxy_set_header X-CSRFToken $http_x_csrf_token;
    proxy_set_header Cookie $http_cookie;
    
  5. Clear Browser Cookies: Sometimes, old or corrupted cookies can cause issues. Clear your browser cookies and try accessing the application again.

By following these steps, you should be able to resolve the "403 Forbidden" error related to the CSRF cookie not being set [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 25, 2024): <!-- Greeting --> Hello, @luisbrandao! I'm here to help with bug reports, answer questions, and assist you while waiting for a human maintainer. Let's work together to resolve the issue you're facing. <!-- Answer --> To resolve the "403 Forbidden" error with the message "Forbidden CSRF cookie not set" when running a clean instance of Dify version 0.6.11 using Docker Compose in a self-hosted environment, follow these steps: 1. **Check Environment Configuration**: Ensure that your environment variables are correctly set up, especially those related to security and CSRF settings. For cross-origin support, you must use the HTTPS protocol and set the configuration to `SameSite=None, Secure=true, HttpOnly=true`. ```yaml # CSRF Cookie settings # Controls whether a cookie is sent with cross-site requests, # providing some protection against cross-site request forgery attacks # # Default: `SameSite=Lax, Secure=false, HttpOnly=true` # This default configuration supports same-origin requests using either HTTP or HTTPS, # but does not support cross-origin requests. It is suitable for local debugging purposes. # # If you want to enable cross-origin support, # you must use the HTTPS protocol and set the configuration to `SameSite=None, Secure=true, HttpOnly=true`. ``` 2. **Update Docker Compose Configuration**: Make sure you are using the latest configuration from the Dify repository. Update your local repository and restart the services: ```bash cd dify/docker git pull origin main docker compose down docker compose pull docker compose up -d ``` 3. **Verify CSRF Token Handling**: Ensure that your frontend application is correctly handling CSRF tokens. The CSRF token should be included in the headers of your requests. If you are using a web browser, make sure it is not blocking cookies or headers. 4. **Check Nginx Configuration**: If you are using Nginx as a reverse proxy, ensure that it is correctly configured to pass through the necessary headers: ```nginx proxy_set_header X-CSRFToken $http_x_csrf_token; proxy_set_header Cookie $http_cookie; ``` 5. **Clear Browser Cookies**: Sometimes, old or corrupted cookies can cause issues. Clear your browser cookies and try accessing the application again. By following these steps, you should be able to resolve the "403 Forbidden" error related to the CSRF cookie not being set <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/jp/getting-started/install-self-hosted/docker-compose.md)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@laipz8200 commented on GitHub (Jun 26, 2024):

Hi @luisbrandao! We recently made some updates to our docker-compose.yaml file, which might have caused a few issues. Could you please check out 0.6.11 and give it another try? We'd love to hear your feedback!

@laipz8200 commented on GitHub (Jun 26, 2024): Hi @luisbrandao! We recently made some updates to our `docker-compose.yaml` file, which might have caused a few issues. Could you please check out `0.6.11` and give it another try? We'd love to hear your feedback!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4263