@@ -28,6 +28,7 @@ const uuidv4 = require("uuid").v4;
28
28
const Helpers = require ( "../lib/helpers" ) ;
29
29
const Registration = require ( "../lib/registration" ) ;
30
30
const Session = require ( "../lib/session" ) ;
31
+ const helpers = require ( "../lib/helpers" ) ;
31
32
const readFile = util . promisify ( fs . readFile ) ;
32
33
const copyFile = util . promisify ( fs . copyFile ) ;
33
34
const mkdir = util . promisify ( fs . mkdir ) ;
@@ -349,7 +350,7 @@ module.exports = {
349
350
//
350
351
isZip = contentType === "application/zip" || contentType === "application/x-zip-compressed" ;
351
352
352
- let courseStructureData ,
353
+ let courseStructureDataRaw ,
353
354
zip ;
354
355
355
356
if ( ! isZip && contentType !== "text/xml" ) {
@@ -365,7 +366,7 @@ module.exports = {
365
366
}
366
367
367
368
try {
368
- courseStructureData = await zip . entryData ( "cmi5.xml" ) ;
369
+ courseStructureDataRaw = await zip . entryData ( "cmi5.xml" ) ;
369
370
}
370
371
catch ( ex ) {
371
372
if ( ex . message === "Bad archive" ) {
@@ -377,13 +378,18 @@ module.exports = {
377
378
}
378
379
else {
379
380
try {
380
- courseStructureData = await readFile ( req . payload . path ) ;
381
+ courseStructureDataRaw = await readFile ( req . payload . path ) ;
381
382
}
382
383
catch ( ex ) {
383
384
throw Boom . internal ( `Failed to read structure file: ${ ex } ` ) ;
384
385
}
385
386
}
386
387
388
+ let courseStructureData = helpers . sanitizeXML ( courseStructureDataRaw ) ;
389
+ if ( courseStructureData != undefined && helpers . isPotentiallyMaliciousXML ( courseStructureData ) ) {
390
+ throw Boom . internal ( `Invalid XML data provided: ${ ex } ` ) ;
391
+ }
392
+
387
393
let courseStructureDocument ;
388
394
389
395
try {
0 commit comments