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. It must be reachable from the public internet, so a service that runs only on your company’s internal network needs a public address first. See Custom Endpoint Scanner API for the request and response it must handle.
Turn On Scanning for a Knowledge Base
In the knowledge base’s Settings, go to File security scan: turn it on, choose a Scanner, set the two choices below, and save. Scanning covers files uploaded after you turn it on. To have every file scanned, create an empty knowledge base first, turn scanning on, then upload your files. What happens to documents already in the knowledge base depends on its kind:- Classic knowledge base: a document is scanned the next time it’s processed, such as when it’s retried or its chunk settings change. If it turns out to be infected, the document shows Error.
- Agent knowledge base: its documents are never scanned, even when they’re retried or re-indexed.
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.
- 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. It should be blocked, with a message that malware was detected.
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
When the file itself caused the block, act on the reason:- Malware detected: leave this file out of the knowledge base. 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 and save.
- In a classic knowledge base, retry the document. In an agent knowledge base, remove the file and upload it again.
- Once the file is in, switch the choice back if you only needed it for this one. Otherwise, it applies to every later file in the knowledge base.