Skip to content

Commit 1259b7e

Browse files
committed
JS: Post-processing query for inline test expectations
1 parent e5f2bbb commit 1259b7e

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Security/CWE-611/Xxe.ql
1+
query: Security/CWE-611/Xxe.ql
2+
postprocess: testUtilities/InlineExpectationsTestQuery.ql
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function test() {
2-
var src = document.location.search;
2+
var src = document.location.search; // $ Source=search
33

44
if (window.DOMParser) {
55
// OK: DOMParser only expands internal general entities
@@ -8,10 +8,10 @@ function test() {
88
var parser;
99
try {
1010
// NOT OK: XMLDOM expands external entities by default
11-
(new ActiveXObject("Microsoft.XMLDOM")).loadXML(src);
11+
(new ActiveXObject("Microsoft.XMLDOM")).loadXML(src); // $ Alert=search
1212
} catch (e) {
1313
// NOT OK: MSXML expands external entities by default
14-
(new ActiveXObject("Msxml2.DOMDocument")).loadXML(src);
14+
(new ActiveXObject("Msxml2.DOMDocument")).loadXML(src); // $ Alert=search
1515
}
1616
}
1717
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
const express = require('express');
22
const libxmljs = require('libxmljs');
33

4-
express().get('/some/path', function(req) {
4+
express().get('/some/path', function (req) {
55
// NOT OK: unguarded entity expansion
6-
libxmljs.parseXml(req.param("some-xml"), { noent: true });
6+
libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert
77
});
88

9-
express().post('/some/path', function(req, res) {
9+
express().post('/some/path', function (req, res) {
1010
// NOT OK: unguarded entity expansion
11-
libxmljs.parseXml(req.param("some-xml"), { noent: true });
11+
libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ Alert
1212

1313
// NOT OK: unguarded entity expansion
14-
libxmljs.parseXmlString(req.param("some-xml"), {noent:true})
14+
libxmljs.parseXmlString(req.param("some-xml"), { noent: true }) // $ Alert
1515
// NOT OK: unguarded entity expansion
16-
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:true})
17-
16+
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: true })// $ Source=files $ Alert=files
17+
1818
// OK - no entity expansion
19-
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:false})
19+
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: false })
2020
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const express = require('express');
22
const libxmljs = require('libxmljs');
33

4-
express().get('/some/path', function(req) {
4+
express().get('/some/path', function (req) {
55
const parser = new libxmljs.SaxParser();
6-
parser.parseString(req.param("some-xml")); // NOT OK: the SAX parser expands external entities by default
6+
parser.parseString(req.param("some-xml")); // $ Alert: the SAX parser expands external entities by default
77
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const express = require('express');
22
const libxmljs = require('libxmljs');
33

4-
express().get('/some/path', function(req) {
4+
express().get('/some/path', function (req) {
55
const parser = new libxmljs.SaxPushParser();
6-
parser.push(req.param("some-xml")); // NOT OK: the SAX parser expands external entities by default
6+
parser.push(req.param("some-xml")); // $ Alert: the SAX parser expands external entities by default
77
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
private import javascript
6+
private import codeql.util.test.InlineExpectationsTest as T
7+
private import internal.InlineExpectationsTestImpl
8+
import T::TestPostProcessing
9+
import T::TestPostProcessing::Make<Impl, Input>
10+
11+
private module Input implements T::TestPostProcessing::InputSig<Impl> {
12+
string getRelativeUrl(Location location) {
13+
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
14+
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
15+
f = location.getFile()
16+
|
17+
result =
18+
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
19+
)
20+
}
21+
}

0 commit comments

Comments
 (0)