@contrast/agent 4.9.1 → 4.10.0
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/lib/assess/propagators/joi/any.js +48 -0
- package/lib/assess/propagators/joi/index.js +2 -0
- package/lib/assess/propagators/joi/object.js +61 -0
- package/lib/assess/propagators/joi/string-base.js +16 -0
- package/lib/assess/propagators/mongoose/string.js +8 -0
- package/lib/core/config/options.js +11 -9
- package/lib/core/express/index.js +3 -0
- package/lib/core/fastify/index.js +2 -1
- package/lib/core/hapi/index.js +2 -1
- package/lib/core/koa/index.js +9 -1
- package/lib/core/rewrite/callees.js +16 -0
- package/lib/core/rewrite/import-declaration.js +71 -0
- package/lib/core/rewrite/index.js +9 -7
- package/lib/core/rewrite/injections.js +5 -1
- package/lib/protect/restify/sources.js +35 -0
- package/lib/protect/rules/nosqli/nosql-injection-rule.js +30 -16
- package/lib/protect/rules/nosqli/nosql-scanner/index.js +1 -1
- package/lib/protect/rules/nosqli/nosql-scanner/rethinkdbscanner.js +26 -0
- package/lib/protect/sinks/index.js +2 -0
- package/lib/protect/sinks/mongodb.js +1 -3
- package/lib/protect/sinks/rethinkdb.js +47 -0
- package/package.json +15 -9
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
Contact: support@contrastsecurity.com
|
|
4
|
+
License: Commercial
|
|
5
|
+
|
|
6
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
made available through public repositories, use of this Software is subject to
|
|
9
|
+
the applicable End User Licensing Agreement found at
|
|
10
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
const requireHook = require('../../../hooks/require');
|
|
16
|
+
const patcher = require('../../../hooks/patcher');
|
|
17
|
+
const {
|
|
18
|
+
PATCH_TYPES: { ASSESS_PROPAGATOR }
|
|
19
|
+
} = require('../../../constants');
|
|
20
|
+
const tracker = require('../../../tracker');
|
|
21
|
+
const agent = require('../../../agent');
|
|
22
|
+
|
|
23
|
+
requireHook.resolve(
|
|
24
|
+
{ name: 'joi', file: 'lib/types/any.js', version: '>=17.0.0' },
|
|
25
|
+
(object) => {
|
|
26
|
+
if (
|
|
27
|
+
!agent.config ||
|
|
28
|
+
(agent.config && !agent.config.agent.trust_custom_validators)
|
|
29
|
+
) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
patcher.patch(object._definition.rules.custom, 'validate', {
|
|
34
|
+
name: 'joi.any.custom.validate',
|
|
35
|
+
patchType: ASSESS_PROPAGATOR,
|
|
36
|
+
alwaysRun: true,
|
|
37
|
+
post(data) {
|
|
38
|
+
if (data.result && typeof data.result === 'string') {
|
|
39
|
+
tracker.untrack(data.result);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (data.args[0] && typeof data.args[0] === 'string') {
|
|
43
|
+
tracker.untrack(data.args[0]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
Contact: support@contrastsecurity.com
|
|
4
|
+
License: Commercial
|
|
5
|
+
|
|
6
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
made available through public repositories, use of this Software is subject to
|
|
9
|
+
the applicable End User Licensing Agreement found at
|
|
10
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
const requireHook = require('../../../hooks/require');
|
|
16
|
+
const patcher = require('../../../hooks/patcher');
|
|
17
|
+
const {
|
|
18
|
+
PATCH_TYPES: { ASSESS_PROPAGATOR }
|
|
19
|
+
} = require('../../../constants');
|
|
20
|
+
const tracker = require('../../../tracker');
|
|
21
|
+
const agent = require('../../../agent');
|
|
22
|
+
|
|
23
|
+
const traverseObjectAndUntrack = (object, incomingInput, result) => {
|
|
24
|
+
if (object.type === 'object' && object.$_terms.keys) {
|
|
25
|
+
object.$_terms.keys.forEach(({ key, schema }) => {
|
|
26
|
+
traverseObjectAndUntrack(schema, incomingInput[key], result[key]);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
object.type === 'string' &&
|
|
32
|
+
Array.isArray(object.$_terms.externals) &&
|
|
33
|
+
object.$_terms.externals.length
|
|
34
|
+
) {
|
|
35
|
+
tracker.untrack(incomingInput);
|
|
36
|
+
tracker.untrack(result);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
requireHook.resolve(
|
|
41
|
+
{ name: 'joi', file: 'lib/types/object.js', version: '>=17.0.0' },
|
|
42
|
+
(object) => {
|
|
43
|
+
if (
|
|
44
|
+
!agent.config ||
|
|
45
|
+
(agent.config && !agent.config.agent.trust_custom_validators)
|
|
46
|
+
) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
patcher.patch(object.__proto__, 'validateAsync', {
|
|
51
|
+
name: 'joi.object.validateAsync',
|
|
52
|
+
patchType: ASSESS_PROPAGATOR,
|
|
53
|
+
alwaysRun: true,
|
|
54
|
+
post(data) {
|
|
55
|
+
data.result.then((result) =>
|
|
56
|
+
traverseObjectAndUntrack(data.obj, data.args[0], result)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
);
|
|
@@ -24,6 +24,7 @@ const tracker = require('../../../tracker');
|
|
|
24
24
|
const { PropagationEvent, Signature, CallContext } = require('../../models');
|
|
25
25
|
const TagRange = require('../../models/tag-range');
|
|
26
26
|
const tagRangeUtil = require('../../models/tag-range/util');
|
|
27
|
+
const agent = require('../../../agent');
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Patch joi.string.validate so that it tags input with string-type-checked if validated
|
|
@@ -54,6 +55,21 @@ function instrumentJoiString(string) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
if (agent.config.agent.trust_custom_validators) {
|
|
60
|
+
patcher.patch(string.__proto__, 'validateAsync', {
|
|
61
|
+
name: 'joi.string.validateAsync',
|
|
62
|
+
patchType: ASSESS_PROPAGATOR,
|
|
63
|
+
alwaysRun: true,
|
|
64
|
+
post(data) {
|
|
65
|
+
if (!data.obj.$_terms.externals.length) return;
|
|
66
|
+
data.result.then((result) => {
|
|
67
|
+
tracker.untrack(data.args[0]);
|
|
68
|
+
tracker.untrack(result);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
57
73
|
}
|
|
58
74
|
|
|
59
75
|
requireHook.resolve(
|
|
@@ -24,6 +24,7 @@ const {
|
|
|
24
24
|
const TagRange = require('../../models/tag-range');
|
|
25
25
|
const { CallContext, PropagationEvent, Signature } = require('../../models');
|
|
26
26
|
const { hasUserDefinedValidator } = require('./helpers');
|
|
27
|
+
const agent = require('../../../agent');
|
|
27
28
|
|
|
28
29
|
const enumPatcher = (SchemaString) => {
|
|
29
30
|
patcher.patch(SchemaString.prototype, 'enum', {
|
|
@@ -98,6 +99,13 @@ const doValidateSyncPatcher = (SchemaString) => {
|
|
|
98
99
|
requireHook.resolve(
|
|
99
100
|
{ name: 'mongoose', file: 'lib/schema/string.js', version: '>=5.0.0' },
|
|
100
101
|
(SchemaString) => {
|
|
102
|
+
if (
|
|
103
|
+
!agent.config ||
|
|
104
|
+
(agent.config && !agent.config.agent.trust_custom_validators)
|
|
105
|
+
) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
enumPatcher(SchemaString);
|
|
102
110
|
doValidateSyncPatcher(SchemaString);
|
|
103
111
|
}
|
|
@@ -487,6 +487,12 @@ const agent = [
|
|
|
487
487
|
desc:
|
|
488
488
|
'set limit for stack trace size (larger limits will improve accuracy but increase memory usage)'
|
|
489
489
|
},
|
|
490
|
+
{
|
|
491
|
+
name: 'agent.trust_custom_validators',
|
|
492
|
+
arg: '<trust-custom-validators>',
|
|
493
|
+
default: false,
|
|
494
|
+
desc: `trust incoming strings when they pass custom validators (Mongoose, Joi)`
|
|
495
|
+
},
|
|
490
496
|
{
|
|
491
497
|
name: 'agent.traverse_and_track',
|
|
492
498
|
arg: '<traverse-and-track>',
|
|
@@ -977,11 +983,11 @@ if (process.env.CONTRAST_DEV) {
|
|
|
977
983
|
const sails = [
|
|
978
984
|
{
|
|
979
985
|
name: 'pathToSails',
|
|
980
|
-
arg: '<path>'
|
|
986
|
+
arg: '<path>'
|
|
981
987
|
},
|
|
982
988
|
{
|
|
983
989
|
name: 'gdsrc',
|
|
984
|
-
arg: '<path>'
|
|
990
|
+
arg: '<path>'
|
|
985
991
|
}
|
|
986
992
|
];
|
|
987
993
|
|
|
@@ -1030,16 +1036,12 @@ options.forEach((option) => {
|
|
|
1030
1036
|
// The agent doesn't need to do anything with these options. It just needs to not
|
|
1031
1037
|
// throw an error when it encounters them but we also don't need them displayed on
|
|
1032
1038
|
// the agent's config option list. The newest version of Commander lets us do exactly this.
|
|
1033
|
-
// This is structured so that if anything like this is discovered again, they can be
|
|
1039
|
+
// This is structured so that if anything like this is discovered again, they can be
|
|
1034
1040
|
// added in easily.
|
|
1035
|
-
const hiddenOptions = [].concat(
|
|
1036
|
-
sails
|
|
1037
|
-
)
|
|
1041
|
+
const hiddenOptions = [].concat(sails);
|
|
1038
1042
|
|
|
1039
1043
|
hiddenOptions.forEach((option) => {
|
|
1040
|
-
program.addOption(
|
|
1041
|
-
new Option(`--${option.name} ${option.arg}`).hideHelp()
|
|
1042
|
-
)
|
|
1044
|
+
program.addOption(new Option(`--${option.name} ${option.arg}`).hideHelp());
|
|
1043
1045
|
});
|
|
1044
1046
|
|
|
1045
1047
|
function getDefault(optionName) {
|
package/lib/core/hapi/index.js
CHANGED
package/lib/core/koa/index.js
CHANGED
|
@@ -216,13 +216,21 @@ class KoaCore {
|
|
|
216
216
|
*/
|
|
217
217
|
registerRequestHandler(ctx) {
|
|
218
218
|
ctx.req.request = ctx.request;
|
|
219
|
+
const { query } = ctx.request;
|
|
219
220
|
ctx.request = new Proxy(ctx.request, {
|
|
220
221
|
set(...args) {
|
|
221
222
|
const [obj, prop] = args;
|
|
222
223
|
const result = Reflect.set(...args);
|
|
224
|
+
if (query) {
|
|
225
|
+
decorateRequest({
|
|
226
|
+
query
|
|
227
|
+
});
|
|
228
|
+
}
|
|
223
229
|
switch (prop) {
|
|
224
230
|
case 'body':
|
|
225
|
-
decorateRequest({
|
|
231
|
+
decorateRequest({
|
|
232
|
+
body: obj[prop]
|
|
233
|
+
});
|
|
226
234
|
agentEmitter.emit(constants.EVENTS.CTX_REQUEST_BODY, {
|
|
227
235
|
request: obj,
|
|
228
236
|
ctx
|
|
@@ -67,6 +67,22 @@ const specs = [
|
|
|
67
67
|
token: 'eval',
|
|
68
68
|
modes: { assess: true, protect: true }
|
|
69
69
|
},
|
|
70
|
+
// Import Declaration
|
|
71
|
+
{
|
|
72
|
+
name: '__importDefault',
|
|
73
|
+
type: 'ImportDefaultSpecifier',
|
|
74
|
+
modes: { assess: true, protect: true }
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: '__importNamespace',
|
|
78
|
+
type: 'ImportNamespaceSpecifier',
|
|
79
|
+
modes: { assess: true, protect: true }
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: '__import',
|
|
83
|
+
type: 'ImportSpecifier',
|
|
84
|
+
modes: { assess: true, protect: true }
|
|
85
|
+
},
|
|
70
86
|
// Member Expression
|
|
71
87
|
{
|
|
72
88
|
name: '__forceCopy',
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
Contact: support@contrastsecurity.com
|
|
4
|
+
License: Commercial
|
|
5
|
+
|
|
6
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
made available through public repositories, use of this Software is subject to
|
|
9
|
+
the applicable End User Licensing Agreement found at
|
|
10
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const t = require('@babel/types');
|
|
18
|
+
const _ = require('lodash');
|
|
19
|
+
|
|
20
|
+
const IMPORT_META_URL_MEMBER_EXPRESSION = t.memberExpression(
|
|
21
|
+
t.memberExpression(t.identifier('import'), t.identifier('meta')),
|
|
22
|
+
t.identifier('url')
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Appends calls to our own instrumentable import methods, providing access to
|
|
27
|
+
* the imported modules.
|
|
28
|
+
* ```
|
|
29
|
+
* import x from 'mod';
|
|
30
|
+
* // becomes:
|
|
31
|
+
* import x from 'mod';
|
|
32
|
+
* ContrastMethods.__importDefault(x, 'mod', import.meta.url);
|
|
33
|
+
*
|
|
34
|
+
* import * as x from 'mod';
|
|
35
|
+
* // becomes:
|
|
36
|
+
* import x from 'mod';
|
|
37
|
+
* ContrastMethods.__importNamespace(x, 'mod', import.meta.url);
|
|
38
|
+
*
|
|
39
|
+
* import { foo, bar as baz } from 'mod';;
|
|
40
|
+
* // becomes
|
|
41
|
+
* ContrastMethods.__import(foo, 'foo', 'mod', import.meta.url);
|
|
42
|
+
* ContrastMethods.__import(baz, 'bar', 'mod', import.meta.url);
|
|
43
|
+
* ```
|
|
44
|
+
* @param {import('@babel/traverse').NodePath<import('@babel/types').ImportDeclaration>} path
|
|
45
|
+
* @param {import('.').State} state
|
|
46
|
+
*/
|
|
47
|
+
module.exports = function ImportDeclaration(path, state) {
|
|
48
|
+
const { source, specifiers } = path.node;
|
|
49
|
+
|
|
50
|
+
path.insertAfter(
|
|
51
|
+
specifiers.map((importSpec) => {
|
|
52
|
+
const spec = _.find(state.specs, { type: importSpec.type });
|
|
53
|
+
if (!spec || !state.callees[spec.name]) return;
|
|
54
|
+
|
|
55
|
+
const args = [importSpec.local];
|
|
56
|
+
|
|
57
|
+
if (t.isImportSpecifier(importSpec)) {
|
|
58
|
+
args.push(
|
|
59
|
+
t.isIdentifier(importSpec.imported)
|
|
60
|
+
? t.stringLiteral(importSpec.imported.name)
|
|
61
|
+
: importSpec.imported
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
args.push(source);
|
|
66
|
+
args.push(IMPORT_META_URL_MEMBER_EXPRESSION);
|
|
67
|
+
|
|
68
|
+
return t.callExpression(state.callees[spec.name], args);
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -18,23 +18,24 @@ const { default: generate } = require('@babel/generator');
|
|
|
18
18
|
const { parse } = require('@babel/parser');
|
|
19
19
|
const { default: traverse } = require('@babel/traverse');
|
|
20
20
|
|
|
21
|
+
const RewriteDeadzones = require('../../assess/deadzones/rewrite');
|
|
22
|
+
const { util: sourceMapUtility } = require('../../util/source-map');
|
|
21
23
|
const Scopes = require('../async-storage/scopes');
|
|
22
24
|
const logger = require('../logger')('contrast:rewrite');
|
|
23
|
-
const RewriteDeadzones = require('../../assess/deadzones/rewrite');
|
|
24
|
-
const logRewrite = require('./log');
|
|
25
|
-
const RewriteLog = require('./rewrite-log');
|
|
26
|
-
const isContrastMethod = require('./is-contrast-method');
|
|
27
|
-
const functionWrap = require('./function-wrap');
|
|
28
|
-
const prependGlobals = require('./prepend-globals');
|
|
29
25
|
const AssignmentExpression = require('./assignment-expression');
|
|
30
26
|
const BinaryExpression = require('./binary-expression');
|
|
31
27
|
const CallExpression = require('./call-expression');
|
|
32
28
|
const CatchClause = require('./catch-clause');
|
|
29
|
+
const functionWrap = require('./function-wrap');
|
|
30
|
+
const ImportDeclaration = require('./import-declaration');
|
|
31
|
+
const isContrastMethod = require('./is-contrast-method');
|
|
32
|
+
const logRewrite = require('./log');
|
|
33
33
|
const MemberExpression = require('./member-expression');
|
|
34
34
|
const ObjectProperty = require('./object-property');
|
|
35
|
+
const prependGlobals = require('./prepend-globals');
|
|
36
|
+
const RewriteLog = require('./rewrite-log');
|
|
35
37
|
const SwitchStatement = require('./switch-statement');
|
|
36
38
|
const TemplateLiteral = require('./template-literal');
|
|
37
|
-
const sourceMapUtility = require('../../util/source-map').util;
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* @typedef {Object} State
|
|
@@ -105,6 +106,7 @@ class Rewriter {
|
|
|
105
106
|
BinaryExpression,
|
|
106
107
|
CallExpression,
|
|
107
108
|
CatchClause,
|
|
109
|
+
ImportDeclaration,
|
|
108
110
|
MemberExpression,
|
|
109
111
|
ObjectProperty,
|
|
110
112
|
SwitchStatement,
|
|
@@ -100,7 +100,11 @@ const ContrastMethods = new Injection(null, 'ContrastMethods', {
|
|
|
100
100
|
},
|
|
101
101
|
__contrastEval: function __contrastEval(str) {
|
|
102
102
|
return str;
|
|
103
|
-
}
|
|
103
|
+
},
|
|
104
|
+
// TODO: NODE-2020
|
|
105
|
+
__importDefault(mod, source, url) {},
|
|
106
|
+
__importNamespace(mod, source, url) {},
|
|
107
|
+
__import(mod, spec, source, url) {}
|
|
104
108
|
});
|
|
105
109
|
|
|
106
110
|
ContrastMethods.enable();
|
|
@@ -21,6 +21,8 @@ const {
|
|
|
21
21
|
} = require('../../constants');
|
|
22
22
|
const { emitSourceEvent } = require('../../hooks/frameworks/common');
|
|
23
23
|
const agentEmitter = require('../../agent-emitter');
|
|
24
|
+
const patcher = require('../../hooks/patcher');
|
|
25
|
+
const { PATCH_TYPES } = require('../../constants');
|
|
24
26
|
const {
|
|
25
27
|
utils,
|
|
26
28
|
constants: { EVENTS }
|
|
@@ -39,6 +41,39 @@ class RestifyProtectSources {
|
|
|
39
41
|
EVENTS.CREATE_SERVER,
|
|
40
42
|
this.registerUrlParamsHandler.bind(this)
|
|
41
43
|
);
|
|
44
|
+
agentEmitter.on(
|
|
45
|
+
EVENTS.RESTIFY_EXPORT,
|
|
46
|
+
this.registerQueryParamsHandler.bind(this)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Patches query parser middleware to wrap the callback argument. Once this
|
|
53
|
+
* wrapped callback is invoked w/out error we know we can proxy `req.query`.
|
|
54
|
+
* @param {object} restify
|
|
55
|
+
*/
|
|
56
|
+
registerQueryParamsHandler(restify) {
|
|
57
|
+
const {
|
|
58
|
+
plugins: { queryParser: origQueryParser }
|
|
59
|
+
} = restify;
|
|
60
|
+
|
|
61
|
+
if (origQueryParser) {
|
|
62
|
+
patcher.patch(restify.plugins, 'queryParser', {
|
|
63
|
+
name: 'restify.plugins',
|
|
64
|
+
patchType: PATCH_TYPES.FRAMEWORK,
|
|
65
|
+
alwaysRun: true,
|
|
66
|
+
post(data) {
|
|
67
|
+
patcher.patch(data, 'result', {
|
|
68
|
+
name: 'restify.plugins.queryParser',
|
|
69
|
+
patchType: PATCH_TYPES.PROTECT_SOURCE,
|
|
70
|
+
alwaysRun: true,
|
|
71
|
+
post(data) {
|
|
72
|
+
decorateRequest({ query: get(data.args[0], 'query') });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
42
77
|
}
|
|
43
78
|
}
|
|
44
79
|
|
|
@@ -26,9 +26,11 @@ const brackets = /\[(.{1,1024}?)\]/;
|
|
|
26
26
|
const child = /\[(.{1,1024}?)\]/g;
|
|
27
27
|
|
|
28
28
|
const MONGODB = 'mongodb';
|
|
29
|
+
const RETHINKDB = 'rethinkdb';
|
|
29
30
|
|
|
30
31
|
const ScannerKit = new Map([
|
|
31
|
-
[MONGODB, () => require('../nosqli/nosql-scanner').create('MongoDB')]
|
|
32
|
+
[MONGODB, () => require('../nosqli/nosql-scanner').create('MongoDB')],
|
|
33
|
+
[RETHINKDB, () => require('../nosqli/nosql-scanner').create('RethinkDB')]
|
|
32
34
|
]);
|
|
33
35
|
const SubstringFinder = require('../base-scanner/substring-finder');
|
|
34
36
|
|
|
@@ -144,27 +146,14 @@ class NoSqlInjectionRule extends require('../') {
|
|
|
144
146
|
_documentType === constants.INPUT_TYPES.PARAMETER_NAME &&
|
|
145
147
|
_documentPath.length <= 1024
|
|
146
148
|
) {
|
|
147
|
-
|
|
148
|
-
const parent = segment
|
|
149
|
-
? _documentPath.slice(0, segment.index)
|
|
150
|
-
: _documentPath;
|
|
151
|
-
|
|
152
|
-
pathArray.push('query');
|
|
153
|
-
|
|
154
|
-
if (parent) {
|
|
155
|
-
pathArray.push(parent);
|
|
156
|
-
}
|
|
157
|
-
while ((segment = child.exec(_documentPath))) {
|
|
158
|
-
pathArray.push(segment[1]);
|
|
159
|
-
}
|
|
160
|
-
pathArray.pop();
|
|
149
|
+
this.buildPathArray(_documentPath, pathArray);
|
|
161
150
|
} else {
|
|
162
151
|
// only qs params and body are "expandable"
|
|
163
152
|
pathArray.push('body', ..._documentPath.split('.'));
|
|
164
153
|
}
|
|
165
154
|
|
|
166
155
|
let data;
|
|
167
|
-
let curr = ctx.
|
|
156
|
+
let curr = ctx.request;
|
|
168
157
|
|
|
169
158
|
for (const path of pathArray) {
|
|
170
159
|
if (curr) {
|
|
@@ -175,6 +164,31 @@ class NoSqlInjectionRule extends require('../') {
|
|
|
175
164
|
return data;
|
|
176
165
|
}
|
|
177
166
|
|
|
167
|
+
buildPathArray(documentPath, pathArray) {
|
|
168
|
+
const documentPathArray = documentPath.split('.');
|
|
169
|
+
|
|
170
|
+
pathArray.push('query');
|
|
171
|
+
documentPathArray.forEach((dotSegment) => {
|
|
172
|
+
let lastChar;
|
|
173
|
+
let bracketSegment = brackets.exec(dotSegment);
|
|
174
|
+
let parent = bracketSegment
|
|
175
|
+
? dotSegment.slice(0, bracketSegment.index)
|
|
176
|
+
: dotSegment;
|
|
177
|
+
if (parent) {
|
|
178
|
+
lastChar = parent.slice(-1);
|
|
179
|
+
parent = lastChar === ']' ? parent.slice(0, -1) : parent;
|
|
180
|
+
pathArray.push(parent);
|
|
181
|
+
}
|
|
182
|
+
while ((bracketSegment = child.exec(dotSegment))) {
|
|
183
|
+
lastChar = bracketSegment[1].slice(-1);
|
|
184
|
+
const segment =
|
|
185
|
+
lastChar === ']' ? bracketSegment[1].slice(0, -1) : bracketSegment[1];
|
|
186
|
+
pathArray.push(segment);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
pathArray.pop();
|
|
190
|
+
}
|
|
191
|
+
|
|
178
192
|
getScanner(id) {
|
|
179
193
|
if (!ScannerKit.has(id)) {
|
|
180
194
|
throw new Error(`Unknown NoSQL scanner: ${id}`);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
Contact: support@contrastsecurity.com
|
|
4
|
+
License: Commercial
|
|
5
|
+
|
|
6
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
made available through public repositories, use of this Software is subject to
|
|
9
|
+
the applicable End User Licensing Agreement found at
|
|
10
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* RethinkDB scanner module
|
|
17
|
+
* @module lib/protect/rules/nosql/nosql-scanner/RethinkDBScanner
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const { BaseScanner } = require('../../base-scanner');
|
|
23
|
+
|
|
24
|
+
class RethinkDBScanner extends BaseScanner {}
|
|
25
|
+
|
|
26
|
+
module.exports = RethinkDBScanner;
|
|
@@ -29,6 +29,7 @@ const MongoDBSink = require('./mongodb');
|
|
|
29
29
|
const MySQLSink = require('./mysql');
|
|
30
30
|
const NodeSerializeSink = require('./node-serialize');
|
|
31
31
|
const PostgresSink = require('./postgres');
|
|
32
|
+
const RethinkDBSink = require('./rethinkdb');
|
|
32
33
|
const SequelizeSink = require('./sequelize');
|
|
33
34
|
const Sqlite3Sink = require('./sqlite3');
|
|
34
35
|
const VMSink = require('./vm');
|
|
@@ -46,6 +47,7 @@ module.exports = function init(agent) {
|
|
|
46
47
|
new MySQLSink(agent).install({ ModuleHook });
|
|
47
48
|
new NodeSerializeSink(agent).install({ ModuleHook });
|
|
48
49
|
new PostgresSink(agent).install({ ModuleHook });
|
|
50
|
+
new RethinkDBSink(agent).install({ ModuleHook });
|
|
49
51
|
new SequelizeSink(agent).install({ ModuleHook });
|
|
50
52
|
new VMSink(agent).install({ ModuleHook });
|
|
51
53
|
new Sqlite3Sink(agent).install({ ModuleHook });
|
|
@@ -21,8 +21,6 @@ const BaseSensor = require('../../hooks/frameworks/base');
|
|
|
21
21
|
const patcher = require('../../hooks/patcher');
|
|
22
22
|
const { PATCH_TYPES } = require('../../constants');
|
|
23
23
|
const { emitSinkEvent } = require('../../hooks/frameworks/common');
|
|
24
|
-
const agentEmitter = require('../../agent-emitter');
|
|
25
|
-
const SinkEvent = require('../models/sink-event');
|
|
26
24
|
|
|
27
25
|
const { SINK_TYPES } = constants;
|
|
28
26
|
const ID = 'mongodb';
|
|
@@ -37,7 +35,7 @@ function getCursorQueryData(args, version) {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
if (_.isString(query)) {
|
|
40
|
-
return query.toString()
|
|
38
|
+
return query.toString();
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
if (query['$where']) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
Contact: support@contrastsecurity.com
|
|
4
|
+
License: Commercial
|
|
5
|
+
|
|
6
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
made available through public repositories, use of this Software is subject to
|
|
9
|
+
the applicable End User Licensing Agreement found at
|
|
10
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const constants = require('../../constants');
|
|
18
|
+
const BaseSensor = require('../../hooks/frameworks/base');
|
|
19
|
+
const patcher = require('../../hooks/patcher');
|
|
20
|
+
const { PATCH_TYPES } = require('../../constants');
|
|
21
|
+
const { emitSinkEvent } = require('../../hooks/frameworks/common');
|
|
22
|
+
|
|
23
|
+
const { SINK_TYPES } = constants;
|
|
24
|
+
const ID = 'rethinkdb';
|
|
25
|
+
|
|
26
|
+
class RethinkDBSensor extends BaseSensor {
|
|
27
|
+
constructor(agent) {
|
|
28
|
+
super({ id: ID, agent });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
install({ ModuleHook }) {
|
|
32
|
+
ModuleHook.resolve({ name: 'rethinkdb' }, (rethinkdb) => {
|
|
33
|
+
patcher.patch(rethinkdb, 'js', {
|
|
34
|
+
alwaysRun: true,
|
|
35
|
+
name: 'rethinkdb',
|
|
36
|
+
patchType: PATCH_TYPES.PROTECT_SINK,
|
|
37
|
+
pre: (data) => {
|
|
38
|
+
emitSinkEvent(data.args[0], SINK_TYPES.NOSQL_QUERY, ID);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = RethinkDBSensor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agent",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Node.js security instrumentation by Contrast Security",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"security",
|
|
@@ -19,7 +19,13 @@
|
|
|
19
19
|
"Griffin Yourick",
|
|
20
20
|
"Ati Ok",
|
|
21
21
|
"Pat McClory",
|
|
22
|
-
"Michael Woytowitz"
|
|
22
|
+
"Michael Woytowitz",
|
|
23
|
+
"Jacob Kaplan",
|
|
24
|
+
"Yulia Tenincheva",
|
|
25
|
+
"Bruce MacNaughton",
|
|
26
|
+
"Krasen Penchev",
|
|
27
|
+
"Ivaylo Grahlyov",
|
|
28
|
+
"Yavor Stoychev"
|
|
23
29
|
],
|
|
24
30
|
"scripts": {
|
|
25
31
|
"docs": "jsdoc -c ../.jsdoc.json",
|
|
@@ -72,10 +78,10 @@
|
|
|
72
78
|
"@babel/types": "^7.12.1",
|
|
73
79
|
"@contrast/distringuish-prebuilt": "^2.2.0",
|
|
74
80
|
"@contrast/flat": "^4.1.1",
|
|
75
|
-
"@contrast/fn-inspect": "^2.4.
|
|
81
|
+
"@contrast/fn-inspect": "^2.4.4",
|
|
76
82
|
"@contrast/heapdump": "^1.1.0",
|
|
77
|
-
"@contrast/protobuf-api": "^3.2.
|
|
78
|
-
"@contrast/require-hook": "^2.0.
|
|
83
|
+
"@contrast/protobuf-api": "^3.2.3",
|
|
84
|
+
"@contrast/require-hook": "^2.0.8",
|
|
79
85
|
"@contrast/synchronous-source-maps": "^1.1.0",
|
|
80
86
|
"amqp-connection-manager": "^3.2.2",
|
|
81
87
|
"amqplib": "^0.8.0",
|
|
@@ -109,7 +115,7 @@
|
|
|
109
115
|
"@bmacnaughton/string-generator": "^1.0.0",
|
|
110
116
|
"@contrast/eslint-config": "^2.0.1",
|
|
111
117
|
"@contrast/fake-module": "file:test/mock/contrast-fake",
|
|
112
|
-
"@contrast/screener-service": "^1.12.
|
|
118
|
+
"@contrast/screener-service": "^1.12.9",
|
|
113
119
|
"@hapi/boom": "file:test/mock/boom",
|
|
114
120
|
"@hapi/hapi": "file:test/mock/hapi",
|
|
115
121
|
"@ls-lint/ls-lint": "^1.8.1",
|
|
@@ -142,13 +148,13 @@
|
|
|
142
148
|
"husky": "^6.0.0",
|
|
143
149
|
"inquirer": "^8.1.2",
|
|
144
150
|
"joi": "^17.4.0",
|
|
145
|
-
"jsdoc": "^3.6.
|
|
151
|
+
"jsdoc": "^3.6.10",
|
|
146
152
|
"libxmljs": "file:test/mock/libxmljs",
|
|
147
153
|
"libxmljs2": "file:test/mock/libxmljs2",
|
|
148
154
|
"lint-staged": "^12.0.2",
|
|
149
155
|
"madge": "^4.0.1",
|
|
150
156
|
"marsdb": "file:test/mock/marsdb",
|
|
151
|
-
"mocha": "^9.
|
|
157
|
+
"mocha": "^9.2.0",
|
|
152
158
|
"mochawesome": "^7.0.1",
|
|
153
159
|
"mongodb": "file:test/mock/mongodb",
|
|
154
160
|
"mongodb-npm": "npm:mongodb@^3.6.5",
|
|
@@ -156,7 +162,7 @@
|
|
|
156
162
|
"mustache": "^3.0.1",
|
|
157
163
|
"mysql": "file:test/mock/mysql",
|
|
158
164
|
"nock": "^12.0.3",
|
|
159
|
-
"node-fetch": "^2.6.
|
|
165
|
+
"node-fetch": "^2.6.7",
|
|
160
166
|
"node-serialize": "file:test/mock/node-serialize",
|
|
161
167
|
"npm-license-crawler": "^0.2.1",
|
|
162
168
|
"nyc": "^15.1.0",
|