langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
46.73k stars 6.61k forks source link

Forbidden CSRF cookie not set. #5587

Closed luisbrandao closed 1 month ago

luisbrandao commented 3 months ago

Self Checks

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

dosubot[bot] commented 3 months ago

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.

laipz8200 commented 3 months ago

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!