File Security Scan is off by default. Enable it by setting
FILE_SCAN_ENABLED to true. See Environment Variables for details.Connect a Scanner
In Integrations > File Security Scan, click Add scanner and choose the type that fits where your files are allowed to go:- Cloudmersive, Scanii, or MetaDefender Cloud: a hosted service you have an account with. Each file’s contents go to that service. Each file it scans uses your quota there, and any member who can edit a knowledge base’s settings can turn scanning on with this scanner. Size your plan for every knowledge base that could use it.
-
Custom Endpoint: your company’s own scanning service. See Custom Endpoint Scanner API for the request and response it must handle.
If your scanning service runs on your company’s internal network, Dify can’t reach it until the deployment allows its address.Dify’s outgoing requests pass through a proxy that blocks internal addresses by default, so that no one can use Dify to reach your internal systems. Allow your endpoint by setting one of:
SSRF_PROXY_ALLOW_PRIVATE_IPS= the endpoint’s IP addressSSRF_PROXY_ALLOW_PRIVATE_DOMAINS= the endpoint’s hostname
Turn On Scanning for a Knowledge Base
Turning on scanning requires the Editor role or above.
Choose What Happens to Unscanned Files
For the two cases where a scan can’t give an answer, choose whether to block the file or let it in unscanned:- When the scanner is unavailable: the scanner can’t be reached, times out, returns a server error, or sends an answer Dify can’t read. Dify retries temporary failures before this choice applies.
- When a file cannot be scanned (encrypted or too large): the file is encrypted or password-protected, larger than the scanner accepts, or a type the scanner doesn’t support.
Check That Scanning Works
Download the EICAR test file from eicar.org. It’s a harmless file that every antivirus engine reports as malware. Save it with a.txt extension and upload it to the knowledge base. Its document should show Error, and hovering the icon next to it should show a malware message.
If it’s indexed instead:
- Check that scanning was turned on and saved before you uploaded the file.
- Check the knowledge base’s When the scanner is unavailable choice. With Allow files, the file goes in unscanned when the scanner doesn’t answer. In Integrations > File Security Scan, a workspace owner or admin can click Test on the scanner to see whether it answers.
Handle a Blocked File
In the document list, hover the icon next to a document’s Error to read why it was blocked. For these two cases, there’s more to know:- Malware detected: delete the document. Retrying it, or uploading the same file again, only blocks it again.
- Encrypted, too large, or not supported by the scanner: such files are blocked by default. If you’re fine with them going into the knowledge base unscanned, switch the knowledge base’s When a file cannot be scanned (encrypted or too large) choice to Allow files, then retry. The choice applies to every later file in the knowledge base, so switch it back if you only needed it for this one.