Skip to content

v6 (src/v6): 2 broken imports, uncaught RangeError on �, regx typo replacing literal 'undefined' #922

Closed

Description

@hicay

v6 parser: 6 issues found while auditing src/v6/ (2 blockers, 1 crash, 1 data corruption)

While auditing the parser for input-handling bugs, I found six issues in the v6 code under src/v6/. Since v6 is not yet reachable from the package entry point (package.json exports only .), none of these affect v5 users today — but four of them will matter before v6 is wired up.

Blockers: v6 cannot currently be imported

1. OptionsBuilder.js:2 — named import that doesn't exist

import { JsObjOutputBuilder } from './OutputBuilders/JsObjBuilder.js';

JsObjBuilder.js only has a default export (export default class OutputBuilder). Any import of src/v6/XMLParser.js fails immediately.

2. Xml2JsParser.js — named import TagPath that doesn't exist

import('./src/v6/Xml2JsParser.js')
→ The requested module './TagPath.js' does not provide an export named 'TagPath'

3. spec/importTests/v6/import_test.js — duplicate import (syntax error)

import XMLParser from "fast-xml-parser/src/v6/XMLParser";
import XMLParser from "fast-xml-parser/src/v6/XMLParser";  // ← duplicate

This means the one test that would have caught #1 and #2 has never run.

Crash: missing codepoint range check (regression vs v5)

4. EntitiesParser.js:16-17 — String.fromCodePoint() without range validation

"num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },

v5's OrderedObjParser.fromCodePoint() explicitly checks cp >= 0 && cp <= 0x10FFFF before calling String.fromCodePoint(), and @nodable/entities does the same in its _resolveNCR() (NaN || cp < 0 || cp > 0x10FFFF → leave as-is). v6 has no such check:

> new V6EntitiesParser(true).replaceEntitiesValue('a&#9999999;b')
RangeError: Invalid code point 9999999

> new V6EntityParser(true).replaceEntitiesValue('a&#xFFFFFF;b')
RangeError: Invalid code point 16777215

Regex bounds {1,7} / {1,6} are too permissive: 9999999 > 0x10FFFF and 0xFFFFFF > 0x10FFFF. Untrusted input of &#9999999; (12 bytes) crashes the parse — a DoS vector, and a re-opening of a class of bug v5 already fixed.

Data corruption: regx typo in entity replacement

5. EntitiesParser.js:78 — entity.regx instead of entity.regex

for (let entityName in this.docTypeEntities) {
  const entity = this.docTypeEntities[entityName];
  val = val.replace(entity.regx, entity.val);   // ← regx: always undefined
}

Entities are stored under regex (line 58) but read as regx (line 78). Because String.prototype.replace(undefined, replacement) coerces undefined to the string "undefined" and treats it as a literal substring search, two things go wrong:

  1. DOCTYPE-declared entities are never replaced (silent no-op), and
  2. any occurrence of the literal word undefined in the text gets replaced by the entity's value:
const p = new V6EntityParser(true);
p.addDocTypeEntities({ myent: 'REPLACED' });
p.replaceEntitiesValue('hello &myent; world')
// → "hello &myent; world"          (entity not replaced)
p.replaceEntitiesValue('value is undefined here')
// → "value is REPLACED here"       (text silently corrupted)

Crash: undefined function reference

6. EntitiesParser.js:42 — reportWarning() is not defined

addExternalEntity() calls reportWarning(...) on the &-in-value path, but no such function is imported or defined in the module. Result: registering an external entity whose value contains & throws ReferenceError: reportWarning is not defined (and skips adding the entity). Note addDocTypeEntities() has no & check at all — which may be intentional, but the asymmetry looks accidental.

Suggested fixes

  1. Wrong output #1/Update .codeclimate.yml #2: fix the named imports (or add named exports).
  2. parse fail to get attribute #3: dedupe the import line in the test.
  3. no validate function #4: validate the parsed codepoint before calling String.fromCodePoint() — mirror v5's fromCodePoint() or @nodable/entities' _resolveNCR() and leave the entity as-is (or substitute U+FFFD) when out of range.
  4. Can't get CDATA section content #5: rename regx → regex.
  5. Removed whitespace at startup #6: import/define reportWarning (or use the same warning channel the rest of the file uses).

I have verified all four runtime behaviors (import failures, both crashes, and the undefined-replacement) against v5.12.1 / current src/v6/. Happy to send a PR for any subset of these if useful.

Environment

  • fast-xml-parser 5.12.1 (tag), src/v6/ at that commit
  • Node 22.21.0

Activity

  1. github-actions commented on Nov 13, 2026

    @github-actions

    We're glad you find this project helpful. We'll try to address this issue ASAP. You can join Discord channel(https://discord.gg/X4Qp9u6Vz) for anonucements and pre release discussions. Don't forget to star this repo.

  2. amitguptagwl commented on Nov 14, 2026

    @amitguptagwl
    Member

    plz read docs. v6 is not supported. Use flexible xml parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions