/

CVE-2026-39408

Severity:

HIGH RISK

(7.5)

Path Traversal in Hono toSSG()

CVE-2026-39408

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Intended Directory

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

A path traversal issue in Hono's toSSG() static site generation function can allow generated files to be written outside the configured output directory when dynamic route parameters are used.

By supplying specially crafted ssgParams values, an attacker who controls these parameters may cause the static generator to escape the intended output directory and write files to unintended locations on the host system.

Affected context

This vulnerability affects applications using Hono's static site generation (toSSG()) feature in configurations where:

  • Dynamic route parameters are used to generate pages via ssgParams
  • Generated file paths are derived directly or indirectly from user-influenced route parameters
  • The static output directory path is assumed to be enforced solely by application logic rather than by robust path normalization and validation

In such setups, static generation can produce files whose resolved paths escape the configured output directory, depending on how route parameters are sourced and managed.

Exploit preconditions

  • Attack surface: Static site generation pipeline using Hono's toSSG() function.
  • Required access: Ability to control or influence values passed as ssgParams (e.g., configuration, build-time inputs, or other parameter sources used for dynamic routes).
  • Trigger point: Invoking toSSG() with dynamic routes whose parameters contain crafted path traversal sequences (for example, sequences that manipulate directory structure).
  • Why exploitation is possible: The implementation trusts route parameters when constructing output file paths and does not sufficiently normalize or constrain them to the configured output directory, enabling traversal outside the intended path.

Why this happens

The underlying issue is improper constraint of file paths derived from dynamic parameters, corresponding to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

In this pattern, parts of a filesystem path are built from untrusted input (here, values from ssgParams used for dynamic routes) without robust normalization, canonicalization, and enforcement that the final resolved path remains within a designated output directory.

As a result, specially crafted parameter values can alter the effective directory structure and cause the static generator to write files outside the intended output folder.

Potential impact

  • Generated files may be written to directories outside the intended static output folder.
  • Existing files in writable locations could be overwritten by generated content.
  • Application or build infrastructure configuration files located in writable paths could be modified, potentially affecting deployment behavior.
  • In multi-tenant or shared build environments, other projects' directories could be impacted if they reside under writable parent paths.

General mitigation guidance

Effective mitigation focuses on isolating file generation from untrusted input and enforcing strict directory boundaries:

  • Normalize and canonicalize all file paths derived from route parameters before writing, and verify that the resolved path remains under the configured output directory.
  • Implement a strict mapping from route parameters to filenames (e.g., whitelisting allowed characters, rejecting path separators and traversal tokens).
  • Use a centralized helper for path construction that treats the output directory as a fixed root and prevents relative segments from escaping it.
  • Run static generation in a restricted environment or dedicated container with limited filesystem permissions so that even if traversal is attempted, sensitive areas remain unwritable.
  • Prefer configuration-driven or prevalidated parameter sets for ssgParams rather than values directly derived from untrusted runtime input.

How teams detect issues like this

Organizations can detect this type of issue through a combination of code and build pipeline reviews:

  • Static analysis: Look for file write operations in the SSG code path that directly concatenate or interpolate route parameters, ssgParams, or other untrusted values into filesystem paths without normalization or bounds checking.
  • Code review signals: Verify that all usage of toSSG() and related utilities rely on safe path-joining helpers, reject path traversal patterns, and enforce that generated paths are children of the configured output directory.
  • Build-time checks: Add tests or CI scripts that attempt to generate pages using crafted parameters and verify that no files appear outside the expected output directory.
  • Automated tools: Static application security testing (SAST) tools or custom lint rules can be configured to flag dynamic path construction where user-influenced data is used in file write operations.

Sources

SourceLink
github.comgithub.com/honojs/hono/commit/b470278920fffcfd6d76002755d6db53db827679
github.comgithub.com/honojs/hono/releases/tag/v4.12.12
github.comgithub.com/honojs/hono/security/advisories/GHSA-xf4j-xp2r-rqqx

Frequently asked

questions

It depends on how ssgParams are sourced. If build-time parameters are derived directly from user-controllable input (e.g., API data that incorporates user values), remote influence is possible. If ssgParams are purely internal and not impacted by external input, the risk is limited to whoever controls the build configuration.

An attacker needs the ability to influence or control the values used as ssgParams for dynamic routes during static site generation. This could be through direct access to build configuration, manipulation of upstream data sources, or any other mechanism that feeds into parameter generation.

The safest pattern is to treat all path fragments derived from parameters as untrusted: normalize and canonicalize paths, strictly restrict allowed characters, and enforce that the final resolved path is inside the designated output directory. Centralizing path construction and validation logic reduces the risk of individual call sites making mistakes.

Adopt a defense-in-depth approach for filesystem operations: never join untrusted input directly into paths, always validate resolved paths against an allowed root, add automated tests for traversal attempts, and include security-focused code review checks around any static generation, build tooling, or file-writing functionality that processes dynamic parameters.

Find out what's already
exploitable in your codebase.