diff --git a/HISTORY.md b/HISTORY.md index 67e42f946..30ddf7ea1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. +* Changed + * The provided XML validation capabilities no longer supports external entities (via [#1063]; concerns [#1061]) + This is considered a security measure to prevent XML external entity (XXE) injection. + +[#1061]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061 +[#1063]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1063 + ## 6.6.1 -- 2024-05-06 * Fixed diff --git a/src/validation/xmlValidator.node.ts b/src/validation/xmlValidator.node.ts index 667657ad0..08601be69 100644 --- a/src/validation/xmlValidator.node.ts +++ b/src/validation/xmlValidator.node.ts @@ -48,7 +48,8 @@ async function getParser (): Promise { const xmlParseOptions: Readonly = Object.freeze({ nonet: true, - compact: true + compact: true, + noent: true // prevent https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061 }) export class XmlValidator extends BaseValidator { diff --git a/tests/integration/Validation.XmlValidator.test.js b/tests/integration/Validation.XmlValidator.test.js index 17a273aa8..bbdf6bd9e 100644 --- a/tests/integration/Validation.XmlValidator.test.js +++ b/tests/integration/Validation.XmlValidator.test.js @@ -99,5 +99,59 @@ describe('Validation.XmlValidator', () => { const validationError = await validator.validate(input) assert.strictEqual(validationError, null) }) + + it('is not vulnerable to advisories/GHSA-mjr4-7xg5-pfvh', async () => { + /* report: + see https://github.com/advisories/GHSA-mjr4-7xg5-pfvh + see https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061 + */ + const validator = new XmlValidator(version) + /* POC payload: + see https://research.jfrog.com/vulnerabilities/libxmljs2-attrs-type-confusion-rce-jfsa-2024-001034097/#poc + */ + const input = ` + + ]> + + + + &writer; + 1.337 + ${version === '1.0' ? 'false' : ''} + + + ` + const validationError = await validator.validate(input) + assert.strictEqual(validationError, null) + }) + + it('is not vulnerable to advisories/GHSA-78h3-pg4x-j8cv', async () => { + /* report: + see https://github.com/advisories/GHSA-78h3-pg4x-j8cv + see https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061 + */ + const validator = new XmlValidator(version) + /* POC payload: + see https://research.jfrog.com/vulnerabilities/libxmljs2-namespaces-type-confusion-rce-jfsa-2024-001034098/#poc + */ + const input = ` + + ]> + + + + &writer; + 1.337 + ${version === '1.0' ? 'false' : ''} + + + ` + const validationError = await validator.validate(input) + assert.strictEqual(validationError, null) + }) })) })