Summary
A path traversal flaw in Incus template processing allows users who can launch containers with custom images to read and write arbitrary files on the host through crafted metadata templates.
By abusing directory traversal and symbolic links in template source and target paths, an attacker may escalate from container-level control to arbitrary command execution on the host system.
Affected context
This vulnerability affects Incus system container and virtual machine environments, including IncusOS, where:
- Users are permitted to launch containers or VMs with custom images.
- Images can carry a
metadata.yamlfile defining templating behavior. - The templating engine runs with access to the host filesystem and applies templates during instance creation.
In such setups, both the template source and destination paths are processed without rigorous checks for directory traversal sequences or symbolic links, allowing crafted paths to escape intended directories.
Exploit preconditions
- Attack surface: Incus daemon or host via the container/VM image import and launch workflow.
- Required access: Ability to:
- Supply or modify a custom Incus image, or
- Launch containers from images that the attacker can control, including their
metadata.yaml.
Typically this implies membership in the incus group or equivalent delegated control.
- Trigger point: Instance creation or initialization when the templating functionality processes entries from
metadata.yaml, copying or rendering files to specified locations. - Why exploitation is possible:
- Template source and target paths in
metadata.yamlare not normalized or constrained to a safe root. - Symbolic links are not resolved or filtered before use.
- As a result,
../sequences and symlink chains can direct operations to arbitrary paths on the host filesystem.
Why this happens
The root cause aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The templating functionality responsible for processing metadata.yaml trusts path values provided in the image:
- It does not sanitize or canonicalize paths to prevent
../directory traversal. - It does not robustly handle or restrict symbolic links that may point outside the intended directory tree.
Because the template engine operates with host-level privileges, this lack of path restriction enables arbitrary file access on the host, turning what should be a scoped configuration mechanism into a powerful escalation primitive.
Potential impact
- Reading sensitive host files (e.g., configuration files, secrets, credentials) that the Incus daemon can access.
- Overwriting or creating arbitrary files on the host filesystem.
- Planting or modifying scripts, configuration, or service units to execute attacker-controlled commands.
- Escalating from container-level control to host-level arbitrary code execution.
- Persistence on the host via modified startup or service configuration.
- Lateral movement within the host environment through credential or key theft.
General mitigation guidance
Effective mitigation typically involves tightening how template paths are interpreted and reducing the trust boundary between images and the host:
- Constrain template paths: Normalize and canonicalize all template source and target paths, and reject paths that resolve outside a defined, safe base directory.
- Harden symlink handling: Disallow symlinks in template-controlled directories or ensure that symlink resolution is restricted to a safe root; consider treating unexpected symlinks as errors.
- Apply strict validation to
metadata.yaml: Enforce schema and policy checks on template entries, including allowed directories, filename patterns, and operation types. - Limit host privileges of templating routines: Run the templating process with minimal necessary permissions and access only to explicitly allowed directories.
- Restrict who can provide custom images: Limit membership in the
incusgroup or similar roles, and apply additional review or approval for externally supplied images. - Isolate image processing: Where possible, perform template expansion in a constrained environment (e.g., chroot, mount namespaces, or dedicated service accounts) that does not expose the full host filesystem.
How teams detect issues like this
Detection approaches can combine code-level analysis with operational monitoring:
- Static analysis and code review:
- Search for file operations that rely on unvalidated paths from
metadata.yamlor other image-controlled inputs. - Flag uses of path concatenation without canonicalization and checks against a strict base directory.
- Review handling of symlinks in template directories and ensure that APIs enforcing "no symlink escape" semantics are used.
- Policy and configuration checks:
- Enforce policies requiring path normalization and base-path enforcement in all templating components.
- Require security review for changes to image import and templating logic.
- Runtime monitoring and logging:
- Enable detailed logging of templating activity, including source and target paths and any failures due to validation.
- Monitor for template operations targeting unexpected host directories (e.g.,
/etc,/root,/var/lib/incus). - Use host intrusion detection systems to identify unusual file changes originating from Incus-related processes.
- Automated tooling:
- Incorporate specialized linters or SAST tools capable of recognizing path traversal patterns.
- Use CI/CD checks to enforce that new code paths dealing with template metadata follow established safe patterns.

