GHSA-J4CP-CC36-JXWG
Exponential backtracking in the multi-line basic string grammar lets a ~100-byte document hang the event loop
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-J4CP-CC36-JXWG divulgada · CVSS 7.5 (GitHub) | |
| Remediación | Parche 1.2.2 | js-toml · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
An unterminated multi-line basic string containing a run of line-ending backslashes makes `load()` backtrack exponentially. Under 100 bytes of input blocks the event loop for about nine seconds, and each further three bytes doubles that.
Details
`multiLineBasicEscapedNewline` in `src/load/tokens/MultiLineBasicString.ts` was:
{{escape}}{{whiteSpace}}{{newline}}({{whiteSpaceChar}}|{{newline}})*The trailing `({{whiteSpaceChar}}|{{newline}})*` is ambiguous with the enclosing `{{multiLineBasicContent}}*` loop, which matches the same characters: `{{newline}}` directly, and spaces and tabs through `basicUnescaped`. Every whitespace character following the escaped newline can be consumed at either level.
While a match succeeds this costs nothing. When the overall match must fail, which is what an unterminated string forces, the engine enumerates every composition of the whitespace run before giving up.
Impact
Any application calling `load()` on TOML it did not author. In practice that means services accepting TOML uploads, and build or CI systems parsing TOML out of untrusted repositories. An application reading its own configuration file from disk is not exposed.
Measured on Node v22.22.3, payload `x = """` followed by `\<newline><space>` repeated n times:
67 B 45 ms
79 B 128 ms
85 B 508 ms
91 B 2105 ms
97 B 8631 msCost doubles roughly every three bytes added. Extrapolating, about 133 bytes reaches ten hours and about 163 bytes exceeds a year. The hang is a busy loop inside the lexer, so it is not interruptible and the process must be killed.
The distinguishing property is that damage is unbounded at trivial input size. A request-size limit, which caps a size-proportional CPU bug proportionally, gives no protection here.
The same input is also reachable in array and inline-table value positions. Tabs work as well as spaces. Multi-line literal strings (`'''`) are unaffected: they have no escape rule and therefore no ambiguity.
Proof of concept
const { load } = require('js-toml');
load('x = """' + '\\\n '.repeat(30)); // about 9 s, 100 bytesPatch
Drop the trailing group:
{{escape}}{{whiteSpace}}{{newline}}The accepted language is unchanged. The lexer pattern never performed line-ending-backslash trimming: `unescapeString` in `src/load/tokens/utils.ts` re-matches the whitespace run at interpretation time and does the trimming there. The enclosing content loop already absorbs the whitespace and newlines the group used to claim.
After the fix the 100-byte payload parses in about 0.05 ms, and a 60 kB version in about 11 ms.
Workarounds
None within the library for affected versions. Upgrade to 1.2.2. Callers that cannot upgrade and that parse untrusted input can reject documents containing `"""` before parsing, which is coarse but effective.
Credit
Found by the maintainer while triaging an unrelated report.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmjs-toml |
Corregida | 1.2.2 | 0 d | 2.0.1 no afectada |
1.2.2Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/sunnyadn/js-toml/security/advisories/GHSA-j4cp-cc36-jxwgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
