Listen to this Post
The vulnerability in Copier stems from inadequate security controls when processing templates with symbolic links. When a template is deemed “safe” by not using custom Jinja extensions, it can still exploit the `_preserve_symlinks: true` setting to preserve directory symlinks. A malicious template author can create a symlink within the template directory that points to an arbitrary location outside the intended destination path, such as system directories. During project generation, Copier traverses the template file tree using os.scandir, which yields entries in an arbitrary order. If the symlink is processed before the files whose rendered paths resolve inside the symlinked directory, Copier may write generated files into the target of the symlink, bypassing path restrictions. This allows overwriting of arbitrary files based on the user’s permissions, potentially leading to system compromise or data loss. The non-deterministic nature of `os.scandir` means the exploit does not always succeed, depending on directory entry order. This flaw undermines the safety claims of “safe” templates, as no unsafe features are required to trigger it, only careful construction of the template structure with symlinks and the appropriate configuration.
Platform: Copier
Version: Prior versions
Vulnerability: Symlink file write
Severity: Critical
Date: Unspecified
Prediction: No patch yet
What Undercode Say:
Analytics:
Create a malicious template with symlink mkdir malicious_template cd malicious_template ln -s /etc target echo "_preserve_symlinks: true" > copier.yml mkdir -p target/config echo "malicious_content" > target/config/file.txt Use Copier to generate project (may overwrite /etc/config/file.txt) copier copy ./malicious_template ./output
How Exploit:
Attacker crafts template with symlink to sensitive directory and includes files resolving inside symlink. User runs Copier, triggering arbitrary file writes due to `os.scandir` order and _preserve_symlinks.
Protection from this CVE:
Avoid untrusted templates, disable `_preserve_symlinks`, await patch.
Impact:
Arbitrary file overwrite, system compromise.
🎯Let’s Practice Exploiting & Learn Patching For Free:
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

