feat: XML Validator prevent parsing XXE#1063
Conversation
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
|
@artola please review |
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more Footnotes
|
|
https://research.jfrog.com/vulnerabilities/libxmljs2-namespaces-type-confusion-rce-jfsa-2024-001034098/#poc reports DOS via payload const libxmljs2 = require('libxmljs2');
var d = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note
[
<!ENTITY writer PUBLIC "` + "A".repeat(8) + "B".repeat(8) + "C".repeat(8) + "D".repeat(8) + "P".repeat(8) + `" "JFrog Security">
]>
<from>&writer;</from>
`;
t = libxmljs2.parseXml(d)
from = t.get('//from')
c = from.childNodes()[0]
c2 = c.childNodes()[0] //entity_decl
n = c2.namespaces(true) //onlyLocal = truetested, acknowledged. to prevent this, the following parser options were used: Object.freeze({
nonet: true,
compact: true,
noent: false // prevent https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061
/* !!! do not set to true.
setting true would enable XXE.
the oposite is the intended solution
*/
})see https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1063/files#r1592446370 fixed code: const libxmljs2 = require('libxmljs2');
var d = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note
[
<!ENTITY writer PUBLIC "` + "A".repeat(8) + "B".repeat(8) + "C".repeat(8) + "D".repeat(8) + "P".repeat(8) + `" "JFrog Security">
]>
<from>&writer;</from>
`;
var po = Object.freeze({
nonet: true,
compact: true,
noent: false // prevent https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061
})
t = libxmljs2.parseXml(d, po)
from = t.get('//from')
c = from.childNodes()[0]
c2 = c.childNodes()[0] //entity_decl
n = c2.namespaces(true) //onlyLocal = true This code does not cause a DOS anymore, nor does it open any sockets or such... I consider this a fix. Therefore: fixes #1061 |
|
Great work @jkowalleck! I found this when I was researching on how to prevent the parsing vulnerabilities following up on CVE-2024-34393.
|
|
yes, the
|
|
FYI: this fix will be resulting an security advisory: GHSA-38gf-rh2w-gmj7 |
|
!!! REVERTED !!! instead of preventing XXE, it actually enabled it. |
|
I was wrong. This library was not affected by XXE in the first place. |
| nonet: true, | ||
| compact: true | ||
| compact: true, | ||
| noent: true // prevent https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061 |
There was a problem hiding this comment.
noent: true means substitute entities.
Omitting this option is the secure default.
There was a problem hiding this comment.
exactly.
therefore GHSA-38gf-rh2w-gmj7 exists,
and the #1064 introduced test for this
prevent the XmlValidation from XXE parsing - prevent XML external entity (XXE) injection
This is considered a security measure.
fixes #1061 as described here: #1063 (comment)