Summary
i18next-fs-backend previously interpolated user-controllable language (lng) and namespace (ns) values directly into file paths without validation, enabling path traversal.
When these values are derived from untrusted HTTP input, an attacker can craft values that cause the backend to read or overwrite arbitrary files outside the intended locales directory.
Affected context
This vulnerability arises in Node.js or Deno applications using i18next-fs-backend where:
- The backend is configured with
loadPathand/oraddPathtemplates that incorporate{{lng}}and{{ns}}. lngand/ornsvalues can be influenced directly or indirectly by end users (for example via i18next-http-middleware, query strings, cookies, or headers).- No additional server-side validation or normalization is applied to constrain these values to known-safe locale and namespace identifiers.
In such setups, a malicious value containing path traversal sequences, path separators, or extremely long strings can divert file operations away from the designated translation directory.
Exploit preconditions
- Attack surface: Web-facing applications that expose language or namespace selection via HTTP (query parameters, cookies, headers, or route parameters) and use i18next-fs-backend for filesystem-based translations.
- Required access: Ability to send requests that influence
lngand/ornsvalues; no application-level authentication may be required if language selection is public. - Trigger point: Any request that causes i18next-fs-backend to resolve
loadPathoraddPathwith attacker-controlledlng/nsand then perform a filesystem read or write. - Why exploitation is possible: The backend directly interpolates
lngandnsinto file path templates without encoding, normalization, or validation, allowing directory traversal (../), control characters, or crafted keys to escape the intended locale directory and target arbitrary filesystem paths.
Why this happens
The core issue is improper neutralization of user input when constructing filesystem paths.
i18next-fs-backend takes lng and ns values and substitutes them into the configured loadPath / addPath templates, then uses the resulting string as a path for read or write operations.
Because these values are treated as trusted and are neither normalized nor restricted to an allowed set, adversaries can embed .., path separators, or other special sequences to traverse out of the locale directory and interact with arbitrary files on the host.
This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') and is closely related to CWE-73: External Control of File Name or Path, where external input controls what file is opened.
Potential impact
- Read access to sensitive files such as
/etc/passwd, application configuration files, or API keys, depending on process permissions. - Overwriting or corrupting files reachable by the application user, potentially affecting logs, translation files, or other application data.
- Indirect information disclosure about the filesystem layout and environment through error messages or timing.
- Facilitation of further attacks if overwritten files are later interpreted as code, templates, or configuration by other components.
General mitigation guidance
Defensive strategies focus on constraining and sanitizing all data that influences filesystem paths and avoiding direct string interpolation:
- Treat
lngandnsas untrusted and normalize them before usage: enforce strict whitelists of allowed language codes and namespace identifiers and reject unknown or malformed values. - Avoid directly interpolating raw user-controlled values into file path templates; instead, resolve requested languages and namespaces to known-safe directory names or IDs.
- Use path-joining and normalization utilities that operate on canonicalized paths and then enforce a rule that the final path must remain within a designated base directory (for example, the locales root).
- Impose maximum length and character-set constraints on
lngandnsto prevent abuse with extremely long or control-character-laden inputs. - Run the application under least-privilege accounts with minimal filesystem access so that even if a path escapes the intended directory, the set of readable and writable targets is limited.
How teams detect issues like this
Organizations can pursue multiple approaches to detect this pattern and similar issues:
- Static analysis: Define rules that flag direct concatenation or template substitution of external input into file paths, particularly around i18next-fs-backend configuration (
loadPath,addPath) and anyfsor Deno filesystem calls. - Configuration review: During code review, examine translation backend configuration to ensure
lng/nsare not used raw and that there is a validation or mapping layer between HTTP-level inputs and filesystem paths. - Runtime monitoring: Instrument logging for suspicious path access patterns, such as requests attempting to reach
../, absolute paths, or non-locale directories; set alerts for repeated traversal attempts. - Security testing: Incorporate automated tests or dynamic scanners that attempt language and namespace values containing
../, path separators, or overly long values and verify that access outside the locale directory is blocked.

