Summary
A path traversal vulnerability in liquidjs allows layout, render, and include tags to access arbitrary files via absolute paths, either directly or through Liquid variables when dynamicPartials is enabled.
When an attacker can control template content or influence file paths passed into these tags, they may read sensitive files on the server and potentially expose secrets or application internals.
Affected context
This issue arises in applications that embed liquidjs as a server-side template engine and allow untrusted or partially trusted users to control template content or the values of variables used in layout, render, or include tags.
It is particularly relevant when:
- Templates are user-supplied, user-editable, or generated from external input
- dynamicPartials is enabled (default), allowing include paths to be driven by variables
- The server process has filesystem access to sensitive paths (configuration, credentials, source code)
In such deployments, absolute paths in templates can bypass intended template-root or sandbox restrictions and reach arbitrary files.
Exploit preconditions
- Attack surface: Server-side template rendering endpoints using liquidjs.
- Required access: Ability to:
- Provide or modify Liquid templates (e.g., user-customizable themes, CMS templates), or
- Control variables that determine the filepath in layout, render, or include tags when dynamicPartials is true.
- Trigger point: Rendering of a malicious template or template variable that specifies an absolute filesystem path.
- Why exploitation is possible: The engine resolves absolute paths provided to layout, render, and include tags without enforcing a strict, immutable template root or whitelist, enabling path traversal / arbitrary file access from within the rendering context.
Why this happens
The vulnerability stems from insufficient validation and restriction of file paths used by layout, render, and include tags in liquidjs.
When these tags accept absolute paths—either as string literals or via variables with dynamicPartials enabled—the template engine directly maps those paths to the host filesystem without enforcing a constrained template directory, canonicalization, or a strong allowlist.
This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-influenced paths are resolved outside of the intended root, allowing unauthorized access to files.
Potential impact
- Reading sensitive configuration files (API keys, database credentials, environment variables)
- Exposing application source code and internal logic
- Leakage of access tokens, private keys, or other secrets stored on disk
- Gathering detailed system information useful for subsequent attacks
- Undermining multi-tenant isolation if per-tenant templates can read shared files
General mitigation guidance
Effective mitigation focuses on strictly constraining file resolution and reducing template trust:
- Restrict template loading to a fixed, immutable template root directory and block absolute paths outright.
- Enforce a strict allowlist of templates or partials that can be referenced by layout, render, and include tags.
- Disable or tightly scope dynamicPartials when template paths may be influenced by untrusted input.
- Treat user-supplied templates as untrusted content and avoid granting them direct control over file inclusion paths.
- Run the template-rendering process with least-privilege filesystem permissions so that even if a path is misused, access to sensitive directories is limited.
- Apply input validation and normalization to any path-like values before they reach the template engine, rejecting absolute paths and directory traversal patterns.
How teams detect issues like this
Organizations can detect and monitor for this class of issue using several approaches:
- Static analysis / code scanning:
- Flag uses of layout, render, and include where the path argument is derived from user input or untrusted variables.
- Identify configurations that enable dynamicPartials alongside user-controlled template content.
- Code review checklists:
- Verify that all template includes are constrained to a known directory or allowlist.
- Confirm that absolute paths and traversal sequences are rejected before they reach the template engine.
- Runtime monitoring and logging:
- Log template include resolutions, especially when an unexpected absolute path is requested.
- Alert on attempts to load files from system directories (e.g.,
/etc/, application config directories). - Security testing:
- Incorporate path traversal test cases into QA and security tests for any endpoint that renders liquidjs templates.

