Skip to content

Commit 5bd28e7

Browse files
authored
refactor: XML validator explicitely harden against XXE injections (#1064)
## Changed * The provided XML validation capabilities are hardened (via [#1064]; concerns [#1061]) This is considered a security measure concerning XML external entity (XXE) injection. [#1061]: #1061 [#1064]: #1064 ---- This is not an actual change. Per default, the XML validation capabilities were already secure in the intended ways. This is to prevent the fuckup like in the yanked v6.7.0 --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent e7bc72e commit 5bd28e7

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

HISTORY.md

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66

77
<!-- add unreleased items here -->
88

9+
* Changed
10+
* The provided XML validation capabilities are hardened (via [#1064]; concerns [#1061])
11+
This is considered a security measure concerning XML external entity (XXE) injection.
12+
13+
[#1061]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1061
14+
[#1064]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1064
15+
916
## 6.7.1 -- 2024-05-07
1017

1118
Reverted v6.7.0, back to v6.6.1

src/validation/xmlValidator.node.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ async function getParser (): Promise<typeof parseXml> {
4848

4949
const xmlParseOptions: Readonly<ParserOptions> = Object.freeze({
5050
nonet: true,
51-
compact: true
51+
compact: true,
52+
// explicitly prevent XXE
53+
// see https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
54+
noent: false,
55+
dtdload: false
5256
})
5357

5458
export class XmlValidator extends BaseValidator {

tests/_data/xxe_flag.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This file is target of XXE injection tests.
2+
The flag is:
3+
4+
vaiquia2zoo3Im8ro9zahNg5mohwipouka2xieweed6ahChei3doox2fek3ise0lmohju3loh5oDu7eigh3jaeR2aiph2Voo

tests/integration/Validation.XmlValidator.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

2020
const assert = require('assert')
21+
const { realpathSync } = require('fs')
22+
const { join } = require('path')
23+
const { pathToFileURL } = require('url')
24+
2125
const { describe, it } = require('mocha')
2226

2327
let hasDep = true
@@ -99,5 +103,32 @@ describe('Validation.XmlValidator', () => {
99103
const validationError = await validator.validate(input)
100104
assert.strictEqual(validationError, null)
101105
})
106+
107+
it('is not affected by XXE injection', async () => {
108+
const validator = new XmlValidator(version)
109+
const input = `<?xml version="1.0" encoding="UTF-8"?>
110+
<!DOCTYPE poc [
111+
<!ENTITY flag SYSTEM "${pathToFileURL(realpathSync(join(__dirname, '..', '_data', 'xxe_flag.txt')))}">
112+
]>
113+
<bom xmlns="http://cyclonedx.org/schema/bom/${version}">
114+
<components>
115+
<component type="library">
116+
<name>bar</name>
117+
<version>1.337</version>
118+
${version === '1.0' ? '<modified>false</modified>' : ''}
119+
<licenses>
120+
<license>
121+
<id>&flag;</id>
122+
</license>
123+
</licenses>
124+
</component>
125+
</components>
126+
</bom>`
127+
const validationError = await validator.validate(input)
128+
assert.doesNotMatch(
129+
JSON.stringify(validationError),
130+
/vaiquia2zoo3Im8ro9zahNg5mohwipouka2xieweed6ahChei3doox2fek3ise0lmohju3loh5oDu7eigh3jaeR2aiph2Voo/
131+
)
132+
})
102133
}))
103134
})

0 commit comments

Comments
 (0)