@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,134 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
DataflowTag: { UNTRUSTED, SQL_ENCODED },
|
|
5
|
-
} = require('@contrast/common');
|
|
6
|
-
const { expect } = require('chai');
|
|
7
|
-
const sinon = require('sinon');
|
|
8
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow sinks mssql', function () {
|
|
11
|
-
let core, simulateRequestScope, trackString, tracker, reportFindings, reportSafePositive;
|
|
12
|
-
|
|
13
|
-
class PreparedStatement {
|
|
14
|
-
prepare() {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class Request {
|
|
18
|
-
batch() {}
|
|
19
|
-
query() {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
beforeEach(function () {
|
|
23
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
24
|
-
tracker = core.assess.dataflow.tracker;
|
|
25
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
26
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
27
|
-
|
|
28
|
-
core.depHooks.resolve
|
|
29
|
-
.withArgs(sinon.match({ name: 'mssql', file: 'lib/base/prepared-statement.js' }))
|
|
30
|
-
.yields(PreparedStatement);
|
|
31
|
-
|
|
32
|
-
core.depHooks.resolve
|
|
33
|
-
.withArgs(sinon.match({ name: 'mssql', file: 'lib/base/request.js' }))
|
|
34
|
-
.yields(Request);
|
|
35
|
-
|
|
36
|
-
require('./mssql')(core).install();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
[
|
|
40
|
-
{ subject: PreparedStatement, method: 'prepare', name: 'mssql/lib/base/prepared-statement.prototype.prepare' },
|
|
41
|
-
{ subject: Request, method: 'batch', name: 'mssql/lib/base/request.prototype.batch' },
|
|
42
|
-
{ subject: Request, method: 'query', name: 'mssql/lib/base/request.prototype.query' },
|
|
43
|
-
].forEach(({ subject, method, name }) => {
|
|
44
|
-
describe(`${subject.name}.prototype.${method}()`, function () {
|
|
45
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
46
|
-
subject.prototype[method]();
|
|
47
|
-
expect(reportFindings).not.to.have.been.called;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('skips instrumentation if no argument is provided', function () {
|
|
51
|
-
simulateRequestScope(function () {
|
|
52
|
-
subject.prototype[method]();
|
|
53
|
-
expect(reportFindings).not.to.have.been.called;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('skips instrumentation if the argument is not a string', function () {
|
|
58
|
-
simulateRequestScope(function () {
|
|
59
|
-
subject.prototype[method]({});
|
|
60
|
-
expect(reportFindings).not.to.have.been.called;
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('skips instrumentation if the argument is not tracked', function () {
|
|
65
|
-
simulateRequestScope(function () {
|
|
66
|
-
subject.prototype[method]('hello');
|
|
67
|
-
expect(reportFindings).not.to.have.been.called;
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('skips instrumentation if the argument is safe', function () {
|
|
72
|
-
simulateRequestScope(function () {
|
|
73
|
-
const extern = trackString(';drop table Foo--', {
|
|
74
|
-
tags: {
|
|
75
|
-
[SQL_ENCODED]: [0, 16],
|
|
76
|
-
[UNTRUSTED]: [0, 16],
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
subject.prototype[method](extern);
|
|
81
|
-
expect(reportFindings).not.to.have.been.called;
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('reports an sql-injection', function () {
|
|
86
|
-
simulateRequestScope(function () {
|
|
87
|
-
const value = ';drop table Foo--';
|
|
88
|
-
const extern = trackString(value);
|
|
89
|
-
|
|
90
|
-
subject.prototype[method](extern);
|
|
91
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
92
|
-
ruleId: 'sql-injection',
|
|
93
|
-
sinkEvent: {
|
|
94
|
-
name,
|
|
95
|
-
moduleName: 'mssql',
|
|
96
|
-
methodName: `${subject.name}.prototype.${method}`,
|
|
97
|
-
context: `mssql.${subject.name}.${method}('${value}')`,
|
|
98
|
-
object: {
|
|
99
|
-
value: sinon.match(subject.name),
|
|
100
|
-
tracked: false,
|
|
101
|
-
},
|
|
102
|
-
args: [{ value, tracked: true }],
|
|
103
|
-
tags: { [UNTRUSTED]: [0, 16] },
|
|
104
|
-
source: 'P0',
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('reports safe positive', function () {
|
|
111
|
-
simulateRequestScope(function () {
|
|
112
|
-
const extern = trackString(';drop table Foo--', {
|
|
113
|
-
tags: {
|
|
114
|
-
[SQL_ENCODED]: [0, 16],
|
|
115
|
-
[UNTRUSTED]: [0, 16],
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
const strInfo = tracker.getData(extern);
|
|
119
|
-
|
|
120
|
-
subject.prototype[method](extern);
|
|
121
|
-
expect(reportSafePositive).to.have.been.calledWithMatch({
|
|
122
|
-
name,
|
|
123
|
-
ruleId: 'sql-injection',
|
|
124
|
-
safeTags: [SQL_ENCODED],
|
|
125
|
-
strInfo: {
|
|
126
|
-
tags: strInfo.tags,
|
|
127
|
-
value: strInfo.value,
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow sinks mysql', function () {
|
|
8
|
-
let Connection, connection, core, simulateRequestScope, trackString, tracker, reportFindings;
|
|
9
|
-
|
|
10
|
-
beforeEach(function () {
|
|
11
|
-
Connection = function () { };
|
|
12
|
-
Connection.prototype.query = sinon.stub();
|
|
13
|
-
|
|
14
|
-
connection = function () { };
|
|
15
|
-
connection.prototype.query = sinon.stub();
|
|
16
|
-
connection.prototype.execute = sinon.stub();
|
|
17
|
-
|
|
18
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
19
|
-
tracker = core.assess.dataflow.tracker;
|
|
20
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
21
|
-
|
|
22
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'mysql' })).yields(Connection);
|
|
23
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'mysql2' })).yields(connection);
|
|
24
|
-
|
|
25
|
-
require('./mysql')(core).install();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('mysql', function () {
|
|
29
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
30
|
-
const conn = new Connection();
|
|
31
|
-
conn.query('SELECT "foo"');
|
|
32
|
-
expect(reportFindings).not.to.have.been.called;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('skips instrumentation if no argument is provided', function () {
|
|
36
|
-
simulateRequestScope(function () {
|
|
37
|
-
const conn = new Connection();
|
|
38
|
-
conn.query();
|
|
39
|
-
expect(reportFindings).not.to.have.been.called;
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('skips instrumentation if the argument is not a string', function () {
|
|
44
|
-
simulateRequestScope(function () {
|
|
45
|
-
const conn = new Connection();
|
|
46
|
-
conn.query({});
|
|
47
|
-
expect(reportFindings).not.to.have.been.called;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('skips instrumentation if the argument is not tracked', function () {
|
|
52
|
-
simulateRequestScope(function () {
|
|
53
|
-
const conn = new Connection();
|
|
54
|
-
conn.query('SELECT "foo"');
|
|
55
|
-
expect(reportFindings).not.to.have.been.called;
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('skips instrumentation if the argument is safe', function () {
|
|
60
|
-
simulateRequestScope(function () {
|
|
61
|
-
const extern = trackString(';drop table Foo--', {
|
|
62
|
-
tags: {
|
|
63
|
-
SQL_ENCODED: [0, 16],
|
|
64
|
-
UNTRUSTED: [0, 16],
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const conn = new Connection();
|
|
69
|
-
conn.query(extern);
|
|
70
|
-
expect(reportFindings).not.to.have.been.called;
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('reports an sql-injection (arg0 string)', function () {
|
|
75
|
-
simulateRequestScope(function () {
|
|
76
|
-
const value = ';drop table Foo--';
|
|
77
|
-
const extern = trackString(value);
|
|
78
|
-
|
|
79
|
-
const conn = new Connection();
|
|
80
|
-
conn.query(extern);
|
|
81
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
82
|
-
ruleId: 'sql-injection',
|
|
83
|
-
sinkEvent: {
|
|
84
|
-
name: 'mysql/lib/Connection.query',
|
|
85
|
-
moduleName: 'mysql',
|
|
86
|
-
methodName: 'prototype.query',
|
|
87
|
-
context: `mysql.query('${value}')`,
|
|
88
|
-
object: {
|
|
89
|
-
value: 'mysql.Connection',
|
|
90
|
-
tracked: false,
|
|
91
|
-
},
|
|
92
|
-
args: [{ value, tracked: true }],
|
|
93
|
-
tags: { UNTRUSTED: [0, 16] },
|
|
94
|
-
source: 'P0',
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('reports an sql-injection (arg0 obj)', function () {
|
|
101
|
-
simulateRequestScope(function () {
|
|
102
|
-
const value = ';drop table Foo--';
|
|
103
|
-
const extern = trackString(value);
|
|
104
|
-
|
|
105
|
-
const conn = new Connection();
|
|
106
|
-
conn.query({ sql: extern });
|
|
107
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
108
|
-
ruleId: 'sql-injection',
|
|
109
|
-
sinkEvent: {
|
|
110
|
-
name: 'mysql/lib/Connection.query',
|
|
111
|
-
moduleName: 'mysql',
|
|
112
|
-
methodName: 'prototype.query',
|
|
113
|
-
context: `mysql.query({ sql: '${value}' })`,
|
|
114
|
-
object: {
|
|
115
|
-
value: 'mysql.Connection',
|
|
116
|
-
tracked: false,
|
|
117
|
-
},
|
|
118
|
-
args: [{ value, tracked: true }],
|
|
119
|
-
tags: { UNTRUSTED: [0, 16] },
|
|
120
|
-
source: 'P0',
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('mysql2', function () {
|
|
128
|
-
['query', 'execute'].forEach((method) => {
|
|
129
|
-
describe(`${method}`, function () {
|
|
130
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
131
|
-
const conn = new connection();
|
|
132
|
-
conn[method]('SELECT "foo"');
|
|
133
|
-
expect(reportFindings).not.to.have.been.called;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('skips instrumentation if no argument is provided', function () {
|
|
137
|
-
simulateRequestScope(function () {
|
|
138
|
-
const conn = new connection();
|
|
139
|
-
conn[method]();
|
|
140
|
-
expect(reportFindings).not.to.have.been.called;
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('skips instrumentation if the argument is not a string', function () {
|
|
145
|
-
simulateRequestScope(function () {
|
|
146
|
-
const conn = new connection();
|
|
147
|
-
conn[method]({});
|
|
148
|
-
expect(reportFindings).not.to.have.been.called;
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('skips instrumentation if the argument is not tracked', function () {
|
|
153
|
-
simulateRequestScope(function () {
|
|
154
|
-
const conn = new connection();
|
|
155
|
-
conn[method]('SELECT "foo"');
|
|
156
|
-
expect(reportFindings).not.to.have.been.called;
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('skips instrumentation if the argument is safe', function () {
|
|
161
|
-
simulateRequestScope(function () {
|
|
162
|
-
const tracked = trackString(';drop table Foo--', {
|
|
163
|
-
tags: {
|
|
164
|
-
SQL_ENCODED: [0, 16],
|
|
165
|
-
UNTRUSTED: [0, 16],
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
const { extern } = tracker.getData(tracked);
|
|
169
|
-
|
|
170
|
-
const conn = new connection();
|
|
171
|
-
conn[method](extern);
|
|
172
|
-
expect(reportFindings).not.to.have.been.called;
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('reports an sql-injection (arg0 string)', function () {
|
|
177
|
-
simulateRequestScope(function () {
|
|
178
|
-
const value = ';drop table Foo--';
|
|
179
|
-
const extern = trackString(value);
|
|
180
|
-
|
|
181
|
-
const conn = new connection();
|
|
182
|
-
conn[method](extern);
|
|
183
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
184
|
-
ruleId: 'sql-injection',
|
|
185
|
-
sinkEvent: {
|
|
186
|
-
name: `mysql2/lib/connection.Connection.${method}`,
|
|
187
|
-
object: {
|
|
188
|
-
value: 'mysql2.connection',
|
|
189
|
-
tracked: false,
|
|
190
|
-
},
|
|
191
|
-
args: [{ value, tracked: true }],
|
|
192
|
-
tags: { UNTRUSTED: [0, 16] },
|
|
193
|
-
source: 'P0',
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('reports an sql-injection (arg0 obj)', function () {
|
|
200
|
-
simulateRequestScope(function () {
|
|
201
|
-
const value = ';drop table Foo--';
|
|
202
|
-
const extern = trackString(value);
|
|
203
|
-
|
|
204
|
-
const conn = new connection();
|
|
205
|
-
conn[method]({ sql: extern });
|
|
206
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
207
|
-
ruleId: 'sql-injection',
|
|
208
|
-
sinkEvent: {
|
|
209
|
-
name: `mysql2/lib/connection.Connection.${method}`,
|
|
210
|
-
object: {
|
|
211
|
-
value: 'mysql2.connection',
|
|
212
|
-
tracked: false,
|
|
213
|
-
},
|
|
214
|
-
args: [{ value, tracked: true }],
|
|
215
|
-
tags: { UNTRUSTED: [0, 16] },
|
|
216
|
-
source: 'P0',
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const serialize = require('node-serialize');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow sinks node-serialize', function () {
|
|
9
|
-
let core, simulateRequestScope, trackString, reportFindings, serializedObj;
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
|
|
13
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
14
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
15
|
-
|
|
16
|
-
core.depHooks.resolve.yields(serialize);
|
|
17
|
-
|
|
18
|
-
require('./node-serialize')(core).install();
|
|
19
|
-
|
|
20
|
-
serializedObj = '{"rce":"_$$ND_FUNC$$_function (){}()"}';
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('node-serialize.unserialize', function() {
|
|
24
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
25
|
-
serialize.unserialize(serializedObj);
|
|
26
|
-
expect(reportFindings).not.to.have.been.called;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('skips instrumentation if no argument is provided', function () {
|
|
30
|
-
simulateRequestScope(function () {
|
|
31
|
-
serialize.unserialize(serializedObj);
|
|
32
|
-
expect(reportFindings).not.to.have.been.called;
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('skips instrumentation if instrumentation is locked', function () {
|
|
37
|
-
simulateRequestScope(function () {
|
|
38
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
39
|
-
serialize.unserialize(serializedObj);
|
|
40
|
-
expect(reportFindings).not.to.have.been.called;
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('skips instrumentation if the argument is not a string', function () {
|
|
46
|
-
simulateRequestScope(function () {
|
|
47
|
-
serialize.unserialize(true);
|
|
48
|
-
expect(reportFindings).not.to.have.been.called;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('skips instrumentation if the argument is not tracked', function () {
|
|
53
|
-
simulateRequestScope(function () {
|
|
54
|
-
serialize.unserialize(serializedObj);
|
|
55
|
-
expect(reportFindings).not.to.have.been.called;
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('reports untrusted-deserialization', function () {
|
|
60
|
-
simulateRequestScope(function () {
|
|
61
|
-
const extern = trackString(serializedObj);
|
|
62
|
-
|
|
63
|
-
serialize.unserialize(extern);
|
|
64
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
65
|
-
ruleId: 'untrusted-deserialization',
|
|
66
|
-
sinkEvent: {
|
|
67
|
-
name: 'node-serialize.unserialize',
|
|
68
|
-
moduleName: 'node-serialize',
|
|
69
|
-
methodName: 'unserialize',
|
|
70
|
-
context: 'node-serialize.unserialize({"rce":"_$$ND_FUNC$$_function (){}()"})',
|
|
71
|
-
object: {
|
|
72
|
-
value: 'node-serialize',
|
|
73
|
-
tracked: false,
|
|
74
|
-
},
|
|
75
|
-
args: [{ value: serializedObj, tracked: true }],
|
|
76
|
-
tags: { UNTRUSTED: [0, 37] },
|
|
77
|
-
source: 'P0',
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
DataflowTag: { UNTRUSTED, SQL_ENCODED },
|
|
5
|
-
Rule: { SQL_INJECTION: ruleId },
|
|
6
|
-
} = require('@contrast/common');
|
|
7
|
-
const { expect } = require('chai');
|
|
8
|
-
const sinon = require('sinon');
|
|
9
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow sinks postgres', function () {
|
|
12
|
-
let core, simulateRequestScope, trackString, reportFindings, reportSafePositive;
|
|
13
|
-
|
|
14
|
-
class Client {
|
|
15
|
-
query() { }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class NativeClient {
|
|
19
|
-
query() { }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class Pool {
|
|
23
|
-
query() { }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
beforeEach(function () {
|
|
27
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
28
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
29
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
30
|
-
|
|
31
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'pg', file: 'lib/client.js' })).yields(Client);
|
|
32
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'pg', file: 'lib/native/client.js' })).yields(NativeClient);
|
|
33
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'pg-pool' })).yields(Pool);
|
|
34
|
-
|
|
35
|
-
require('./postgres')(core).install();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
[Client, NativeClient, Pool].forEach((client) => {
|
|
39
|
-
describe(`${client.name}.prototype.query()`, function () {
|
|
40
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
41
|
-
client.prototype.query();
|
|
42
|
-
expect(reportFindings).to.not.have.been.called;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('skips instrumentation if a query is not provided ', function () {
|
|
46
|
-
simulateRequestScope(function () {
|
|
47
|
-
client.prototype.query();
|
|
48
|
-
expect(reportFindings).to.not.have.been.called;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('skips instrumentation if the query is not a string', function () {
|
|
53
|
-
simulateRequestScope(function () {
|
|
54
|
-
client.prototype.query({});
|
|
55
|
-
expect(reportFindings).to.not.have.been.called;
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('skips instrumentation if the query is not a tracked', function () {
|
|
60
|
-
simulateRequestScope(function () {
|
|
61
|
-
client.prototype.query('hello');
|
|
62
|
-
expect(reportFindings).to.not.have.been.called;
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('skips instrumentation if the query is safe', function() {
|
|
67
|
-
simulateRequestScope(function () {
|
|
68
|
-
const value = 'drop table';
|
|
69
|
-
const extern = trackString(value, {
|
|
70
|
-
tags: {
|
|
71
|
-
[SQL_ENCODED]: [0, 9],
|
|
72
|
-
[UNTRUSTED]: [0, 9],
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
client.prototype.query(extern);
|
|
77
|
-
expect(reportFindings).to.not.have.been.called;
|
|
78
|
-
expect(reportSafePositive).to.have.been.calledWithMatch({
|
|
79
|
-
name: sinon.match(/query$/),
|
|
80
|
-
ruleId,
|
|
81
|
-
safeTags: [SQL_ENCODED],
|
|
82
|
-
strInfo: {
|
|
83
|
-
tags: {
|
|
84
|
-
[SQL_ENCODED]: [0, 9],
|
|
85
|
-
[UNTRUSTED]: [0, 9],
|
|
86
|
-
},
|
|
87
|
-
value,
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('reports an sql-injection', function () {
|
|
94
|
-
simulateRequestScope(function () {
|
|
95
|
-
const value = 'drop table';
|
|
96
|
-
const extern = trackString(value, {
|
|
97
|
-
tags: {
|
|
98
|
-
[SQL_ENCODED]: [0, 4],
|
|
99
|
-
[UNTRUSTED]: [0, 9],
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
client.prototype.query(extern);
|
|
104
|
-
|
|
105
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
106
|
-
ruleId,
|
|
107
|
-
sinkEvent: {
|
|
108
|
-
name: sinon.match('query'),
|
|
109
|
-
moduleName: sinon.match('pg'),
|
|
110
|
-
methodName: 'Connection.prototype.query',
|
|
111
|
-
object: {
|
|
112
|
-
value: sinon.match('pg'),
|
|
113
|
-
tracked: false,
|
|
114
|
-
},
|
|
115
|
-
args: [{ value, tracked: true }],
|
|
116
|
-
tags: { [SQL_ENCODED]: [0, 4], [UNTRUSTED]: [0, 9] },
|
|
117
|
-
source: 'P0',
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
['pg.native.Client.prototype.query', 'pg.Client.prototype.query'].forEach((clientType) => {
|
|
126
|
-
it(`skips calling the hook if the ${clientType} is already patched`, function () {
|
|
127
|
-
simulateRequestScope(function () {
|
|
128
|
-
const extern = trackString('drop table', {
|
|
129
|
-
tags: {
|
|
130
|
-
[SQL_ENCODED]: [0, 4],
|
|
131
|
-
[UNTRUSTED]: [0, 9],
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
Pool.prototype.Client = {
|
|
136
|
-
prototype: {
|
|
137
|
-
query: () => { }
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
core.patcher.patch(Pool.prototype.Client.prototype, 'query', {
|
|
142
|
-
name: clientType,
|
|
143
|
-
patchType: 'assess-dataflow-sink',
|
|
144
|
-
pre: () => { }
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
Pool.prototype.query(extern);
|
|
148
|
-
expect(reportFindings).to.not.have.been.called;
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|