AI Cloud & DevOps Dify AI IT Outsourcing

Dify Security: Hardening a Self-Hosted Dify App Before It Goes Live

8 min read
Dify Security: Hardening a Self-Hosted Dify App Before It Goes Live

In November 2026, Amazon published what its decoy sensors had recorded between 3 October and 5 November: AI agents, run by criminal groups on an open-source attack framework called ARTEX, searching the internet for exposed AI applications and taking the model API keys stored inside them. Dify was on the target list, next to LiteLLM, Langflow, RAGFlow, Open WebUI and others. If an outside team is building your chatbot, agent or internal assistant on Dify, Dify security belongs in the delivery scope itself. This guide covers why these platforms are targeted, which defaults to change before launch, and what to write into the scope of your AI development project.

Why attackers go after Dify and other AI app builders

The AWS Security Blog report (13 November 2026) explains the logic. AI gateways and app builders hold the keys for the upstream model providers. One weak management interface can expose many downstream accounts, so the agents focused on exactly these products.

The method was the same across campaigns: find internet-exposed AI applications, pull out the upstream provider keys, check that they work, and add them to a pool. Stolen keys then paid for the model calls that powered the search for more keys.

The attackers did not need new techniques. According to Amazon, their playbook covered:

  • uninitialized installs that could be claimed by whoever reached them first;
  • anonymous management and provider-configuration endpoints;
  • default administrator credentials;
  • known CVEs in AI tools, such as CVE-2025-3248 in Langflow;
  • SSRF through URL-fetch features to reach cloud metadata services;
  • secrets left in client-side JavaScript, source maps, debug routes and environment files.

The agents also searched GitHub, npm and PyPI packages, container image layers, notebooks and paste sites for leaked keys. Keys that had been public for more than 30 days were treated as low-value inventory: the agents went after fresh leaks. Amazon's advice follows from that speed: assume exposed secrets and misconfigurations will be found quickly.

Amazon's conclusion is the part to share with your team: the agents succeeded where basic hygiene was missing, and organizations should bring AI applications, model gateways and inference endpoints under the same controls as other production systems.

How the attackers stole AI keys, as recorded by Amazon: find an exposed AI app such as Dify, extract provider keys, validate them, pool the working keys, use them to hunt for more

Who owns Dify security when an outside team builds the app

When a partner builds on Dify, two things stay with you: the model provider accounts the keys belong to, and the cloud account the app runs in. A leaked key bills your account. An exposed instance sits in your network.

The development partner owns what goes into the build: the configuration, the network layout of the deployment, how keys move from your vault into Dify, and the tests that prove the defaults were changed. Spell out that split in writing, so neither side assumes the other changed the defaults.

Who owns Dify security when an outside team builds the app: the client keeps the model provider accounts, the cloud account and key revocation; the partner delivers the hardened configuration, network layout, key handling and proof that defaults changed

The Dify defaults to change before launch

Dify's own environment variable reference lists the values a Docker deployment ships with. Several are fine for a laptop and wrong for production.

Secrets and passwords

  • SECRET_KEY signs authentication tokens and file URLs and encrypts system-level OAuth client credentials. If it is empty, Dify generates one and stores it in its storage volume. The docs recommend generating a strong random value and setting it before first launch.
  • DB_PASSWORD and REDIS_PASSWORD default to difyai123456. So do the passwords for several bundled vector stores.
  • CODE_EXECUTION_API_KEY and SANDBOX_API_KEY default to dify-sandbox. Both must match, so change them together.

Store the replacements in a secrets manager, not in a .env file committed to the repository. Amazon's report names environment files as one of the places the agents looked.

Network exposure

  • WEB_API_CORS_ALLOW_ORIGINS and CONSOLE_CORS_ALLOW_ORIGINS default to *. Set them to your own console and app domains.
  • The plugin daemon listens for remote debugging on port 5003, with PLUGIN_DEBUGGING_HOST set to 0.0.0.0 by default. Keep that port closed to the internet in production.
  • Complete the first-run admin setup before the instance is reachable from outside, and put the console behind your VPN or SSO where you can. An uninitialized install was one of the entry points in Amazon's report.
  • The database, Redis and the vector store do not need public addresses.

Outbound requests

