Skip to content

Commit e5659a2

Browse files
committed
fixing sanitization syntax
1 parent feee873 commit e5659a2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

player/service/plugins/routes/v1/courses.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,12 @@ module.exports = {
385385
}
386386
}
387387

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+
}
391394
}
392395

393396
let courseStructureDocument;

player/service/tests/xml.spec.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ const fs = require("fs");
77

88
const helpers = require("../plugins/routes/lib/helpers");
99
const chai = require("chai");
10+
const exp = require("constants");
1011

11-
describe("Libxmljs Usage", async () => {
12+
describe("XML Parsing and Usage", async () => {
1213

1314
/**
1415
* https://www.stackhawk.com/blog/nodejs-xml-external-entities-xxe-guide-examples-and-prevention/
@@ -22,4 +23,14 @@ describe("Libxmljs Usage", async () => {
2223

2324
chai.expect(suspicious).to.be.equal(true, "The provided XML should have thrown a validity issue for its use of an <!ENTITY tag");
2425
});
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+
});
2536
});

0 commit comments

Comments
 (0)