Dosu LogoDosu Logo
Ask
Join our Discord
Organization avatar
difyPublic
Dify
Documentsdify
File URL Resolution
File URL Resolution
Type
Topic
Status
Published
Created
Jul 23, 2026
Updated
Aug 4, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

File URL Resolution#

Overview#

Dify uses two base URL settings to serve file content: FILES_URL for external/public access and INTERNAL_FILES_URL for internal service-to-service communication (primarily the plugin daemon). When backend code needs to fetch a Dify-owned signed file URL, it goes through remote_fetcher.py, which resolves the file locally from storage (database lookup + ext_storage) rather than making an outbound HTTP round-trip. Unrecognized URLs fall back to the SSRF-proxied network client.


Configuration: FILES_URL vs INTERNAL_FILES_URL#

Both settings live in FileAccessConfig in api/configs/feature/__init__.py:

SettingEnv vars (in priority order)Purpose
FILES_URLFILES_URL, CONSOLE_API_URLExternal base URL for signed file URLs β€” used in browser-facing links and multimodal model inputs.
INTERNAL_FILES_URLINTERNAL_FILES_URL, SERVER_CONSOLE_API_URLInternal base URL for Docker-internal service access (plugin daemon). Falls back to FILES_URL if unset.
FILES_ACCESS_TIMEOUTFILES_ACCESS_TIMEOUTExpiry for all signed file URLs; default 300 s.

The INTERNAL_FILES_URL field's description explicitly states it is "used for plugin daemon and internal service communication" . In a typical Docker Compose deployment, INTERNAL_FILES_URL is set to http://api:5001 so the plugin daemon can reach the API container directly, while FILES_URL points to the public-facing domain.


URI Generation and URL Binding#

Dify now separates file URL resolution into two stages: URI generation (origin-free signed paths) and URL binding (attaching the appropriate base URL for the target audience).

URI Generation#

Signature functions in api/core/tools/signature.py produce origin-free /files/... URIs with HMAC signatures:

  • sign_tool_file_uri returns /files/tools/{id}{ext}?timestamp=...&nonce=...&sign=... without any base URL.
  • get_signed_file_uri_for_plugin returns /files/upload/for-plugin?... for plugin upload endpoints.

These URIs are network-agnostic: they contain no origin and can be bound to different base URLs for different consumers (plugins, workflows, browser clients, internal services).

URL Binding#

bind_file_uri attaches a base URL to an origin-free /files/... URI:

bind_file_uri(uri, base_url)

The base_url parameter can be:

  • Explicit: a caller-provided URL for custom contexts.
  • FILES_URL for browser-facing links or external clients.
  • INTERNAL_FILES_URL (falling back to FILES_URL if unset) for internal services.

Backward-Compatible Wrappers#

sign_tool_file combines URI generation and binding for convenience:

  • for_external=True (default): calls sign_tool_file_uri then binds the result to FILES_URL β†’ suitable for client-facing URLs.
  • for_external=False: calls sign_tool_file_uri then binds the result to INTERNAL_FILES_URL or FILES_URL β†’ used when plugins or internal workflow steps need to fetch the file.

sign_upload_file_preview_url always uses FILES_URL β€” it is only for external preview/download.


Local Resolution in remote_fetcher.py#

api/core/file/remote_fetcher.py is the canonical client for any backend code that needs to fetch the content of a file URL (workflow nodes, tool callers, pipeline steps). Its module docstring distinguishes it from ssrf_proxy.py, which is for generic outbound HTTP.

Resolution logic in make_request:

  1. For GET and HEAD requests, _resolve_dify_signed_file_url is called first.
  2. _is_dify_file_origin checks if the URL's origin (scheme + host + port) matches either FILES_URL or INTERNAL_FILES_URL. Both are in the allowed set β€” this means a signed URL built with the internal base URL is also resolved locally.
  3. If origin matches, the path is matched against three patterns :
    • /files/<id>/<file-preview|image-preview> β†’ upload file
    • /files/tools/<id> β†’ tool file
    • /files/datasources/<id> β†’ datasource file
  4. The HMAC signature is verified locally (same algorithm as the HTTP endpoint).
  5. On success, file content is loaded from ext_storage via storage.load_once and returned as a synthetic httpx.Response β€” no network request is made.
  6. If any check fails (wrong origin, bad signature, unknown path), the call falls through to ssrf_proxy.make_request.