Amazon's report lists SSRF through URL-fetch features as one way the agents reached cloud metadata services. Dify routes outbound HTTP requests, such as HTTP nodes and image downloads, through a Squid-based SSRF proxy that blocks internal and private IP ranges. Keep that proxy in the path. When an integration needs a private address, let only that host through the proxy instead of switching the proxy off to make the integration work.

The docs add one caveat: code running in the sandbox cannot reach the internet directly, but it can still connect to the API, workers, plugin daemon and other services on the same internal network. If your code nodes handle input you do not control, isolate the sandbox network as well.

Keys inside Dify

Dify release 1.17.1 (10 September 2026) added knowledge-base API keys that can be bound to specific knowledge bases. Before that, one key could read and write every knowledge base in the workspace. Existing keys stay workspace-wide after the upgrade, so ask for new, bound keys for each integration.

For the model provider keys themselves, OpenAI's API key safety guidance is a good baseline for any vendor: a unique key for each team member, keys with an expiry date and a rotation process, never a key in a browser or mobile app, never a key committed to the repository. Requests should go through your own backend.

Patching

Dify ships often. Version 1.18.0 came out on 23 October 2026, 1.19.0 on 4 November and 1.20.0 on 18 November. The 1.20.0 release can scan uploaded knowledge files for malware before they are indexed, once FILE_SCAN_ENABLED is turned on.

AI tools get serious vulnerabilities like any other software. CVE-2025-3248 let a remote, unauthenticated attacker run code on Langflow versions before 1.3.0, and CISA added it to its Known Exploited Vulnerabilities catalog on 5 May 2025. Agree up front who watches Dify releases and how fast security fixes reach production.

Watch spend and usage

According to Amazon, the attackers most likely wanted keys so they could run models while someone else paid, which means misuse shows up as spend. Amazon's advice is to watch for misuse of AI services through unexpected spend or unusual usage. Set budget alerts on every provider account, keep separate keys per environment so a spike points to one app, and decide in advance who can revoke a key at 2 a.m.

Pre-launch Dify security checklist: replace default secrets, close what is public, keep the SSRF proxy on, bind and rotate keys, patch on a schedule, alert on spend

What to write into the statement of work

A short section in the scope saves an argument later. These are the items we would put in it:

  1. Deployment layout: where Dify runs, which ports are public (ideally only the app and API behind HTTPS), and which services stay on the private network.
  2. Secrets: every default secret and password replaced, values stored in a named secrets manager, nothing in the repository or the client bundle.
  3. Keys: one provider key per environment, expiry and rotation dates, knowledge-base keys bound to specific datasets, and the person on your side who owns the provider accounts.
  4. Access: console behind VPN or SSO, admin accounts named, setup completed before exposure.
  5. Patching: the Dify version at launch, who reads release notes, and the target time to apply a security release.
  6. Monitoring: budget alerts per provider account and the runbook for a suspected key leak.
  7. Evidence at handover: a configuration review against this list, plus a scan of the repository and container images for secrets.

Handover evidence matters as much as the work itself. If you later change vendors or bring the app in-house, the next team needs to know what was hardened and why.

How we approach Dify projects at MOHA

MOHA has built a Dify-powered pet care app on AWS with React Native and real-time translation. Our engineers also write about Dify in practice, for example connecting Dify to GitHub to answer engineering questions, where we recommend self-hosting Dify in your own VPC when the app handles personal or regulated data.

For finance clients, our AI development team delivers with security reviews, audit trails and documented test evidence. A Dify deployment deserves the same habit: the hardening is written down and handed over, not left in one engineer's head. For hosting and delivery pipelines, see our cloud and DevOps services.

Before an agent goes live, we also test how it behaves, which we cover in our guide to AI agent evaluation.

Questions to settle with your AI development partner

  • Which Dify services will be reachable from the internet, and how is the console protected?
  • Where do the provider keys live, and who can read them?
  • Which default secrets were replaced, and how will we see proof of that at handover?
  • Which Dify version are we launching on, and who applies security releases after go-live?
  • What alerts tell us a key is being misused, and who revokes it?

If you are planning a Dify app or want a second look at one already running, contact us to discuss the project.

Emily
Related Articles
IT Outsourcing Software Technology
We got your back! Share your idea with us and get a free quote