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
49.47k stars 7.08k forks source link

In udify.app, can't display external images because of CSP #9878

Open andrebalza opened 2 hours ago

andrebalza commented 2 hours ago

Self Checks

Dify version

0.10.1

Cloud or Self Hosted

Cloud

Steps to reproduce

1.  Have the udify.app load an image from any external source (ex. loaded from markdown).
2.  Attempt to load the image, and observe the CSP error in the browser console.

✔️ Expected Behavior

External images should load without CSP violations, allowing for integration of external image sources as needed.

❌ Actual Behavior

External images are currently blocked by the CSP, preventing them from loading. Browser console error message: Refused to load the image 'https://omitted.omitted.fi/Cover/Show?id=kyyti.639346&index=0&size=large' because it violates the following Content Security Policy directive: "img-src 'self' data: mediastream: blob: filesystem: 'nonce-MDdlNWNlZjYtMzg0MS00ZjI0LTk0ZDAtNWZiNzM5ZjQwNmM3' .dify.ai .udify.app udify.app .cloudflareinsights.com .sentry.io http://localhost: http://127.0.0.1: https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com".

dosubot[bot] commented 2 hours ago

Hey @andrebalza! I'm here to help you with any bugs, questions, or contributions you have regarding udify.app. Let's work together to solve this issue!

To resolve the issue of external images being blocked by the Content Security Policy (CSP) in Dify, you need to modify the CSP settings to include the external domains you want to allow. This can be done by updating the CSP_WHITELIST environment variable in your configuration. This variable allows you to specify additional domains that should be permitted by the CSP.

Here's how you can do it:

  1. Locate the .env configuration file in your Dify setup.

  2. Find the CSP_WHITELIST parameter.

  3. Add the external domains you want to allow for image sources to this list. For example, if you want to allow images from example.com, you would add it like this:

    CSP_WHITELIST="*.sentry.io http://localhost:* http://127.0.0.1:* https://analytics.google.com https://googletagmanager.com https://api.github.com example.com"
  4. Save the changes and restart your Dify application to apply the new settings.

This should allow external images from the specified domains to load without CSP violations.

To continue talking to Dosu, mention @dosu.