Summary toml.parse() converts integer literals (hex, octal, binary, and decimal) to BigInt without first bounding the length of the digit sequence. Since BigInt(string) construction from a very long numeric string runs in super-linear time, a single small, well-formed TOML document containing one long integer literal can pin a Node.js process's event loop at 100% CPU for several seconds — a denial of service for any application that parses attacker-supplied or third-party TOML. No authentication or complex crafting is required.
Details In lib/parser.js, the grammar actions that build integer nodes call BigInt() directly on the matched digit text, with no upper bound on its length:
- lib/parser.js:326 — hex: BigInt('0x' + stripUnderscores(digits)) - lib/parser.js:327 — octal: BigInt('0o' + stripUnderscores(digits)) - lib/parser.js:328 — binary: BigInt('0b' + stripUnderscores(digits)) - lib/parser.js:329 — decimal: BigInt(stripUnderscores(text))
The parser does enforce a nesting-depth limit (MAXDEPTH, default 500, lib/parser.js:4343) to guard against stack overflow from deeply nested arrays/inline tables (per GHSA-82x6-q7mm-w9cf). However, that guard only bounds structural nesting — it does not bound the length of a single scalar token.
The subsequent 64-bit range check in lib/compiler.js (reduceInteger, lines 143–150, comparing against INT64MIN / INT64MAX defined at lines 3–4) happens after the expensive BigInt() conversion has already completed. It therefore provides no protection against this cost — the CPU time is already spent by the time the value is rejected as out of range.
PoC
js const toml = require('toml');
const N = 5000000; // ~5 MB request body const doc = 'x = 0x' + 'f'.repeat(N);
const start = Date.now(); try { toml.parse(doc); // eventually throws "outside the 64-bit signed integer range" — // but only after the costly conversion has run } catch (e) {}
console.log('elapsed:', Date.now() - start, 'ms');
Measured results:
| Digits (hex) | Approx. payload size | Parse time | |---:|---:|---:| | 200,000 | ~200 KB | 141 ms | | 400,000 | ~400 KB | 276 ms | | 800,000 | ~800 KB | 685 ms | | 1,600,000 | ~1.6 MB | 1,761 ms | | 5,000,000 | ~5 MB | 6,061 ms |
Growth is clearly super-linear. The same behavior reproduces for plain decimal literals (3,000,000 '9' digits → ~6.3 s).
Impact Any application that calls toml.parse() on untrusted or third-party input — config upload endpoints, CI/CD tools ingesting user-supplied .toml files, package managers, linters, editors/language servers — is exposed.
During the conversion, the event loop is fully blocked. In a typical single-threaded Node.js server this stalls all concurrent request handling, not just the request containing the malicious payload. A single ~5 MB request is sufficient to cause several seconds of full CPU denial of service.
Suggested fix: Reject digit sequences above a reasonable length before calling BigInt(), analogous to the existing maxDepth option. A 64-bit signed integer requires at most 20 decimal digits or 16 hex digits, so any digit sequence significantly longer than that is guaranteed to fail the existing range check anyway, and can be rejected with a cheap .length comparison instead of paying for the full BigInt conversion.
Summary
toml.parse() is vulnerable to a quadratic-complexity (O(n²)) denial-of-service via a single long dotted key, table header, or inline-table key. A ~100KB crafted document causes a multi-second synchronous hang; a ~200KB document crashes the Node.js process outright with an uncatchable out-of-memory error. This is a separate, unpatched code path from the previously fixed stack-overflow DoS (GHSA-82x6-q7mm-w9cf) — it requires no array/inline-table nesting at all, and is confirmed unaffected by the maxDepth option that fixed that earlier issue.
Affected component / version
- Package: toml (npm), repository BinaryMuse/toml-node - Functions: assign(), deepRef(), setNestedKey() in lib/compiler.js - Confirmed present in the audited checkout at commit 1b2ac40 (2026-07-16), one commit past the v5.0.0 tag (a changelog-only change) — i.e. present in v5.0.0, the latest release. Not exhaustively verified against every prior release, but the affected functions are unrelated to v5.0.0's BigInt/Temporal changes (per CHANGELOG.md), so the defect likely predates that release as well.
Details
toml.parse(input, options) (index.js:5-9) forwards the caller-supplied string to parser.parse() and then compiler.compile() with no length or structural validation. Inside lib/compiler.js, three separate functions each walk a dotted key's segments in a for loop and, on every iteration, recompute the full path-prefix string from scratch:
- assign() (lines 69-107, the sink at line 81): var intermediatePath = makeFullPath(keys.slice(0, i + 1)); — reached for top-level dotted-key assignments like a.b.c = 1. - deepRef() (lines 247-281, the sink at line 252): the identical pattern via pathKey(keys.slice(0, i + 1)) — reached from table headers [a.b.c] and array-of-tables [[a.b.c]] via setPath()/addTableArray(). - setNestedKey() (lines 184-202, the sink at line 187): the identical pattern — reached from inline-table dotted keys like t = { a.b.c = 1 }.
keys.slice(0, i + 1) allocates a new array of length i; pathKey()/makeFullPath() (lines 311-317) then does .map(quoteDottedString).join("."), also O(i). Since this runs on every one of the n segments of a dotted key, total work is O(1 + 2 + ... + n) = O(n²), not O(n). The string is computed unconditionally on the happy path (only ever used if an error is about to be thrown), so there is no early exit that makes this cheap in practice.
No limit exists anywhere on dotted-key segment count: dotendedtablekeypart+ and inlinedotkeypart+ in src/toml.pegjs (lines 122, 311) are unbounded + repetitions, parsed iteratively rather than through the grammar's value rule — so the existing MAXDEPTH/maxDepth nesting guard (src/toml.pegjs:141-151, enforced in the generated lib/parser.js:1022) does not apply to key length at all. We confirmed this directly: setting options.maxDepth: 1 (the strictest possible value) against a 16,000-segment key produced no measurable timing difference from the unrestricted case.
Proof of Concept
js const toml = require('toml');
// n-segment dotted key: "k0.k1.k2. ... .k{n-1} = 1" function segKey(n) { const parts = []; for (let i = 0; i < n; i++) parts.push('k' + i); return parts.join('.') + ' = 1\n'; }
// ~100.9 KB input -- takes ~6.6-6.8 seconds toml.parse(segKey(16000));
// ~200 KB input -- crashes the Node process: // "FATAL ERROR: Ineffective mark-compacts near heap limit - JavaScript heap out of memory" toml.parse(segKey(32000));
Measured timings (Node v22, direct execution against this repo):
| n (segments) | input size | time | |---|---|---| | 1,000 | ~4.9 KB | 34 ms | | 8,000 | ~46.9 KB | 1.6 s | | 16,000 | ~100.9 KB | 6.8 s | | 32,000 | ~200 KB | process crash (OOM) |
Doubling n from 8,000→16,000 roughly quadruples runtime (~4.2x), the signature of O(n²) rather than the expected O(n) (~2x). Independently reproduced with the identical scaling signature for the table-header variant ([k0. ... .k15999], exercising deepRef()) and the inline-table variant (t = { k0. ... .k15999 = 1 }, exercising setNestedKey()).
We also generalized this into a property-based fuzzing harness (fast-check, run under Node) that automatically tests the "doubling input size should not more than roughly double parse time" invariant across 12 structural dimensions of the grammar/compiler; it independently re-flags all three code paths above on every run, with no additional dimension confirmed vulnerable after follow-up investigation. The harness is available on request.
Impact
Node.js is single-threaded — a synchronous multi-second-to-crashing parse() call blocks the entire event loop of the process calling it, stalling every other request/operation that process is handling, not just the attacker's own. At the upper end this is not merely a hang: an uncaught, process-terminating out-of-memory crash from a ~200KB attacker-supplied string is a full denial of service requiring no authentication — just the ability to get one string parsed by an application using this library (config upload, API request body, imported manifest, or any of this library's intended use cases).
Suggested remediation
Build the path prefix as an incrementally-extended string as the loop walks each segment (append one already-quoted segment per iteration to a running string) instead of re-slicing an array and re-joining the entire prefix from scratch on every iteration. For example, in assign():
js function assign(node) { var keys = node.key; var value = node.value; var off = node.offset; if (!Array.isArray(keys)) keys = [keys]; var reduced = reduceValueNode(value);
var target = context; var pathStr = pathKey(currentPath); // computed once, not per segment for (var i = 0; i < keys.length - 1; i++) { var k = keys[i]; var quotedK = quoteDottedString(k); var intermediatePath = pathStr ? pathStr + "." + quotedK : quotedK; // O(new segment), not O(i) pathStr = intermediatePath; // ...same conditional logic as today, using intermediatePath target = target[k]; } // ... }
The identical treatment applies to deepRef() and setNestedKey(). As defense-in-depth, consider also capping total key-segment count or overall input size, the same way maxDepth already caps nesting.
Credit
Discovered and reported by SecDim Security Research secdim.com | @secdim | security@secdim.com
Summary CVE-2026-63376 described prototype pollution through proto key-path desynchronization and was fixed in 4.1.2 by rewriting the path bookkeeping and adding an ownedContainers WeakSet. The desynchronization is still reachable, spelled with a quote character instead of a dot, and the owned-container check is not applied on the path that matters.
A four-line TOML document parsed with toml.parse() writes a property onto Object.prototype, where it is visible to every object in the process — including objects produced by unrelated libraries.
Details Three gaps compose. All line numbers are lib/compiler.js in 5.0.0.
1. The path-key encoding is ambiguous. quoteDottedString() quotes a segment only when it contains a ., and never escapes a " inside the segment:
js 287: function quoteDottedString(str) { 288: if (str.indexOf(".") > -1) { 289: return "\"" + str + "\""; 290: } else { 291: return str; 292: } 293: }
So the key path ['x.y'] and the key path ['"x', 'y"'] both render as the string "x.y". This is the same desynchronization CVE-2026-63376 named, with a quote in place of the dot.
2. A table-array header can clear another key's guard. addTableArray() walks assignedPaths / valueAssignments with isSameOrSubPath() over those ambiguous strings, so a header whose rendered path collides with an unrelated key deletes that key's entry.
3. The descent in assign() has no owned-container check. deepRef() applies isOwnedContainer() only to intermediate segments (lib/compiler.js:265, :273) and returns the final container unchecked. assign() then walks it with only a shape test:
js 93: target = target[k]; ... 103: target[lastKey] = reduced;
A TOML datetime is a Date. It satisfies typeof target[k] === "object" and is not an array, so the walk descends into it — and a Date has a live prototype chain to Object.prototype.
Putting the three together, a document can make the current table a Date and then walk proto.proto to Object.prototype.
bash mkdir poc && cd poc && npm init -y >/dev/null && npm install toml@5.0.0
toml poc.toml "b.c" = 1979-05-27T07:32:00Z [['"b']] ["b.c"] proto.proto.polluted = "yes"
Line 1 defines a key whose rendered path is "b.c" and whose value is a Date. Line 2 is a table-array header whose rendered path collides with it, clearing its guard. Line 3 re-enters that key, so the current table is now the Date. Line 4 walks Date → Date.prototype → Object.prototype.
js // poc.js const toml = require('toml'); const fs = require('fs');
console.log('before:', JSON.stringify(({}).polluted)); toml.parse(fs.readFileSync('poc.toml', 'utf8')); console.log('after: ', JSON.stringify(({}).polluted)); console.log('Object.prototype.hasOwnProperty("polluted") =', Object.prototype.hasOwnProperty('polluted')); console.log('JSON.parse("{}").polluted =', JSON.stringify(JSON.parse('{}').polluted));
$ node poc.js before: undefined after: "yes" Object.prototype.hasOwnProperty("polluted") = true JSON.parse("{}").polluted = "yes"
The payload sets a single harmless marker property. The last line shows the property is visible on an object this code never touched.
A useful control: the same document without line 2 (the guard-clearing header) is correctly rejected on 4.1.2 and later, which confirms the clearing step is what is load-bearing.
Impact
Any application that parses a TOML document from an untrusted source is affected — a configuration file uploaded by a user, a manifest from a third-party package or repository, a document posted to an API. Prototype pollution of this kind commonly escalates to authentication or authorization bypass, denial of service, and in applications with a suitable gadget, remote code execution, because every object in the process inherits the injected property.
Suggested fix: in assign(), apply the same check the intermediate descent already uses — after target = target[k], reject when !isOwnedContainer(target). Equivalently, apply isOwnedContainer to the value deepRef() returns. Separately, quoteDottedString() should escape " inside a segment so that distinct key paths cannot render to the same string.
Summary
toml.parse() is vulnerable to a quadratic-complexity (O(n²)) denial-of-service via many array-of-tables ([[name]]) headers. addTableArray() in lib/compiler.js rescans two entire bookkeeping Sets on every [[name]] header without pruning unrelated or distinct entries, so a document containing n such headers costs O(n²) compiler work. A ~321KB document of 20,000 distinct-named [[name]] blocks takes ~10.3 seconds to parse — a completely ordinary-looking TOML shape (a flat settings block plus one or more array-of-tables sections), not a contrived edge case. This is a separate, unpatched code path from the previously fixed stack-overflow DoS (GHSA-82x6-q7mm-w9cf) and requires no key nesting or dotted keys at all.
Affected component / version
- Package: toml (npm), repository BinaryMuse/toml-node - Function: addTableArray() in lib/compiler.js - Confirmed present in the audited checkout at commit 1b2ac40 (2026-07-16), one commit past the v5.0.0 tag (a changelog-only change) — i.e. present in v5.0.0, the latest release. Not exhaustively verified against every prior release, but the affected function is unrelated to v5.0.0's BigInt/Temporal changes (per CHANGELOG.md), so the defect likely predates that release as well.
Details
toml.parse(input, options) (index.js:5-9) forwards the caller-supplied string to parser.parse() and then compiler.compile() with no length or structural validation. Every [[name]] (array-of-tables) header is routed (reduce(), lib/compiler.js:43) to addTableArray() (lib/compiler.js:218-245), which performs two full linear scans on every call:
js assignedPaths.forEach(function(p) { if (isSameOrSubPath(p, quotedPath)) assignedPaths.delete(p); }); valueAssignments.forEach(function(p) { if (isSameOrSubPath(p, quotedPath)) valueAssignments.delete(p); }); (lib/compiler.js:228-233)
assignedPaths and valueAssignments accumulate one entry per top-level key/table/array path ever assigned in the entire document. Each scan prunes only entries matching the currently reopened path via isSameOrSubPath() (lib/compiler.js:319-321: path === prefix || path.indexOf(prefix + ".") === 0); anything else — an unrelated top-level key, or simply a different array-of-tables name — is never removed and is rescanned in full on every subsequent [[name]] header for the rest of the parse. Set.prototype.forEach has no early exit, so this is unconditionally O(current Set size) on every call, giving O(n²) total work for n such headers.
Proof of Concept
The sharpest reproduction needs no unrelated keys at all — just N array-of-tables headers with N distinct names, since nothing is ever pruned when no name repeats:
js const toml = require('toml');
function distinctArrayHeaders(n) { let out = ''; for (let i = 0; i < n; i++) out += [[a${i}]]\nv = 1\n; return out; }
// ~321 KB input -- takes ~10.3 seconds toml.parse(distinctArrayHeaders(20000));
Measured timings (Node, direct execution against this repo):
| Variant | n | input size | time | |---|---|---|---| | N distinct-named [[name]] headers, no unrelated keys | 20,000 | 321 KB | 10.3 s | | Same N with all-same-name headers (self-pruning, control) | 20,000 | 240 KB | 78 ms | | M unrelated top-level keys + N same-name [[name]] headers | M=N=32,000 | 906 KB | 42.3 s |
The ~130x gap between the distinct-name and same-name cases at identical N and comparable input size isolates the mechanism precisely: the bug is unbounded Set growth from never-pruned entries, not string length or any other confound. A product-law check (varying M and N independently in the mixed variant) further confirmed genuine O(M·N) complexity.
Impact
Node.js is single-threaded — this synchronous, multi-second-to-tens-of-seconds compile blocks the entire process event loop, standard uncontested Node.js behavior. The triggering document shape — flat top-level config keys plus one or more array-of-tables sections (e.g. a [db] settings block plus a [[servers]] list) — is unremarkable, common real-world TOML, not an edge case. No authentication or special access is required; only the ability to get one TOML string parsed by an application using this library.
Suggested remediation
Avoid scanning the entire assignedPaths/valueAssignments Sets on every [[name]] header. Index entries by their top-level path segment (e.g. a Map<string, Set<string>> keyed by the first key component) so addTableArray() only ever scans the bucket relevant to the path being reopened, in time proportional to that bucket's size rather than the whole document's accumulated path count:
js var assignedByRoot = new Map(); // root segment -> Set<fullPath>
function addTableArray(node) { var path = node.value; var root = path[0]; var bucket = assignedByRoot.get(root) || new Set(); bucket.forEach(function(p) { if (isSameOrSubPath(p, quotedPath)) bucket.delete(p); }); // ...rest of addTableArray unchanged, reading/writing the per-root bucket // instead of the global assignedPaths/valueAssignments Sets }
As with the sibling finding, an input-size or table-count limit would also help as defense-in-depth.
Credit
Discovered and reported by SecDim Security Research secdim.com | @secdim | security@secdim.com