Summary
Python Liquid's FileSystemLoader and CachingFileSystemLoader can be abused to load templates from arbitrary absolute paths outside the intended search directories.
Malicious template authors who can use {% include %} or {% render %} tags may cause the application to read and render files elsewhere on the filesystem, as long as the files contain valid Liquid markup and are readable by the process.
Affected context
This vulnerability appears in Python Liquid deployments that:
- Use the built-in FileSystemLoader or CachingFileSystemLoader
- Allow untrusted or partially trusted users to author or influence template content
- Enable the {% include %} and/or {% render %} tags in those templates
The risk materializes when template resolution does not restrict absolute paths, allowing the engine to reach beyond the configured template directories to any readable file that also parses as Liquid markup.
Exploit preconditions
- Attack surface: Template rendering interface (web views, email templates, CMS pages, or other Liquid-based templating features).
- Required access: Ability to create, upload, edit, or otherwise control Liquid templates or fragments that are rendered by the application.
- Trigger point: Use of
{% include %}or{% render %}with an absolute path that points to a file outside the configured template search paths. - Why exploitation is possible: The loaders accept absolute paths without enforcing that resolved files reside under approved directories, effectively bypassing the intended template root and enabling path traversal-like behavior.
Why this happens
The core issue is a lack of path normalization and enforcement of directory boundaries when resolving template paths.
Python Liquid's FileSystemLoader and CachingFileSystemLoader trust the path provided by templates and, when given an absolute path, do not verify that it lies within the configured search paths.
This behavior corresponds to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where path resolution logic fails to constrain file access to a safe subset of the filesystem.
Potential impact
- Attackers could read and render arbitrary files that:
- Are accessible to the application's OS user, and
- Contain syntactically valid Liquid markup.
- Exposure of sensitive configuration templates or internal template snippets that were not meant to be reachable from untrusted templates.
- Leakage of application logic or proprietary template content that might aid further attacks (such as discovering variable names, data flows, or hidden template endpoints).
- Abuse of unexpected files as templates, potentially causing logic errors or denial-of-service conditions if large or complex files are repeatedly processed as Liquid templates.
General mitigation guidance
Mitigation focuses on enforcing strict, invariant boundaries around which files may be treated as templates and minimizing who can control template content.
Common defensive patterns include:
- Ensuring template loaders perform robust path canonicalization (e.g., resolving symlinks and dot segments) and reject:
- Absolute paths, and
- Paths that resolve outside configured template roots.
- Using loader implementations that are explicitly designed to sandbox template resolution to a fixed directory tree.
- Restricting or disabling dynamic template inclusion capabilities ({% include %}, {% render %}) for untrusted template authors, or providing only a curated set of allowed partial names.
- Segregating templates from any other sensitive files on disk, placing them under a dedicated directory with tightly controlled contents and permissions.
- Reducing the privileges of the application OS user so that even if path constraints fail, the process has limited visibility into sensitive filesystem locations.
How teams detect issues like this
Detection generally combines code-centric review with runtime observation:
- Static analysis and code review:
- Search for use of Python Liquid's FileSystemLoader or CachingFileSystemLoader, especially where templates can be supplied or edited by users.
- Check whether custom loader wrappers enforce path normalization and directory constraints.
- Review usages of {% include %} and {% render %} to ensure only whitelisted template names or relative paths are allowed.
- Configuration and policy checks:
- Enforce internal guidelines that disallow absolute template paths and mandate validation around template resolution.
- Validate that template roots are isolated directories, not overlapping with configuration or source code paths.
- Runtime monitoring:
- Log template load attempts and alert on any absolute path usage or unexpected directories.
- Use file access monitoring or application security tooling to flag Liquid-driven reads from non-template directories.

