Summary
A path traversal issue in Apache Airflow's SFTP provider allows a malicious or compromised SFTP server to write files outside the intended local download directory.
When Airflow tasks use the vulnerable SFTP hook or operator against untrusted servers, crafted directory-entry names can cause files to be stored in arbitrary filesystem locations on the worker.
Affected context
This vulnerability affects Apache Airflow deployments that use the SFTP provider to download directories from SFTP servers which may be untrusted or only partially trusted.
It specifically involves the SFTPHook.retrieve_directory method and SFTPOperator when invoked with operation="get", where directory contents are recursively mirrored to a local destination.
The risk arises when directory-entry names received from the remote SFTP server are not fully normalized and validated against the configured local base directory, allowing crafted paths to escape the intended target folder.
Exploit preconditions
- Attack surface: Any Airflow worker or task instance that downloads directories from an SFTP server via
SFTPHook.retrieve_directoryorSFTPOperator(operation="get"). - Required access: Ability to control or compromise the remote SFTP server, or influence directory-entry names returned over SFTP (e.g., by adding files or symlinks with crafted paths).
- Trigger point: Execution of a DAG task that performs a directory download from the affected SFTP provider to a local destination path.
- Why exploitation is possible: The implementation trusts path components supplied by the remote SFTP server and concatenates them with the local destination directory without robust normalization and containment checks, enabling traversal outside the configured directory.
Why this happens
The root cause aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The SFTP provider logic constructs local file paths directly from server-supplied filenames and directory names, assuming they are safe to place under the configured destination directory.
Without strict canonicalization and validation (e.g., rejecting .., absolute paths, or mixed separators after normalization), an attacker-controlled SFTP server can return entries whose names traverse out of the destination directory, causing file writes in unintended locations.
This pattern reflects a broader class of bugs where external path input is used for filesystem operations without enforcing a fixed, contained root.
Potential impact
- Malicious files could be written outside the intended download folder.
- Sensitive configuration or application files may be overwritten if the Airflow worker process has write permission.
- New files can be planted in locations that influence application behavior (e.g., plugin folders, scripts, or data inputs).
- Local privilege escalation or code execution may be possible if written files are later executed or loaded by other components.
- Data integrity issues can arise through unauthorized modification of workflow inputs or outputs.
General mitigation guidance
Effective mitigation centers on enforcing strict path containment and reducing trust in remote file metadata.
Recommended defensive patterns include:
- Normalize and resolve all remote path components (e.g., using canonical path utilities) before combining them with local destinations, and reject any path that would escape the configured base directory.
- Treat any server-supplied filename or directory name as untrusted input and validate against an allowlist of patterns, rejecting unsafe sequences such as
.., absolute paths, or drive letters. - Run Airflow workers under operating system accounts with minimal filesystem privileges so that even if traversal occurs, critical paths are not writable.
- Isolate download directories onto dedicated volumes or sandboxes where writes cannot affect application code, configuration, or system binaries.
- Prefer narrowly scoped sync patterns (e.g., target subdirectories or curated file lists) rather than broad recursive downloads from untrusted SFTP sources.
How teams detect issues like this
Detection focuses on both code-level review and runtime monitoring:
- Use static analysis or code review to flag any file-write operations that concatenate external input (like remote filenames) with local paths without canonicalization and containment checks.
- Search for implementations that rely on simple string operations (e.g., naive concatenation or prefix checks) to enforce directory boundaries, rather than using resolved absolute paths.
- Implement logging around SFTP download operations, recording resolved local paths and alerting when writes target directories outside known safe roots.
- Apply filesystem monitoring or intrusion detection on Airflow worker hosts to detect unexpected file creation or modification in sensitive locations during SFTP-based tasks.
- Integrate automated security scanning into CI/CD pipelines to identify path traversal patterns across provider hooks and custom operators.

