File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -385,9 +385,12 @@ module.exports = {
385
385
}
386
386
}
387
387
388
- let courseStructureData = helpers . sanitizeXML ( courseStructureDataRaw ) ;
389
- if ( courseStructureData != undefined && helpers . isPotentiallyMaliciousXML ( courseStructureData ) ) {
390
- throw Boom . internal ( `Invalid XML data provided: ${ ex } ` ) ;
388
+ let courseStructureData = await helpers . sanitizeXML ( courseStructureDataRaw ) ;
389
+ if ( courseStructureData != undefined ) {
390
+ let seemsOdd = await helpers . isPotentiallyMaliciousXML ( courseStructureData ) ;
391
+ if ( seemsOdd ) {
392
+ throw Boom . internal ( `Invalid XML data provided: ${ ex } ` ) ;
393
+ }
391
394
}
392
395
393
396
let courseStructureDocument ;
Original file line number Diff line number Diff line change @@ -7,8 +7,9 @@ const fs = require("fs");
7
7
8
8
const helpers = require ( "../plugins/routes/lib/helpers" ) ;
9
9
const chai = require ( "chai" ) ;
10
+ const exp = require ( "constants" ) ;
10
11
11
- describe ( "Libxmljs Usage" , async ( ) => {
12
+ describe ( "XML Parsing and Usage" , async ( ) => {
12
13
13
14
/**
14
15
* https://www.stackhawk.com/blog/nodejs-xml-external-entities-xxe-guide-examples-and-prevention/
@@ -22,4 +23,14 @@ describe("Libxmljs Usage", async () => {
22
23
23
24
chai . expect ( suspicious ) . to . be . equal ( true , "The provided XML should have thrown a validity issue for its use of an <!ENTITY tag" ) ;
24
25
} ) ;
26
+
27
+ it ( "Sanitizes malicious characters out of the XML body" , async ( ) => {
28
+
29
+ let providedText = '\u0000Some text\u0000🎉🎉\u0000' ;
30
+ let expectedText = 'Some text' ;
31
+
32
+ let parsedText = await helpers . sanitizeXML ( providedText ) ;
33
+
34
+ chai . expect ( parsedText ) . to . be . equal ( expectedText , "The provided XML was not parsed into the expected text" ) ;
35
+ } ) ;
25
36
} ) ;
You can’t perform that action at this time.
0 commit comments