Repository navigation
Conversation
…YPE entity replacement Refs NaturalIntelligence#922 - OptionsBuilder/TagPathMatcher: use default imports (the modules only have default exports), so src/v6 is importable again - importTests/v6: drop the duplicate import (syntax error) - EntitiesParser: range-check numeric character references before String.fromCodePoint() and leave out-of-range references untouched, mirroring v5's fromCodePoint() (� threw RangeError) - EntitiesParser: fix entity.regx typo so DOCTYPE-declared entities are replaced (and the literal text "undefined" is no longer corrupted) - EntitiesParser: replace the undefined reportWarning() call in addExternalEntity with console.warn (external entity with & in value threw ReferenceError) - ParserOptionsBuilder: read options.preserveOrder instead of this.preserveOrder in buildOptions (TypeError on import of v6)
Member
|
Please read docs. Use Flexible XML Parser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #922 — fixes all six findings from the v6 audit. Each was reproduced against current
master(5.12.1, 88b816b) before and after the change.What was broken (all in
src/v6/, unreachable from the package entry today)OptionsBuilder.jsimported the named exportJsObjOutputBuilder, butOutputBuilders/JsObjBuilder.jsonly has a default export → any import ofsrc/v6/XMLParser.jsfailed at link time.TagPathMatcher.js:1did a named import ofTagPath, which likewise only has a default export →Xml2JsParser.jsfailed to import.spec/importTests/v6/import_test.jshad the same import line twice (syntax error), so the one test that would have caught Wrong output #1/Update .codeclimate.yml #2 never ran.EntitiesParser.jscalledString.fromCodePoint()without a range check; the regexes allow up to 7 decimal / 6 hex digits, so�(12 bytes of untrusted input) threwRangeError: Invalid code pointand crashed the parse. Now range-checked, and out-of-range references are left untouched — mirroring v5'sfromCodePoint()inOrderedObjParser.js.EntitiesParser.js:78readentity.regx(typo) instead ofentity.regex.String.prototype.replace(undefined, x)treatsundefinedas the literal string "undefined", so DOCTYPE-declared entities were never replaced and any literal wordundefinedin the text was silently replaced by the entity value.EntitiesParser.js:42calledreportWarning(), which is not defined or imported anywhere, so registering an external entity whose value contains&threwReferenceError. Replaced withconsole.warn, the warning channel used elsewhere in the codebase (src/cli/cli.js).One extra fix the import repairs uncovered
With #1/#2 fixed, module evaluation of
OptionsBuilder.jsreachesnew JsObjOutputBuilder()→buildOptions(), which readthis.preserveOrderin a plain exported function (thisisundefinedin ESM) →TypeErroron import. Changed to readoptions.preserveOrder(undefined-safe). Without this, finding #3's import test still fails.Out of scope, for later:
src/v6/valueParsers/EntitiesParser.jsis a stale duplicate ofEntitiesParser.jswith the samereportWarningbug, but nothing imports it; andbuildOptions's shallow{ ...defaultOptions }clone aliases the sharedtags.valueParsersarray, so repeated parser construction accumulates duplicate value parsers. Happy to follow up on either if you want.Verification
npm test→ 343 specs, 0 failures (2 pending are pre-existingxit)new XMLParser().parse('<root><item id="1">hello & world</item>…')→ correct tree�/�left as-is (no RangeError), in-rangeA/Astill decode toA; DOCTYPE entity&myent;replaced, literalundefineduntouched;addExternalEntity('bad', 'a&b')warns and skips instead of throwing...spread) exist identically on master — no new lint issues