-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS: Post-processing query for inline test expectations
- Loading branch information
Showing
6 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Security/CWE-611/Xxe.ql | ||
query: Security/CWE-611/Xxe.ql | ||
postprocess: TestUtilities/InlineExpectationsTestQuery.ql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
javascript/ql/test/query-tests/Security/CWE-611/libxml.noent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
const express = require('express'); | ||
const libxmljs = require('libxmljs'); | ||
|
||
express().get('/some/path', function(req) { | ||
express().get('/some/path', function (req) { | ||
// NOT OK: unguarded entity expansion | ||
libxmljs.parseXml(req.param("some-xml"), { noent: true }); | ||
libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ BAD | ||
}); | ||
|
||
express().post('/some/path', function(req, res) { | ||
express().post('/some/path', function (req, res) { | ||
// NOT OK: unguarded entity expansion | ||
libxmljs.parseXml(req.param("some-xml"), { noent: true }); | ||
libxmljs.parseXml(req.param("some-xml"), { noent: true }); // $ BAD | ||
|
||
// NOT OK: unguarded entity expansion | ||
libxmljs.parseXmlString(req.param("some-xml"), {noent:true}) | ||
libxmljs.parseXmlString(req.param("some-xml"), { noent: true }) // $ BAD | ||
// NOT OK: unguarded entity expansion | ||
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:true}) | ||
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: true }) // $ BAD | ||
|
||
// OK - no entity expansion | ||
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), {noent:false}) | ||
libxmljs.parseXmlString(req.files.products.data.toString('utf8'), { noent: false }) | ||
}); |
4 changes: 2 additions & 2 deletions
4
javascript/ql/test/query-tests/Security/CWE-611/libxml.sax.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const express = require('express'); | ||
const libxmljs = require('libxmljs'); | ||
|
||
express().get('/some/path', function(req) { | ||
express().get('/some/path', function (req) { | ||
const parser = new libxmljs.SaxParser(); | ||
parser.parseString(req.param("some-xml")); // NOT OK: the SAX parser expands external entities by default | ||
parser.parseString(req.param("some-xml")); // $ BAD: the SAX parser expands external entities by default | ||
}); |
4 changes: 2 additions & 2 deletions
4
javascript/ql/test/query-tests/Security/CWE-611/libxml.saxpush.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const express = require('express'); | ||
const libxmljs = require('libxmljs'); | ||
|
||
express().get('/some/path', function(req) { | ||
express().get('/some/path', function (req) { | ||
const parser = new libxmljs.SaxPushParser(); | ||
parser.push(req.param("some-xml")); // NOT OK: the SAX parser expands external entities by default | ||
parser.push(req.param("some-xml")); // $ BAD: the SAX parser expands external entities by default | ||
}); |
21 changes: 21 additions & 0 deletions
21
javascript/ql/test/testUtilities/InlineExpectationsTestQuery.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @kind test-postprocess | ||
*/ | ||
|
||
private import javascript | ||
private import codeql.util.test.InlineExpectationsTest as T | ||
private import internal.InlineExpectationsTestImpl | ||
import T::TestPostProcessing | ||
import T::TestPostProcessing::Make<Impl, Input> | ||
|
||
private module Input implements T::TestPostProcessing::InputSig<Impl> { | ||
string getRelativeUrl(Location location) { | ||
exists(File f, int startline, int startcolumn, int endline, int endcolumn | | ||
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and | ||
f = location.getFile() | ||
| | ||
result = | ||
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn | ||
) | ||
} | ||
} |