SSRF Proxy Bypass#

Because Dify file URLs are served from FILES_URL, which often points to localhost or the Docker API hostname, they would normally be blocked by the Squid SSRF proxy (which denies private/internal addresses by default). The local resolution in remote_fetcher.py sidesteps this entirely: recognized Dify file URLs are served from storage before the SSRF proxy is ever involved.

Do not use ssrf_proxy.make_request directly for file content. The remote_fetcher.py module docstring explicitly calls this out: ssrf_proxy is for generic outbound HTTP (HTTP Request nodes, tool calls, auth discovery), not for Dify file content retrieval.


Plugin Access and SSL Issues#

Plugins (running in the plugin daemon) access files via the URL embedded in the File object passed to them. The URL is built with INTERNAL_FILES_URL (or FILES_URL if INTERNAL_FILES_URL is unset). When INTERNAL_FILES_URL is not set and FILES_URL is an HTTPS endpoint with a self-signed certificate, plugins may encounter SSL errors . The fix is to set INTERNAL_FILES_URL=http://api:5001 so plugins reach the API container over plain HTTP on the Docker network.


Key Files#

FileRole
api/core/file/remote_fetcher.pyMain entry point for backend file fetching; implements local resolution
api/core/tools/signature.pyGenerates signed URIs and binds them to base URLs
api/core/app/workflow/file_runtime.pyWorkflow file runtime; provides resolve_file_uri for origin-free URIs
api/configs/feature/__init__.pyDefines FILES_URL, INTERNAL_FILES_URL, FILES_ACCESS_TIMEOUT
api/core/helper/ssrf_proxy.pyGeneric outbound HTTP; used as fallback by remote_fetcher
Documents
Account Activity Tracking
Agent API Routes
Agent App Architecture
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Agent App Event Architecture
Agent App Input Variables
Agent Cost and Usage Tracking
Agent File Handling
Agent File Upload Configuration
Agent Icon Data Model
Agent Log Event Pipeline
Agent Message History
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Agent Model Settings
Agent Node Data Models
Agent Response Schema
Agent Runtime
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Agent Runtime Backend Initialization
Agent Runtime Layer Provider Registration
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Agent Sandbox SSRF Allowlisting
Agent Shell Layer
Agent Strategy Plugin Architecture
Agent V2 Architecture
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Agent V2 Configure Interface
Agent V2 Feature Flags
Agent V2 File and Vision Handling
Agent V2 Variable System
API Documentation Pipeline
App Mode Configuration
App Publishing and Embedding
Audio to Text API
Auth Route Architecture
Automatic Rule Generation
Avatar Management
Branding Customization
Browser Tab and State Management
Builtin Tool Provider Credentials
Celery Task Resilience
Chat Avatar Rendering
Chatbot Conversation State Recovery
Chatbot Widget Embedding
Code Node Execution
Code Node Output Validation
Collaborative Workflow Editing
Conversation Auto-Naming
Conversation Deep-Linking
Credential Encryption and Secret Management
CSV Data Ingestion
Custom Tool Authentication
Custom Tool HTTP Timeout Configuration
Custom Tool OpenAPI Integration
Data Export
Database Migration System
Database Session Management
Database Transaction Isolation
Dataset Batch Import
Dataset Deletion
Dataset Permission Model
Dataset Segmentation Configuration
Dependency Injection and Testability
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Dify Agent Monorepo Structure
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Dify Cloud Billing
Dify OpenAPI
difyctl CLI
Docker Container Security
Docker Deployment and Upgrades
Docker Frontend Configuration
Docker Image Publishing
Docker Networking
Docker Storage and Permissions
Document Indexing Operations
Edition-Based Feature Gating
Elasticsearch Integration
Embedding Cache Integrity
External Knowledge Integration
File Access Control
File Array Handling
File Download Architecture
File Download Security
File Storage Synchronization
File Upload and Download Integrity
File Upload Configuration
File Upload Processing
File URL Resolution
Flask Application Architecture
Flask Blueprint and Route Registration
Graph Streaming Infrastructure
Home Directory Management
HTTP Request Node
HTTP Request Node Key-Value Editor
HTTP Request Node Size Constraints
httpx and Gevent Compatibility
Human Input Node
Hybrid Search
Icon URL Resolution
Iframe Embedding Security
Internationalization and Locale Management
Jina Reranker Integration
JSON-in-Markdown Parsing
JWT Authentication
Knowledge Base API
Knowledge Base Document Processing
Knowledge Base Metadata Filtering
Knowledge Base Summarization Pipeline
Langfuse Integration
Lexical Editor Integration
LLM Provider Message Validation
LLM Structured Output
Local Development Configuration
Local Embedding Model Deployment
Log Filtering
Markdown Extractor Heading Parsing
Markdown Rendering
MCP Client Transport and Connectivity
MCP Protocol Integration for Dify Workflows
MCP OAuth Integration
MCP Protocol Integration
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
MCP Protocol Integration for Dify Workflows
MCP Provider Architecture
MCP Tool Integration
MCP Protocol Integration for Dify Workflows
MCP Tool Parameter Binding
Messaging Platform Integration
Milvus Integration
Model Provider Error Handling
Monaco Editor Integration
Multi-Tenant Context Propagation
Multimodal Knowledge Base Support
Next.js Routing and Redirects
Next.js SSR Authentication
Nginx Reverse Proxy Configuration
Notion Extractor Table Parsing
NumPy CPU Compatibility
OAuth Login Flow
Observability and Tracing
OpenAI-Compatible Server Integration
OpenAPI Spec Accuracy
OpenDAL Storage Backend
Ops Trace Data Models
Oracle Database Connectivity
Parallel Workflow Execution
Parent-Child Retrieval Architecture
Plugin API Key Configuration
Plugin Architecture
Plugin Credential Management
Plugin Daemon Architecture
Plugin Daemon Communication
Plugin Daemon Model Parameter Handling
Plugin Daemon Port Configuration
Plugin Database Integrity
Plugin Error Handling
Plugin File Handling
Plugin Lifecycle Management
Plugin Marketplace Connectivity
Plugin Model Caching
Plugin Permissions
Plugin Storage Configuration
Plugin System Timeouts
Plugin Taxonomy and Validation
Plugin Trigger OAuth Refresh
Private Address Detection
Provider Model & Credential Management
Pyrefly Type Checker
Rate Limiting and Concurrency Control
RBAC Initialization
Reasoning Model Integration
Reasoning Tag Filtering
Redis Connection Management
Redis Streaming Resilience
Release Breaking Changes
Remote File Handling and Validation
Retrieval Filtering and Scoring
RTL Locale Support
Sandbox Code Execution
Sandbox Network Isolation
Sandbox Seccomp Security
Segment Update and Attachment Lifecycle
Server Deployment Configuration
Service API Error Handling
Service API Pagination
Shell Provider Lifecycle
Snippet Variable Handling
SQLite Test Infrastructure
SSE Stream Lifecycle
SSE Stream Terminal Event Delivery
SSR Data Fetching
SSRF Proxy
Suggested Questions After Answer
Summary Index
Tenant-Isolated Document Indexing Queue
Test Doubles and In-Memory Repositories
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
TiDB Vector Full-Text Search
Time Tools
Timestamp Management
Tool File URL Signing
Tool Node Input Validation
Tool Provider Authorization
Trace Task Pipeline
User and Tenant Context Propagation
User Roles and Permissions
Variable Pool Falsy Value Handling
Variable Resolution and Template Substitution
Vector Database Plugin Architecture
Vector Store Integration
Weaviate Vector Store
Web Container Docker Configuration
Webhook Trigger System
WebSocket Service Architecture
Word Document Extraction
Workflow Agent Node Configuration
Workflow Agent Retry Configuration
Workflow and Agent Composition
Workflow Conditional Branching
Workflow Container Nodes
Workflow Conversation State Management
Workflow Draft Synchronization
Workflow Execution Dispatch
Workflow Execution Persistence
Workflow Fail Branch Architecture
Workflow File Handling
Workflow Iteration Node Execution
Workflow LLM Node Configuration
Workflow Memory Management
Dify Agent Server ζ¨‘ε—εˆ†ζž (Commit 55f95dbc)
Workflow Node Canvas Summary Rendering
Workflow Node Versioning
Workflow Pause-Resume State Management
Workflow Resume Architecture
Workflow Run State Management
Workflow Schedule Triggers
Workflow Test Run Execution
Workflow Timeout and Execution Limits
Workflow Tool Visibility and Access Control
Workflow Variable Size Management