/

CVE-2026-55760

Severity:

HIGH RISK

(7.5)

Path Traversal (CWE-22) in Handlebars.java Templates

CVE-2026-55760

Awaiting Analysis

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Read

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Handlebars.java templates compiled from user-controlled names can be abused to traverse directories and read arbitrary files on the server.

When template names are derived from URL paths, query parameters, or other untrusted input and passed to FileTemplateLoader or ClassPathTemplateLoader, attackers may access sensitive files outside the intended template directory.

Affected context

This vulnerability occurs in Java applications that integrate Handlebars.java and dynamically compile templates using Handlebars.compile() with template names influenced by user input.

It is most relevant when FileTemplateLoader or ClassPathTemplateLoader is used and the application does not normalize or strictly validate template paths.

The risk increases when template identifiers come directly from URL path segments, request parameters, headers, or any other user-controlled fields without constraining them to a safe, predefined set.

Exploit preconditions

  • Attack surface: HTTP endpoints or APIs that accept template names directly or indirectly from user input.
  • Required access: Ability to send crafted requests that influence the template name passed into Handlebars.compile().
  • Trigger point: Invocation of Handlebars.compile() with FileTemplateLoader or ClassPathTemplateLoader using an untrusted template name.
  • Why exploitation is possible: The template loaders resolve file paths based on provided names and, without rigorous canonicalization and enforcement of allowed directories, directory traversal sequences (e.g., ../) can escape the intended template root and access other files.

Why this happens

The underlying issue is improper restriction of file paths when resolving templates, corresponding to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

Handlebars.java, when used with FileTemplateLoader or ClassPathTemplateLoader, trusts the template name as a relative path without consistently preventing traversal outside the configured base directory.

When applications pass user-controlled values directly into Handlebars.compile(), this trust boundary is violated, enabling attackers to supply traversal patterns that cause the loader to read arbitrary files within the accessible filesystem or classpath.

Potential impact

  • May allow reading of application configuration files containing secrets, keys, or database credentials.
  • Can expose source code, templates, or internal documentation that aids further attacks.
  • Could reveal environment metadata and system files that help with reconnaissance.
  • May leak authentication tokens, API keys, or other sensitive data stored in readable files.

General mitigation guidance

Effective mitigation centers on strictly controlling how template names are derived and resolved:

  • Prefer mapping user input to a predefined, whitelisted set of template identifiers instead of using raw user-provided paths.
  • Enforce normalization and validation of template names to disallow .., absolute paths, or path separators that escape the intended directory.
  • Constrain template resolution to a minimal, dedicated directory or package with no sensitive data.
  • Apply least-privilege principles to the runtime so that even if traversal occurs, accessible files contain limited or no sensitive information.
  • Consider separating template loading privileges from components that store secrets or configuration data.

How teams detect issues like this

Detection typically involves a combination of code review and automated analysis:

  • During code review, look for calls to Handlebars.compile() where the template name is derived from request parameters, path variables, or other untrusted data.
  • Use static analysis or custom linters to flag usages of FileTemplateLoader and ClassPathTemplateLoader where inputs are not validated or normalized.
  • Implement security tests that attempt directory traversal sequences (e.g., ../, URL-encoded variants) in template-related endpoints to confirm behavior.
  • Incorporate SAST/IAST tools that understand path construction patterns and can mark file-access APIs that are influenced by tainted input.

Sources

SourceLink
github.comgithub.com/jknack/handlebars.java/commit/d177cdee8b750385ca7a0d0f89f2d4be73e28f4e
github.comgithub.com/jknack/handlebars.java/releases/tag/v4.5.2
github.comgithub.com/jknack/handlebars.java/security/advisories/GHSA-r4gv-qr8j-p3pg

Frequently asked

questions

Yes, if an application exposes endpoints where clients can influence the template name passed into Handlebars.compile(), an attacker can exploit it remotely over the network.

The attacker needs only the ability to send crafted requests to an affected endpoint; no prior authentication is strictly required unless the vulnerable functionality is behind an authenticated interface.

The safest approach is to avoid passing raw user input into template names entirely and instead map user choices to a fixed, whitelisted set of template identifiers, combined with strict path validation and confinement to a non-sensitive template directory.

Adopt a development practice that treats all user-controlled data as untrusted for file and resource paths, enforce centralized path validation, and include path traversal checks in code review, security testing, and automated scanning policies.

Find out what's already
exploitable in your codebase.