This scanner type is separate from the Custom Endpoint section of Integrations, which holds API-based extensions with a different request format.
Receive the File
Dify sends each file in its own request:401.
The form carries the file and five text fields:
An ID for this scan. Dify’s automatic retries of a scan send the same ID, so you can answer a repeated request from the first scan instead of scanning again. Retrying the document in the knowledge base later starts a new scan with a new ID.
The SHA3-256 hash of the file content, in hex. It can be empty. If your service needs a hash every time, compute one from the content.
Return a Verdict
Answer with any2xx status and a JSON object:
Names of the threats found, shown to users in the blocked document’s error message. Without them, the message says
unknown was detected.Dify keeps up to 20 names, each cut to 200 characters.Why your service couldn’t scan the file, sent with
unscannable. Dify keeps up to 500 characters and doesn’t show it in the product.- Too large: return
413. The error message says the file exceeds the scanner’s size limit. - Encrypted, an unsupported format, or any other reason: return
unscannable. The error message says the scanner doesn’t support the file, whatever your reason was.
Choose the Right Status Code
Dify decides what to do with the file from your status code and body.For a brief overload that a retry would get past, return
503, not 429.Answer Within the Timeout
By default, Dify waits up to 5 minutes for each answer and tries a request up to 3 times. So a slow endpoint can keep a document waiting about 15 minutes (3 × 5 minutes) before the knowledge base’s When the scanner is unavailable choice applies. Both limits are set byapi.fileScan.requestTimeoutSeconds and api.fileScan.maxAttempts in the Helm values.
When a scan would take longer:
- Your scanner regularly needs more than 5 minutes: ask your deployment administrator to raise the timeout.
- One file would take too long: answer at once with
413orunscannableinstead of letting the request time out.
Start from an Example
Replacemy_scanner in this Flask endpoint with your own scanning logic:
scanner.py
scanner.py, then install Flask and start the endpoint with the API key you’ll enter in Dify:
Test the Endpoint Locally
Send your endpoint a request shaped like Dify’s, from the machine it runs on:file_name, file_size, and mime_type to match each. Your endpoint should answer clean for the first and infected for the second.
The EICAR test file is a harmless file that every antivirus engine reports as malware, available from eicar.org.
infected: reused for good, so a clean file your service wrongly flags stays blocked even after you fix the scanner.clean: reused for 24 hours by default, set byapi.fileScan.cleanVerdictTtlHoursin the Helm values. During that time, the same file passes even if you’ve updated the scanner to catch it.
Make the Endpoint Reachable
Run the endpoint at an address Dify can reach, notlocalhost.
If that address is internal, ask your deployment administrator to allow it in Dify’s SSRF proxy (ssrfProxy.squidConf in the Helm values). See SSRF Protection for details.
For https, the proxy allows only port 443. Dify verifies an https endpoint’s TLS certificate unless the deployment sets HTTP_REQUEST_NODE_SSL_VERIFY to false.
Add the Scanner in Dify
In Integrations > File Security Scan, click Add scanner > Custom Endpoint, and enter your endpoint’s full URL as the Endpoint URL, path included, such ashttp://scanner.example.internal:8000/scan.
When you save the scanner, and whenever you click Test, Dify checks the connection by sending one file:
file:clean-test.txt, astext/plainscan_id:connectivity-checkfile_hash: empty
413. Dify saves the scanner only when the check passes.
Once a knowledge base uses the scanner, upload the EICAR test file there to check the whole path.