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
ssgParamsrather 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.

