@contrast/assess 1.46.0 → 1.46.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -11
- package/lib/crypto-analysis/install/crypto.test.js +0 -146
- package/lib/crypto-analysis/install/math.test.js +0 -65
- package/lib/dataflow/index.test.js +0 -36
- package/lib/dataflow/propagation/index.test.js +0 -103
- package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
- package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
- package/lib/dataflow/propagation/install/buffer.test.js +0 -112
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
- package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
- package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
- package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
- package/lib/dataflow/propagation/install/escape.test.js +0 -73
- package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
- package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
- package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
- package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
- package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
- package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
- package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
- package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
- package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
- package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
- package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
- package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
- package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
- package/lib/dataflow/propagation/install/path/format.test.js +0 -250
- package/lib/dataflow/propagation/install/path/index.test.js +0 -45
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
- package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
- package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
- package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
- package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
- package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
- package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
- package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
- package/lib/dataflow/propagation/install/send.test.js +0 -63
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
- package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
- package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
- package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
- package/lib/dataflow/propagation/install/string/index.test.js +0 -103
- package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
- package/lib/dataflow/propagation/install/string/match.test.js +0 -374
- package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
- package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
- package/lib/dataflow/propagation/install/string/split.test.js +0 -513
- package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
- package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
- package/lib/dataflow/propagation/install/unescape.test.js +0 -78
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
- package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
- package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
- package/lib/dataflow/propagation/install/url/url.test.js +0 -466
- package/lib/dataflow/propagation/install/util-format.test.js +0 -336
- package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
- package/lib/dataflow/sinks/index.test.js +0 -78
- package/lib/dataflow/sinks/install/child-process.test.js +0 -338
- package/lib/dataflow/sinks/install/eval.test.js +0 -95
- package/lib/dataflow/sinks/install/express/index.test.js +0 -33
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
- package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/fs.test.js +0 -138
- package/lib/dataflow/sinks/install/function.test.js +0 -103
- package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/http/index.test.js +0 -33
- package/lib/dataflow/sinks/install/http/request.test.js +0 -184
- package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
- package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
- package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
- package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
- package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
- package/lib/dataflow/sinks/install/mssql.test.js +0 -134
- package/lib/dataflow/sinks/install/mysql.test.js +0 -224
- package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
- package/lib/dataflow/sinks/install/postgres.test.js +0 -152
- package/lib/dataflow/sinks/install/restify.test.js +0 -140
- package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
- package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
- package/lib/dataflow/sinks/install/vm.test.js +0 -326
- package/lib/dataflow/sources/handler.test.js +0 -501
- package/lib/dataflow/sources/index.test.js +0 -60
- package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
- package/lib/dataflow/sources/install/busboy.test.js +0 -152
- package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
- package/lib/dataflow/sources/install/express/params.test.js +0 -110
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
- package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
- package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
- package/lib/dataflow/sources/install/formidable1.test.js +0 -119
- package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
- package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
- package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
- package/lib/dataflow/sources/install/http.test.js +0 -149
- package/lib/dataflow/sources/install/koa/index.test.js +0 -40
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
- package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
- package/lib/dataflow/sources/install/multer1.test.js +0 -143
- package/lib/dataflow/sources/install/qs6.test.js +0 -131
- package/lib/dataflow/sources/install/querystring.test.js +0 -82
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
- package/lib/dataflow/sources/install/restify/index.test.js +0 -38
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
- package/lib/dataflow/sources/install/restify/router.test.js +0 -81
- package/lib/dataflow/tag-utils-complete.test.js +0 -27
- package/lib/dataflow/tag-utils.test.js +0 -192
- package/lib/dataflow/tracker.test.js +0 -216
- package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
- package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
- package/lib/event-factory.test.js +0 -326
- package/lib/get-policy.test.js +0 -194
- package/lib/get-source-context.test.js +0 -161
- package/lib/index.test.js +0 -45
- package/lib/make-source-context.test.js +0 -50
- package/lib/response-scanning/handlers/index.test.js +0 -419
- package/lib/response-scanning/handlers/utils.test.js +0 -380
- package/lib/response-scanning/index.test.js +0 -41
- package/lib/response-scanning/install/http.test.js +0 -175
- package/lib/rule-scopes.test.js +0 -27
- package/lib/sampler/common.test.js +0 -101
- package/lib/sampler/index.test.js +0 -313
- package/lib/session-configuration/handlers.test.js +0 -84
- package/lib/session-configuration/index.test.js +0 -36
- package/lib/session-configuration/install/express-session.test.js +0 -218
- package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
- package/lib/session-configuration/install/hapi.test.js +0 -269
- package/lib/session-configuration/install/koa.test.js +0 -92
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow restify sinks', function () {
|
|
8
|
-
let core,
|
|
9
|
-
simulateRequestScope,
|
|
10
|
-
trackString,
|
|
11
|
-
reportFindings,
|
|
12
|
-
getRes,
|
|
13
|
-
patchMock;
|
|
14
|
-
|
|
15
|
-
function next() {}
|
|
16
|
-
|
|
17
|
-
beforeEach(function () {
|
|
18
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
19
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
20
|
-
|
|
21
|
-
// this represents mock of what restify does here: https://github.com/restify/node-restify/blob/master/lib/response.js
|
|
22
|
-
function patch(Orig) {
|
|
23
|
-
Orig.prototype.redirect = function() {
|
|
24
|
-
return 'canary';
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function Response() {}
|
|
29
|
-
|
|
30
|
-
getRes = () => {
|
|
31
|
-
// this mimics running of restify's patch, and our it will trigger out instrumentation
|
|
32
|
-
patchMock(Response);
|
|
33
|
-
return new Response();
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
core.depHooks.resolve.callsFake((desc, cb) => {
|
|
37
|
-
patchMock = cb(patch);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
require('./restify')(core).install();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('res.redirect(String, Function)', function() {
|
|
44
|
-
it('reports when string is tracked', function() {
|
|
45
|
-
simulateRequestScope(() => {
|
|
46
|
-
const res = getRes();
|
|
47
|
-
res.redirect(trackString('/fargs'), next);
|
|
48
|
-
|
|
49
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
50
|
-
ruleId: 'unvalidated-redirect',
|
|
51
|
-
sinkEvent: sinon.match({
|
|
52
|
-
args: [
|
|
53
|
-
{ tracked: true, value: '\'/fargs\'' },
|
|
54
|
-
{ tracked: false, value: 'Function' }
|
|
55
|
-
],
|
|
56
|
-
context: 'res.redirect(\'/fargs\',Function)',
|
|
57
|
-
tags: { UNTRUSTED: [1, 6] },
|
|
58
|
-
source: 'P0',
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('does not report if string arg is untracked or safely tagged', function() {
|
|
65
|
-
simulateRequestScope(() => {
|
|
66
|
-
const res = getRes();
|
|
67
|
-
const str = trackString('/fargs', { tags: { UNTRUSTED: [0, 5], URL_ENCODED: [0, 5] } });
|
|
68
|
-
res.redirect(str, next);
|
|
69
|
-
res.redirect('/fargs', next);
|
|
70
|
-
expect(reportFindings.getCalls()).to.have.lengthOf(0);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('res.redirect(Number, String, Function)', function() {
|
|
76
|
-
it('reports when string is tracked', function() {
|
|
77
|
-
simulateRequestScope(() => {
|
|
78
|
-
const res = getRes();
|
|
79
|
-
res.redirect(301, trackString('/fargs'), next);
|
|
80
|
-
|
|
81
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
82
|
-
ruleId: 'unvalidated-redirect',
|
|
83
|
-
sinkEvent: sinon.match({
|
|
84
|
-
args: [
|
|
85
|
-
{ tracked: false, value: 'Number' },
|
|
86
|
-
{ tracked: true, value: '\'/fargs\'' },
|
|
87
|
-
{ tracked: false, value: 'Function' }
|
|
88
|
-
],
|
|
89
|
-
context: 'res.redirect(Number,\'/fargs\',Function)',
|
|
90
|
-
tags: { UNTRUSTED: [1, 6] },
|
|
91
|
-
source: 'P1',
|
|
92
|
-
}),
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('does not report if string arg is untracked or safely tagged', function() {
|
|
98
|
-
simulateRequestScope(() => {
|
|
99
|
-
const res = getRes();
|
|
100
|
-
const str = trackString('/fargs', { tags: { UNTRUSTED: [0, 5], URL_ENCODED: [0, 5] } });
|
|
101
|
-
res.redirect(301, str, next);
|
|
102
|
-
res.redirect('/fargs', next);
|
|
103
|
-
expect(reportFindings.getCalls()).to.have.lengthOf(0);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('res.redirect(Object, Function)', function() {
|
|
109
|
-
it('reports when string options are tracked', function() {
|
|
110
|
-
simulateRequestScope(() => {
|
|
111
|
-
const res = getRes();
|
|
112
|
-
|
|
113
|
-
res.redirect({ pathname: trackString('/fargs') }, next);
|
|
114
|
-
|
|
115
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
116
|
-
ruleId: 'unvalidated-redirect',
|
|
117
|
-
sinkEvent: sinon.match({
|
|
118
|
-
args: [
|
|
119
|
-
{ tracked: true, value: '{...\'pathname\':\'/fargs\'...}' },
|
|
120
|
-
{ tracked: false, value: 'Function' }
|
|
121
|
-
],
|
|
122
|
-
context: 'res.redirect({...\'pathname\':\'/fargs\'...},Function)',
|
|
123
|
-
tags: { UNTRUSTED: [16, 21] },
|
|
124
|
-
source: 'P0',
|
|
125
|
-
}),
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('does not report if string arg is untracked or safely tagged', function() {
|
|
131
|
-
simulateRequestScope(() => {
|
|
132
|
-
const res = getRes();
|
|
133
|
-
const str = trackString('/fargs', { tags: { UNTRUSTED: [0, 5], URL_ENCODED: [0, 5] } });
|
|
134
|
-
res.redirect({ pathname: str }, next);
|
|
135
|
-
res.redirect({ pathname: '/fargs' }, next);
|
|
136
|
-
expect(reportFindings.getCalls()).to.have.lengthOf(0);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { inspect } = require('util');
|
|
6
|
-
const {
|
|
7
|
-
DataflowTag: { SQL_ENCODED, UNTRUSTED },
|
|
8
|
-
} = require('@contrast/common');
|
|
9
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow sinks sequelize', function () {
|
|
12
|
-
let core, simulateRequestScope, trackString, tracker, reportFindings;
|
|
13
|
-
|
|
14
|
-
class Sequelize {
|
|
15
|
-
query() { }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(function () {
|
|
19
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
20
|
-
tracker = core.assess.dataflow.tracker;
|
|
21
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
22
|
-
|
|
23
|
-
core.depHooks.resolve.yields(Sequelize);
|
|
24
|
-
|
|
25
|
-
require('./sequelize')(core).install();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
29
|
-
Sequelize.prototype.query();
|
|
30
|
-
expect(reportFindings).to.not.have.been.called;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('skips instrumentation if a query is not provided ', function () {
|
|
34
|
-
simulateRequestScope(function () {
|
|
35
|
-
Sequelize.prototype.query();
|
|
36
|
-
expect(reportFindings).to.not.have.been.called;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('skips instrumentation if the query is not a string', function () {
|
|
41
|
-
simulateRequestScope(function () {
|
|
42
|
-
Sequelize.prototype.query({});
|
|
43
|
-
expect(reportFindings).to.not.have.been.called;
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('skips instrumentation if the query is not a tracked', function () {
|
|
48
|
-
simulateRequestScope(function () {
|
|
49
|
-
Sequelize.prototype.query('hello');
|
|
50
|
-
expect(reportFindings).to.not.have.been.called;
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('skips instrumentation if the query is safe', function () {
|
|
55
|
-
simulateRequestScope(function () {
|
|
56
|
-
const str = trackString('drop table', {
|
|
57
|
-
tags: {
|
|
58
|
-
[SQL_ENCODED]: [0, 9],
|
|
59
|
-
[UNTRUSTED]: [0, 9],
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
const { extern } = tracker.getData(str);
|
|
63
|
-
|
|
64
|
-
Sequelize.prototype.query(extern);
|
|
65
|
-
expect(reportFindings).to.not.have.been.called;
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('reports an sql-injection', function () {
|
|
70
|
-
simulateRequestScope(function () {
|
|
71
|
-
const str = trackString('drop table', {
|
|
72
|
-
tags: {
|
|
73
|
-
[SQL_ENCODED]: [0, 4],
|
|
74
|
-
[UNTRUSTED]: [0, 9],
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const { value } = tracker.getData(str);
|
|
78
|
-
const options = { dialect: 'mysql' };
|
|
79
|
-
|
|
80
|
-
Sequelize.prototype.query(str, options);
|
|
81
|
-
|
|
82
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
83
|
-
ruleId: 'sql-injection',
|
|
84
|
-
sinkEvent: {
|
|
85
|
-
name: 'sequelize.prototype.query',
|
|
86
|
-
moduleName: 'sequelize',
|
|
87
|
-
methodName: 'prototype.query',
|
|
88
|
-
context: `sequelize.prototype.query('${value}', { dialect: 'mysql' })`,
|
|
89
|
-
object: {
|
|
90
|
-
value: sinon.match('sequelize'),
|
|
91
|
-
tracked: false,
|
|
92
|
-
},
|
|
93
|
-
args: [{ value, tracked: true }, { value: inspect(options), tracked: false }],
|
|
94
|
-
tags: { [SQL_ENCODED]: [0, 4], [UNTRUSTED]: [0, 9] },
|
|
95
|
-
source: 'P0',
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const {
|
|
6
|
-
DataflowTag: { UNTRUSTED, SQL_ENCODED },
|
|
7
|
-
} = require('@contrast/common');
|
|
8
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow sinks sqlite3', function () {
|
|
11
|
-
let core, sqlite3, simulateRequestScope, trackString, tracker, reportFindings;
|
|
12
|
-
|
|
13
|
-
beforeEach(function () {
|
|
14
|
-
|
|
15
|
-
sqlite3 = {
|
|
16
|
-
// eslint-disable-next-line object-shorthand
|
|
17
|
-
Database: function () { }
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
sqlite3.Database.prototype = {
|
|
21
|
-
all: sinon.stub(),
|
|
22
|
-
run: sinon.stub(),
|
|
23
|
-
get: sinon.stub(),
|
|
24
|
-
each: sinon.stub(),
|
|
25
|
-
exec: sinon.stub(),
|
|
26
|
-
prepare: sinon.stub()
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
30
|
-
tracker = core.assess.dataflow.tracker;
|
|
31
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
32
|
-
|
|
33
|
-
core.depHooks.resolve.yields(sqlite3);
|
|
34
|
-
|
|
35
|
-
require('./sqlite3')(core).install();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
['all', 'run', 'get', 'each', 'exec', 'prepare'].forEach((method) => {
|
|
39
|
-
describe(`instruments connection.${method}()`, function () {
|
|
40
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
41
|
-
const db = new sqlite3.Database();
|
|
42
|
-
db[method]('SELECT "foo"');
|
|
43
|
-
expect(reportFindings).not.to.have.been.called;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('skips instrumentation if a value is not provided ', function () {
|
|
47
|
-
simulateRequestScope(function () {
|
|
48
|
-
const db = new sqlite3.Database();
|
|
49
|
-
db[method]();
|
|
50
|
-
expect(reportFindings).not.to.have.been.called;
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('skips instrumentation if the value is not a string', function () {
|
|
55
|
-
simulateRequestScope(function () {
|
|
56
|
-
const db = new sqlite3.Database();
|
|
57
|
-
db[method]({});
|
|
58
|
-
expect(reportFindings).not.to.have.been.called;
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('skips instrumentation if the query is not a tracked', function () {
|
|
63
|
-
simulateRequestScope(function () {
|
|
64
|
-
const db = new sqlite3.Database();
|
|
65
|
-
db[method]('SELECT "foo"');
|
|
66
|
-
expect(reportFindings).not.to.have.been.called;
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('skips instrumentation if the query is safe', function () {
|
|
71
|
-
simulateRequestScope(function () {
|
|
72
|
-
const str = trackString('SELECT "foo"', {
|
|
73
|
-
tags: {
|
|
74
|
-
[SQL_ENCODED]: [0, 11],
|
|
75
|
-
[UNTRUSTED]: [0, 11],
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
const { extern } = tracker.getData(str);
|
|
79
|
-
|
|
80
|
-
const db = new sqlite3.Database();
|
|
81
|
-
db[method](extern);
|
|
82
|
-
expect(reportFindings).not.to.have.been.called;
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('reports an sql-injection', function() {
|
|
87
|
-
simulateRequestScope(function () {
|
|
88
|
-
const value = 'SELECT "foo"';
|
|
89
|
-
const extern = trackString(value, {
|
|
90
|
-
tags: {
|
|
91
|
-
[UNTRUSTED]: [0, 11],
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const db = new sqlite3.Database();
|
|
96
|
-
db[method](extern);
|
|
97
|
-
|
|
98
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
99
|
-
ruleId: 'sql-injection',
|
|
100
|
-
sinkEvent: {
|
|
101
|
-
name: `sqlite3.Database.prototype.${method}`,
|
|
102
|
-
moduleName: 'sqlite3',
|
|
103
|
-
methodName: `Database.prototype.${method}`,
|
|
104
|
-
context: `db.${method}('${extern}')`,
|
|
105
|
-
object: {
|
|
106
|
-
value: '[Module<sqlite3>].Database',
|
|
107
|
-
tracked: false,
|
|
108
|
-
},
|
|
109
|
-
args: [{ value, tracked: true }],
|
|
110
|
-
tags: { [UNTRUSTED]: [0, 11] },
|
|
111
|
-
source: 'P0',
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const {
|
|
6
|
-
DataflowTag: { UNTRUSTED, CUSTOM_VALIDATED },
|
|
7
|
-
Rule: { UNSAFE_CODE_EXECUTION },
|
|
8
|
-
primordials: { UtilInspect },
|
|
9
|
-
} = require('@contrast/common');
|
|
10
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
11
|
-
|
|
12
|
-
describe('assess dataflow sinks vm', function () {
|
|
13
|
-
let vm, core, simulateRequestScope, trackString, reportFindings, reportSafePositive;
|
|
14
|
-
|
|
15
|
-
beforeEach(function () {
|
|
16
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
17
|
-
|
|
18
|
-
vm = require('vm');
|
|
19
|
-
|
|
20
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
21
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
22
|
-
|
|
23
|
-
core.depHooks.resolve.yields(vm);
|
|
24
|
-
|
|
25
|
-
require('./vm')(core).install();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
[
|
|
29
|
-
{
|
|
30
|
-
method: 'Script',
|
|
31
|
-
vulnerableArgs: [{ type: 'string', index: 0 }],
|
|
32
|
-
args: () => ['val = "test"'],
|
|
33
|
-
sanitizedArgs: () => [trackString('val = "test"', {
|
|
34
|
-
tags: {
|
|
35
|
-
[UNTRUSTED]: [0, 11],
|
|
36
|
-
[CUSTOM_VALIDATED]: [0, 11]
|
|
37
|
-
}
|
|
38
|
-
})],
|
|
39
|
-
isConstructor: true,
|
|
40
|
-
expectedSafeReportInfo: [{
|
|
41
|
-
value: UtilInspect('val = "test"'),
|
|
42
|
-
strValues: ['val = "test"'],
|
|
43
|
-
tags: [{ [UNTRUSTED]: [0, 11], [CUSTOM_VALIDATED]: [0, 11] }]
|
|
44
|
-
}],
|
|
45
|
-
expectedSinkEvent: [{
|
|
46
|
-
args: [{ value: 'val = "test"', tracked: true }],
|
|
47
|
-
context: 'vm.Script("val = "test"")',
|
|
48
|
-
name: 'vm.Script',
|
|
49
|
-
moduleName: 'vm',
|
|
50
|
-
methodName: 'Script',
|
|
51
|
-
object: { value: 'vm', tracked: false },
|
|
52
|
-
source: 'P0',
|
|
53
|
-
tags: { [UNTRUSTED]: [0, 11] }
|
|
54
|
-
}]
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
method: 'createScript',
|
|
58
|
-
vulnerableArgs: [{ type: 'string', index: 0 }],
|
|
59
|
-
args: () => ['val = "test"'],
|
|
60
|
-
sanitizedArgs: () => [trackString('val = "test"', {
|
|
61
|
-
tags: {
|
|
62
|
-
[UNTRUSTED]: [0, 11],
|
|
63
|
-
[CUSTOM_VALIDATED]: [0, 11]
|
|
64
|
-
}
|
|
65
|
-
})],
|
|
66
|
-
expectedSafeReportInfo: [{
|
|
67
|
-
value: UtilInspect('val = "test"'),
|
|
68
|
-
strValues: ['val = "test"'],
|
|
69
|
-
tags: [{ [UNTRUSTED]: [0, 11], [CUSTOM_VALIDATED]: [0, 11] }]
|
|
70
|
-
}],
|
|
71
|
-
expectedSinkEvent: [{
|
|
72
|
-
args: [{ value: 'val = "test"', tracked: true }],
|
|
73
|
-
context: 'vm.createScript("val = "test"")',
|
|
74
|
-
name: 'vm.createScript',
|
|
75
|
-
moduleName: 'vm',
|
|
76
|
-
methodName: 'createScript',
|
|
77
|
-
object: { value: 'vm', tracked: false },
|
|
78
|
-
source: 'P0',
|
|
79
|
-
tags: { [UNTRUSTED]: [0, 11] }
|
|
80
|
-
}]
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
method: 'runInContext',
|
|
84
|
-
vulnerableArgs: [{ type: 'string', index: 0 }],
|
|
85
|
-
args: () => ['val = "test"', vm.createContext({ val: '' })],
|
|
86
|
-
sanitizedArgs: () => [trackString('val = "test"', {
|
|
87
|
-
tags: {
|
|
88
|
-
[UNTRUSTED]: [0, 11],
|
|
89
|
-
[CUSTOM_VALIDATED]: [0, 11]
|
|
90
|
-
}
|
|
91
|
-
}),
|
|
92
|
-
vm.createContext({ val: '' })],
|
|
93
|
-
missingArgs: () => ['', vm.createContext({})],
|
|
94
|
-
expectedSafeReportInfo: [{
|
|
95
|
-
value: UtilInspect('val = "test"'),
|
|
96
|
-
strValues: ['val = "test"'],
|
|
97
|
-
tags: [{ [UNTRUSTED]: [0, 11], [CUSTOM_VALIDATED]: [0, 11] }]
|
|
98
|
-
}],
|
|
99
|
-
expectedSinkEvent: [{
|
|
100
|
-
args: [{ value: 'val = "test"', tracked: true }, { value: UtilInspect({ val: '' }), tracked: false }],
|
|
101
|
-
context: 'vm.runInContext("val = "test"", { val: \'\' })',
|
|
102
|
-
name: 'vm.runInContext',
|
|
103
|
-
moduleName: 'vm',
|
|
104
|
-
methodName: 'runInContext',
|
|
105
|
-
object: { value: 'vm', tracked: false },
|
|
106
|
-
source: 'P0',
|
|
107
|
-
tags: { [UNTRUSTED]: [0, 11] }
|
|
108
|
-
}]
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
method: 'runInThisContext',
|
|
112
|
-
vulnerableArgs: [{ type: 'string', index: 0 }],
|
|
113
|
-
sanitizedArgs: () => [trackString('val = "test"', {
|
|
114
|
-
tags: {
|
|
115
|
-
[UNTRUSTED]: [0, 11],
|
|
116
|
-
[CUSTOM_VALIDATED]: [0, 11]
|
|
117
|
-
}
|
|
118
|
-
})],
|
|
119
|
-
args: () => ['val = "test"'],
|
|
120
|
-
expectedSafeReportInfo: [{
|
|
121
|
-
value: UtilInspect('val = "test"'),
|
|
122
|
-
strValues: ['val = "test"'],
|
|
123
|
-
tags: [{ [UNTRUSTED]: [0, 11], [CUSTOM_VALIDATED]: [0, 11] }]
|
|
124
|
-
}],
|
|
125
|
-
expectedSinkEvent: [{
|
|
126
|
-
args: [{ value: 'val = "test"', tracked: true }],
|
|
127
|
-
context: 'vm.runInThisContext("val = "test"")',
|
|
128
|
-
name: 'vm.runInThisContext',
|
|
129
|
-
moduleName: 'vm',
|
|
130
|
-
methodName: 'runInThisContext',
|
|
131
|
-
object: { value: 'vm', tracked: false },
|
|
132
|
-
source: 'P0',
|
|
133
|
-
tags: { [UNTRUSTED]: [0, 11] }
|
|
134
|
-
}]
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
method: 'createContext',
|
|
138
|
-
vulnerableArgs: [{ type: 'object', index: 0 }],
|
|
139
|
-
sanitizedArgs: () => [{
|
|
140
|
-
val: trackString('value', {
|
|
141
|
-
tags: {
|
|
142
|
-
[UNTRUSTED]: [0, 4],
|
|
143
|
-
[CUSTOM_VALIDATED]: [0, 4]
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
}],
|
|
147
|
-
args: () => [{ val: 'value' }],
|
|
148
|
-
expectedSafeReportInfo: [{
|
|
149
|
-
value: UtilInspect({ val: 'value' }),
|
|
150
|
-
strValues: ['value'],
|
|
151
|
-
tags: [{ [UNTRUSTED]: [8, 12], [CUSTOM_VALIDATED]: [8, 12] }]
|
|
152
|
-
}],
|
|
153
|
-
expectedSinkEvent: [{
|
|
154
|
-
args: [{ value: UtilInspect({ val: 'value' }), tracked: false }],
|
|
155
|
-
context: 'vm.createContext({ val: \'value\' })',
|
|
156
|
-
name: 'vm.createContext',
|
|
157
|
-
moduleName: 'vm',
|
|
158
|
-
methodName: 'createContext',
|
|
159
|
-
object: { value: 'vm', tracked: false },
|
|
160
|
-
source: 'P0',
|
|
161
|
-
tags: { [UNTRUSTED]: [8, 12] }
|
|
162
|
-
}]
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
method: 'runInNewContext',
|
|
166
|
-
vulnerableArgs: [{ type: 'string', index: 0 }, { type: 'object', index: 1 }],
|
|
167
|
-
sanitizedArgs: () => [trackString('val = "test"', {
|
|
168
|
-
tags: {
|
|
169
|
-
[UNTRUSTED]: [0, 11],
|
|
170
|
-
[CUSTOM_VALIDATED]: [0, 11]
|
|
171
|
-
}
|
|
172
|
-
}), {
|
|
173
|
-
val: trackString('SAFE', {
|
|
174
|
-
tags: {
|
|
175
|
-
[UNTRUSTED]: [0, 3],
|
|
176
|
-
[CUSTOM_VALIDATED]: [0, 3]
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
}],
|
|
180
|
-
args: () => ['val = "test"', { val: 'value' }],
|
|
181
|
-
expectedSafeReportInfo: [
|
|
182
|
-
{
|
|
183
|
-
value: UtilInspect('val = "test"'),
|
|
184
|
-
strValues: ['val = "test"'],
|
|
185
|
-
tags: [{ [UNTRUSTED]: [0, 11], [CUSTOM_VALIDATED]: [0, 11] }]
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
value: UtilInspect({ val: 'SAFE' }),
|
|
189
|
-
strValues: ['SAFE'],
|
|
190
|
-
tags: [{ [UNTRUSTED]: [8, 11], [CUSTOM_VALIDATED]: [8, 11] }]
|
|
191
|
-
}
|
|
192
|
-
],
|
|
193
|
-
expectedSinkEvent: [{
|
|
194
|
-
args: [{ value: 'val = "test"', tracked: true }, { value: UtilInspect({ val: 'value' }), tracked: false }],
|
|
195
|
-
context: 'vm.runInNewContext("val = "test"", { val: \'value\' })',
|
|
196
|
-
name: 'vm.runInNewContext',
|
|
197
|
-
moduleName: 'vm',
|
|
198
|
-
methodName: 'runInNewContext',
|
|
199
|
-
object: { value: 'vm', tracked: false },
|
|
200
|
-
source: 'P0',
|
|
201
|
-
tags: { [UNTRUSTED]: [0, 11] }
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
args: [{ value: 'val = "test"', tracked: false }, { value: UtilInspect({ val: 'value' }), tracked: false }],
|
|
205
|
-
context: 'vm.runInNewContext("val = "test"", { val: \'value\' })',
|
|
206
|
-
name: 'vm.runInNewContext',
|
|
207
|
-
moduleName: 'vm',
|
|
208
|
-
methodName: 'runInNewContext',
|
|
209
|
-
object: { value: 'vm', tracked: false },
|
|
210
|
-
source: 'P1',
|
|
211
|
-
tags: { [UNTRUSTED]: [8, 12] }
|
|
212
|
-
}]
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
method: 'runInNewContext',
|
|
216
|
-
vulnerableArgs: [{ type: 'object', index: 0 }],
|
|
217
|
-
args: () => [{ val: 'value' }],
|
|
218
|
-
sanitizedArgs: () => [{
|
|
219
|
-
val: trackString('SAFE', {
|
|
220
|
-
tags: {
|
|
221
|
-
[UNTRUSTED]: [0, 3],
|
|
222
|
-
[CUSTOM_VALIDATED]: [0, 3]
|
|
223
|
-
}
|
|
224
|
-
})
|
|
225
|
-
}],
|
|
226
|
-
scriptEntity: true,
|
|
227
|
-
expectedSafeReportInfo: [
|
|
228
|
-
{
|
|
229
|
-
value: UtilInspect({ val: 'SAFE' }),
|
|
230
|
-
strValues: ['SAFE'],
|
|
231
|
-
tags: [{ [UNTRUSTED]: [8, 11], [CUSTOM_VALIDATED]: [8, 11] }]
|
|
232
|
-
}
|
|
233
|
-
],
|
|
234
|
-
expectedSinkEvent: [{
|
|
235
|
-
args: [{ value: UtilInspect({ val: 'value' }), tracked: false }],
|
|
236
|
-
context: 'vm.Script.prototype.runInNewContext({ val: \'value\' })',
|
|
237
|
-
name: 'vm.Script.prototype.runInNewContext',
|
|
238
|
-
moduleName: 'vm',
|
|
239
|
-
methodName: 'runInNewContext',
|
|
240
|
-
object: { value: 'vm.Script.prototype', tracked: false },
|
|
241
|
-
source: 'P0',
|
|
242
|
-
tags: { [UNTRUSTED]: [8, 12] }
|
|
243
|
-
}]
|
|
244
|
-
}
|
|
245
|
-
].forEach(({ method, args, missingArgs = () => [], vulnerableArgs, sanitizedArgs, isConstructor, scriptEntity, expectedSafeReportInfo, expectedSinkEvent }) => {
|
|
246
|
-
describe(`vm.${method}`, function () {
|
|
247
|
-
let fn;
|
|
248
|
-
if (scriptEntity) {
|
|
249
|
-
fn = () => {
|
|
250
|
-
const scr = new vm.Script('val = "test"');
|
|
251
|
-
return scr;
|
|
252
|
-
};
|
|
253
|
-
} else {
|
|
254
|
-
fn = () => vm[method];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function makeAVmMethodCall(args) {
|
|
258
|
-
const vmMethod = fn();
|
|
259
|
-
|
|
260
|
-
if (isConstructor) {
|
|
261
|
-
new vmMethod(...args());
|
|
262
|
-
} else if (scriptEntity) {
|
|
263
|
-
vmMethod.runInNewContext(...args());
|
|
264
|
-
} else {
|
|
265
|
-
vmMethod(...args());
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
270
|
-
makeAVmMethodCall(args);
|
|
271
|
-
|
|
272
|
-
expect(reportFindings).not.to.have.been.called;
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('skips instrumentation if a value is not provided ', function () {
|
|
276
|
-
simulateRequestScope(function () {
|
|
277
|
-
makeAVmMethodCall(missingArgs);
|
|
278
|
-
|
|
279
|
-
expect(reportFindings).not.to.have.been.called;
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('skips instrumentation if the argument is not a tracked', function () {
|
|
284
|
-
simulateRequestScope(function () {
|
|
285
|
-
makeAVmMethodCall(args);
|
|
286
|
-
|
|
287
|
-
expect(reportFindings).not.to.have.been.called;
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('skips instrumentation if the argument is sanitized', function () {
|
|
292
|
-
simulateRequestScope(function () {
|
|
293
|
-
makeAVmMethodCall(sanitizedArgs);
|
|
294
|
-
|
|
295
|
-
expect(reportFindings).not.to.have.been.called;
|
|
296
|
-
expect(reportSafePositive).to.have.been.calledOnce;
|
|
297
|
-
expect(reportSafePositive).to.have.been.calledWith({
|
|
298
|
-
name: scriptEntity ? `vm.Script.prototype.${method}` : `vm.${method}`,
|
|
299
|
-
ruleId: UNSAFE_CODE_EXECUTION,
|
|
300
|
-
safeTags: [CUSTOM_VALIDATED],
|
|
301
|
-
strInfo: expectedSafeReportInfo
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('reports an unsafe-code-execution', function () {
|
|
307
|
-
simulateRequestScope(function () {
|
|
308
|
-
vulnerableArgs.forEach((arg, idx) => {
|
|
309
|
-
const argsCopy = [...args()];
|
|
310
|
-
const extern = arg.type === 'string' ? trackString(argsCopy[arg.index]) : trackString(argsCopy[arg.index].val);
|
|
311
|
-
argsCopy[arg.index] = arg.type === 'string' ? extern : { val: extern };
|
|
312
|
-
|
|
313
|
-
makeAVmMethodCall(() => argsCopy);
|
|
314
|
-
|
|
315
|
-
expect(reportFindings).to.have.been.calledOnce;
|
|
316
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
317
|
-
ruleId: UNSAFE_CODE_EXECUTION,
|
|
318
|
-
sinkEvent: expectedSinkEvent[idx],
|
|
319
|
-
});
|
|
320
|
-
reportFindings.resetHistory();
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
});
|