@contrast/assess 1.9.0 → 1.11.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/dataflow/event-factory.js +1 -1
- package/lib/dataflow/index.js +1 -1
- package/lib/dataflow/propagation/common.js +1 -1
- package/lib/dataflow/propagation/index.js +3 -1
- package/lib/dataflow/propagation/install/JSON/index.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse.js +1 -1
- package/lib/dataflow/propagation/install/JSON/stringify.js +1 -1
- package/lib/dataflow/propagation/install/array-prototype-join.js +1 -1
- package/lib/dataflow/propagation/install/buffer.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/number.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/string.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/tag.js +1 -1
- package/lib/dataflow/propagation/install/decode-uri-component.js +1 -1
- package/lib/dataflow/propagation/install/ejs/escape-xml.js +1 -1
- package/lib/dataflow/propagation/install/ejs/index.js +1 -1
- package/lib/dataflow/propagation/install/encode-uri-component.js +1 -1
- package/lib/dataflow/propagation/install/escape-html.js +1 -1
- package/lib/dataflow/propagation/install/escape.js +1 -1
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +1 -1
- package/lib/dataflow/propagation/install/isnumeric-0.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/common.js +20 -0
- package/lib/dataflow/propagation/install/mongoose/index.js +5 -9
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +149 -0
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +162 -0
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +91 -37
- package/lib/dataflow/propagation/install/mysql-connection-escape.js +1 -1
- package/lib/dataflow/propagation/install/parse-int.js +1 -1
- package/lib/dataflow/propagation/install/path/basename.js +124 -0
- package/lib/dataflow/propagation/install/path/common.js +176 -0
- package/lib/dataflow/propagation/install/path/index.js +32 -0
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +141 -0
- package/lib/dataflow/propagation/install/path/normalize.js +123 -0
- package/lib/dataflow/propagation/install/pug/index.js +1 -1
- package/lib/dataflow/propagation/install/pug-runtime-escape.js +1 -1
- package/lib/dataflow/propagation/install/querystring/index.js +1 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +2 -2
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +182 -0
- package/lib/dataflow/propagation/install/sequelize.js +1 -1
- package/lib/dataflow/propagation/install/sql-template-strings.js +1 -1
- package/lib/dataflow/propagation/install/string/concat.js +1 -1
- package/lib/dataflow/propagation/install/string/format-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/index.js +65 -1
- package/lib/dataflow/propagation/install/string/match-all.js +236 -0
- package/lib/dataflow/propagation/install/string/match.js +84 -38
- package/lib/dataflow/propagation/install/string/replace.js +3 -3
- package/lib/dataflow/propagation/install/string/slice.js +2 -2
- package/lib/dataflow/propagation/install/string/split.js +2 -2
- package/lib/dataflow/propagation/install/string/substring.js +3 -3
- package/lib/dataflow/propagation/install/string/trim.js +2 -2
- package/lib/dataflow/propagation/install/unescape.js +1 -1
- package/lib/dataflow/propagation/install/url/domain-parsers.js +1 -1
- package/lib/dataflow/propagation/install/url/index.js +4 -1
- package/lib/dataflow/propagation/install/url/parse.js +131 -0
- package/lib/dataflow/propagation/install/url/searchParams.js +133 -0
- package/lib/dataflow/propagation/install/url/url.js +185 -0
- package/lib/dataflow/propagation/install/validator/hooks.js +1 -1
- package/lib/dataflow/propagation/install/validator/index.js +1 -1
- package/lib/dataflow/propagation/install/validator/methods.js +1 -1
- package/lib/dataflow/sinks/common.js +1 -1
- package/lib/dataflow/sinks/index.js +9 -5
- package/lib/dataflow/sinks/install/child-process.js +1 -1
- package/lib/dataflow/sinks/install/eval.js +138 -0
- package/lib/dataflow/sinks/install/express/index.js +1 -1
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +2 -2
- package/lib/dataflow/sinks/install/fastify/index.js +1 -1
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +3 -2
- package/lib/dataflow/sinks/install/fs.js +4 -4
- package/lib/dataflow/sinks/install/function.js +160 -0
- package/lib/dataflow/sinks/install/http/index.js +31 -0
- package/lib/dataflow/sinks/install/http/request.js +152 -0
- package/lib/dataflow/sinks/install/{http.js → http/server-response.js} +3 -3
- package/lib/dataflow/sinks/install/koa/index.js +1 -1
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +2 -2
- package/lib/dataflow/sinks/install/marsdb.js +1 -1
- package/lib/dataflow/sinks/install/mongodb.js +34 -46
- package/lib/dataflow/sinks/install/mssql.js +45 -32
- package/lib/dataflow/sinks/install/mysql.js +1 -1
- package/lib/dataflow/sinks/install/postgres.js +1 -1
- package/lib/dataflow/sinks/install/sequelize.js +1 -1
- package/lib/dataflow/sinks/install/sqlite3.js +1 -1
- package/lib/dataflow/sinks/install/vm.js +276 -0
- package/lib/dataflow/sources/common.js +1 -1
- package/lib/dataflow/sources/handler.js +1 -1
- package/lib/dataflow/sources/index.js +1 -1
- package/lib/dataflow/sources/install/body-parser1.js +1 -1
- package/lib/dataflow/sources/install/busboy1.js +1 -1
- package/lib/dataflow/sources/install/cookie-parser1.js +1 -1
- package/lib/dataflow/sources/install/express/index.js +1 -1
- package/lib/dataflow/sources/install/express/params.js +1 -1
- package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
- package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
- package/lib/dataflow/sources/install/fastify/index.js +1 -1
- package/lib/dataflow/sources/install/formidable1.js +1 -1
- package/lib/dataflow/sources/install/http.js +1 -1
- package/lib/dataflow/sources/install/koa/index.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-routers.js +1 -1
- package/lib/dataflow/sources/install/koa/koa2.js +1 -1
- package/lib/dataflow/sources/install/qs6.js +1 -1
- package/lib/dataflow/sources/install/querystring.js +1 -1
- package/lib/dataflow/tag-utils.js +71 -2
- package/lib/dataflow/tracker.js +1 -1
- package/lib/dataflow/utils/is-safe-content-type.js +1 -1
- package/lib/dataflow/utils/is-vulnerable.js +1 -1
- package/lib/index.js +1 -1
- package/lib/response-scanning/handlers/index.js +36 -30
- package/lib/response-scanning/handlers/utils.js +1 -1
- package/lib/response-scanning/index.js +1 -1
- package/lib/response-scanning/install/http.js +3 -3
- package/lib/session-configuration/index.js +1 -1
- package/lib/session-configuration/install/http.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { patchType } = require('../../common');
|
|
19
|
+
const { inspect, isString } = require('@contrast/common');
|
|
20
|
+
|
|
21
|
+
module.exports = function(core) {
|
|
22
|
+
const {
|
|
23
|
+
scopes: { sources, instrumentation },
|
|
24
|
+
patcher,
|
|
25
|
+
depHooks,
|
|
26
|
+
assess: {
|
|
27
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
28
|
+
}
|
|
29
|
+
} = core;
|
|
30
|
+
|
|
31
|
+
function getPropagationEvent(params, paramInfo, data) {
|
|
32
|
+
return createPropagationEvent({
|
|
33
|
+
name: 'url.URLSearchParams',
|
|
34
|
+
moduleName: 'url',
|
|
35
|
+
methodName: 'URLSearchParams',
|
|
36
|
+
context: `url.URLSearchParams('${inspect(params)}')`,
|
|
37
|
+
object: {
|
|
38
|
+
value: 'url',
|
|
39
|
+
tracked: false
|
|
40
|
+
},
|
|
41
|
+
result: {
|
|
42
|
+
value: inspect(data.result),
|
|
43
|
+
tracked: true
|
|
44
|
+
},
|
|
45
|
+
args: [{ value: inspect(params), tracked: false }],
|
|
46
|
+
tags: paramInfo.tags,
|
|
47
|
+
history: [paramInfo],
|
|
48
|
+
source: 'P',
|
|
49
|
+
target: 'R',
|
|
50
|
+
stacktraceOpts: {
|
|
51
|
+
constructorOpt: data.hooked,
|
|
52
|
+
prependFrames: [data.orig]
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return core.assess.dataflow.propagation.urlInstrumentation.searchParams = {
|
|
58
|
+
install() {
|
|
59
|
+
depHooks.resolve({ name: 'url' }, (url) => {
|
|
60
|
+
|
|
61
|
+
const name = 'url.URLSearchParams';
|
|
62
|
+
|
|
63
|
+
patcher.patch(url, 'URLSearchParams', {
|
|
64
|
+
name,
|
|
65
|
+
patchType,
|
|
66
|
+
post(data) {
|
|
67
|
+
const { args, obj, result } = data;
|
|
68
|
+
if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
69
|
+
|
|
70
|
+
const [params] = args;
|
|
71
|
+
|
|
72
|
+
if (isString(params)) {
|
|
73
|
+
params.split('&').forEach((query) => {
|
|
74
|
+
const startIdx = query.indexOf('?') + 1;
|
|
75
|
+
const endIdx = query.indexOf('=');
|
|
76
|
+
const key = query.substring(startIdx, endIdx);
|
|
77
|
+
const param = query.substring(endIdx + 1, query.length);
|
|
78
|
+
const paramInfo = tracker.getData(param);
|
|
79
|
+
if (!paramInfo) return;
|
|
80
|
+
|
|
81
|
+
const event = getPropagationEvent(params, paramInfo, data);
|
|
82
|
+
if (!event);
|
|
83
|
+
|
|
84
|
+
Object.assign(paramInfo, event);
|
|
85
|
+
const { extern } = paramInfo || tracker.track(param, event);
|
|
86
|
+
|
|
87
|
+
if (extern) {
|
|
88
|
+
result.set(key, extern);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (typeof params === 'object') {
|
|
94
|
+
Object.keys(params).forEach((key) => {
|
|
95
|
+
const paramInfo = tracker.getData(params[key]);
|
|
96
|
+
if (!paramInfo) return;
|
|
97
|
+
|
|
98
|
+
const event = getPropagationEvent(params, paramInfo, data);
|
|
99
|
+
if (!event) return;
|
|
100
|
+
|
|
101
|
+
Object.assign(paramInfo, event);
|
|
102
|
+
const { extern } = paramInfo || tracker.track(params[key], event);
|
|
103
|
+
|
|
104
|
+
if (extern) {
|
|
105
|
+
result.set(key, extern);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
patcher.patch(obj.prototype, 'toString', {
|
|
111
|
+
name: 'url.URLSearchParams.toString',
|
|
112
|
+
patchType,
|
|
113
|
+
post(data) {
|
|
114
|
+
const { obj: params } = data;
|
|
115
|
+
let i = 0;
|
|
116
|
+
let str = '';
|
|
117
|
+
params.forEach((val, key) => {
|
|
118
|
+
if (i === 0) {
|
|
119
|
+
str = key.concat('=', val);
|
|
120
|
+
} else {
|
|
121
|
+
str = str.concat('&', key, '=', val);
|
|
122
|
+
}
|
|
123
|
+
i++;
|
|
124
|
+
});
|
|
125
|
+
data.result = str;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 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
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { inspect } = require('@contrast/common');
|
|
19
|
+
const { patchType } = require('../../common');
|
|
20
|
+
|
|
21
|
+
module.exports = function(core) {
|
|
22
|
+
const {
|
|
23
|
+
scopes: { sources, instrumentation },
|
|
24
|
+
patcher,
|
|
25
|
+
depHooks,
|
|
26
|
+
assess: {
|
|
27
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
28
|
+
}
|
|
29
|
+
} = core;
|
|
30
|
+
|
|
31
|
+
const keys = [
|
|
32
|
+
'href',
|
|
33
|
+
[
|
|
34
|
+
'origin',
|
|
35
|
+
'protocol',
|
|
36
|
+
'username',
|
|
37
|
+
'password',
|
|
38
|
+
'host',
|
|
39
|
+
[
|
|
40
|
+
'hostname',
|
|
41
|
+
'port'
|
|
42
|
+
],
|
|
43
|
+
'pathname',
|
|
44
|
+
'search',
|
|
45
|
+
'hash'
|
|
46
|
+
]
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
function getPropagationEvent(strInfo, partInfo, data) {
|
|
50
|
+
const args = data.args.map((v) => {
|
|
51
|
+
const strInfo = tracker.getData(v);
|
|
52
|
+
return {
|
|
53
|
+
value: strInfo ? strInfo.value : v,
|
|
54
|
+
tracked: !!strInfo
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return createPropagationEvent({
|
|
59
|
+
name: 'url.URL',
|
|
60
|
+
moduleName: 'url',
|
|
61
|
+
methodName: 'URL',
|
|
62
|
+
context: `url.URL('${strInfo.value}')`,
|
|
63
|
+
object: {
|
|
64
|
+
value: 'url',
|
|
65
|
+
tracked: false
|
|
66
|
+
},
|
|
67
|
+
result: {
|
|
68
|
+
value: inspect(data.result),
|
|
69
|
+
tracked: true
|
|
70
|
+
},
|
|
71
|
+
args,
|
|
72
|
+
tags: partInfo.tags,
|
|
73
|
+
history: [partInfo],
|
|
74
|
+
source: 'P',
|
|
75
|
+
target: 'R',
|
|
76
|
+
stacktraceOpts: {
|
|
77
|
+
constructorOpt: data.hooked,
|
|
78
|
+
prependFrames: [data.orig]
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return core.assess.dataflow.propagation.urlInstrumentation.url = {
|
|
84
|
+
install() {
|
|
85
|
+
depHooks.resolve({ name: 'url' }, (url) => {
|
|
86
|
+
const { URLSearchParams } = url;
|
|
87
|
+
const name = 'url.URL';
|
|
88
|
+
patcher.patch(url, 'URL', {
|
|
89
|
+
name,
|
|
90
|
+
patchType,
|
|
91
|
+
post(data) {
|
|
92
|
+
const { args, result } = data;
|
|
93
|
+
if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
94
|
+
|
|
95
|
+
const [input, basename] = args;
|
|
96
|
+
let url = input;
|
|
97
|
+
if (basename && url !== result.toString()) {
|
|
98
|
+
const isAbsoluteURL = url.indexOf('://') > 0 || url.indexOf('//') === 0;
|
|
99
|
+
if (isAbsoluteURL) {
|
|
100
|
+
const splitUrl = url.split(new RegExp('(?=//)', 'g'));
|
|
101
|
+
let endOfSlashes = splitUrl.length === 1 ? true : false;
|
|
102
|
+
let newUrl = splitUrl[0] === result.protocol ? splitUrl[0] : basename.split(/(?<=:)/)[0];
|
|
103
|
+
for (let i = 0; i < splitUrl.length; i++) {
|
|
104
|
+
if (endOfSlashes) {
|
|
105
|
+
newUrl = newUrl.concat(splitUrl[i]);
|
|
106
|
+
}
|
|
107
|
+
if (splitUrl[i] === '/' && splitUrl[i + 1] !== '/') {
|
|
108
|
+
endOfSlashes = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
url = newUrl;
|
|
112
|
+
} else {
|
|
113
|
+
url = basename.concat(url);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const strInfo = tracker.getData(url);
|
|
117
|
+
if (!strInfo) return;
|
|
118
|
+
|
|
119
|
+
const proxy = new Proxy(data.result, {
|
|
120
|
+
set(obj, prop, value) {
|
|
121
|
+
return Reflect.set(obj, prop, value);
|
|
122
|
+
},
|
|
123
|
+
get(obj, prop) {
|
|
124
|
+
if (prop === 'toString' || prop === 'toJSON') {
|
|
125
|
+
return function() {
|
|
126
|
+
return Reflect.get(obj, '_contrast_href');
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (typeof prop === 'string') {
|
|
130
|
+
const trackedProp = Reflect.get(obj, `_contrast_${prop}`);
|
|
131
|
+
if (trackedProp) return trackedProp;
|
|
132
|
+
}
|
|
133
|
+
return Reflect.get(obj, prop);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const traverse = function(href, url, keys, idx = 0) {
|
|
138
|
+
let substr = href;
|
|
139
|
+
keys.forEach((key) => {
|
|
140
|
+
if (typeof key === 'string') {
|
|
141
|
+
const part = url[key];
|
|
142
|
+
if (part !== 'null') {
|
|
143
|
+
|
|
144
|
+
if (key === 'origin') {
|
|
145
|
+
const [protocol, originWithoutProtocol] = part.split(new RegExp('(?<=//)'));
|
|
146
|
+
const idx1 = href.indexOf(protocol);
|
|
147
|
+
const idx2 = href.indexOf(originWithoutProtocol, idx - 1);
|
|
148
|
+
substr = href.substring(idx1, idx1 + protocol.length).concat(href.substring(idx2, idx2 + originWithoutProtocol.length));
|
|
149
|
+
} else {
|
|
150
|
+
const index = href.indexOf(part, idx - 1);
|
|
151
|
+
substr = href.substring(index, index + part.length);
|
|
152
|
+
idx += part.length;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const partInfo = tracker.getData(substr);
|
|
156
|
+
if (!partInfo) return;
|
|
157
|
+
|
|
158
|
+
const event = getPropagationEvent(strInfo, partInfo, data);
|
|
159
|
+
if (!event) return;
|
|
160
|
+
|
|
161
|
+
Object.assign(partInfo, event);
|
|
162
|
+
const { extern } = tracker.track(part, event);
|
|
163
|
+
|
|
164
|
+
if (extern) {
|
|
165
|
+
proxy[`_contrast_${key}`] = extern;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
traverse(substr, url, key, 0);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
traverse(url, result, keys, 0);
|
|
175
|
+
|
|
176
|
+
if (proxy.search) {
|
|
177
|
+
proxy._contrast_searchParams = new URLSearchParams(proxy.search);
|
|
178
|
+
}
|
|
179
|
+
data.result = proxy;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -20,7 +20,7 @@ const { callChildComponentMethodsSync, Event, Rule } = require('@contrast/common
|
|
|
20
20
|
const { isVulnerable } = require('../utils/is-vulnerable');
|
|
21
21
|
const { isSafeContentType } = require('../utils/is-safe-content-type');
|
|
22
22
|
|
|
23
|
-
module.exports = function
|
|
23
|
+
module.exports = function(core) {
|
|
24
24
|
const {
|
|
25
25
|
logger,
|
|
26
26
|
messages,
|
|
@@ -29,7 +29,8 @@ module.exports = function (core) {
|
|
|
29
29
|
|
|
30
30
|
const sinkScopes = {
|
|
31
31
|
[Rule.SQL_INJECTION]: new AsyncLocalStorage(),
|
|
32
|
-
[Rule.NOSQL_INJECTION_MONGO]: new AsyncLocalStorage()
|
|
32
|
+
[Rule.NOSQL_INJECTION_MONGO]: new AsyncLocalStorage(),
|
|
33
|
+
['unsafe-code-execution']: new AsyncLocalStorage()
|
|
33
34
|
};
|
|
34
35
|
const sinks = core.assess.dataflow.sinks = {
|
|
35
36
|
isVulnerable,
|
|
@@ -65,19 +66,22 @@ module.exports = function (core) {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
|
|
69
|
+
require('./install/express')(core);
|
|
68
70
|
require('./install/fastify')(core);
|
|
69
71
|
require('./install/koa')(core);
|
|
70
72
|
require('./install/child-process')(core);
|
|
73
|
+
require('./install/eval')(core);
|
|
71
74
|
require('./install/fs')(core);
|
|
75
|
+
require('./install/function')(core);
|
|
72
76
|
require('./install/http')(core);
|
|
77
|
+
require('./install/marsdb')(core);
|
|
73
78
|
require('./install/mongodb')(core);
|
|
74
79
|
require('./install/mssql')(core);
|
|
75
80
|
require('./install/mysql')(core);
|
|
76
81
|
require('./install/postgres')(core);
|
|
77
82
|
require('./install/sequelize')(core);
|
|
78
83
|
require('./install/sqlite3')(core);
|
|
79
|
-
require('./install/
|
|
80
|
-
require('./install/express')(core);
|
|
84
|
+
require('./install/vm')(core);
|
|
81
85
|
|
|
82
86
|
sinks.install = function() {
|
|
83
87
|
callChildComponentMethodsSync(core.assess.dataflow.sinks, 'install');
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 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
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
isString,
|
|
20
|
+
DataflowTag: {
|
|
21
|
+
UNTRUSTED,
|
|
22
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION,
|
|
23
|
+
CUSTOM_ENCODED,
|
|
24
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION,
|
|
25
|
+
CUSTOM_VALIDATED,
|
|
26
|
+
LIMITED_CHARS,
|
|
27
|
+
},
|
|
28
|
+
} = require('@contrast/common');
|
|
29
|
+
const { patchType, filterSafeTags } = require('../common');
|
|
30
|
+
|
|
31
|
+
const ruleId = 'unsafe-code-execution';
|
|
32
|
+
const safeTags = [
|
|
33
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION,
|
|
34
|
+
CUSTOM_ENCODED,
|
|
35
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION,
|
|
36
|
+
CUSTOM_VALIDATED,
|
|
37
|
+
LIMITED_CHARS,
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
module.exports = function(core) {
|
|
41
|
+
const {
|
|
42
|
+
config,
|
|
43
|
+
logger,
|
|
44
|
+
patcher,
|
|
45
|
+
scopes: { sources, instrumentation },
|
|
46
|
+
assess: {
|
|
47
|
+
dataflow: {
|
|
48
|
+
tracker,
|
|
49
|
+
sinks: { isVulnerable, reportFindings, reportSafePositive },
|
|
50
|
+
eventFactory: { createSinkEvent },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
} = core;
|
|
54
|
+
|
|
55
|
+
core.assess.dataflow.sinks.contrastEval = {
|
|
56
|
+
install() {
|
|
57
|
+
if (!global.ContrastMethods?.eval) {
|
|
58
|
+
logger.error(
|
|
59
|
+
'Cannot install `eval` instrumentation - Contrast method DNE'
|
|
60
|
+
);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Object.assign(global.ContrastMethods, {
|
|
65
|
+
eval: patcher.patch(global.ContrastMethods.eval, {
|
|
66
|
+
name: 'global.ContrastMethods.eval',
|
|
67
|
+
patchType,
|
|
68
|
+
pre({ args: origArgs, hooked, orig, name }) {
|
|
69
|
+
const store = sources.getStore()?.assess;
|
|
70
|
+
const script = origArgs[0];
|
|
71
|
+
if (
|
|
72
|
+
!store ||
|
|
73
|
+
instrumentation.isLocked() ||
|
|
74
|
+
!script ||
|
|
75
|
+
!isString(script)
|
|
76
|
+
)
|
|
77
|
+
return;
|
|
78
|
+
|
|
79
|
+
const strInfo = tracker.getData(script);
|
|
80
|
+
|
|
81
|
+
if (!strInfo) return;
|
|
82
|
+
|
|
83
|
+
const isArgVulnerable = isVulnerable(
|
|
84
|
+
UNTRUSTED,
|
|
85
|
+
safeTags,
|
|
86
|
+
strInfo.tags
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (!isArgVulnerable && config.assess.safe_positives.enable) {
|
|
90
|
+
const foundSafeTags = filterSafeTags(safeTags, strInfo);
|
|
91
|
+
const safeStrInfo = {
|
|
92
|
+
value: strInfo.value,
|
|
93
|
+
tags: strInfo.tags,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
reportSafePositive({
|
|
97
|
+
name,
|
|
98
|
+
ruleId,
|
|
99
|
+
safeTags: foundSafeTags,
|
|
100
|
+
strInfo: safeStrInfo,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (isArgVulnerable) {
|
|
105
|
+
const event = createSinkEvent({
|
|
106
|
+
name,
|
|
107
|
+
context: `${name}('${strInfo.value}')`,
|
|
108
|
+
history: [strInfo],
|
|
109
|
+
object: {
|
|
110
|
+
value: 'global.ContrastMethods',
|
|
111
|
+
tracked: false,
|
|
112
|
+
},
|
|
113
|
+
moduleName: 'global.ContrastMethods',
|
|
114
|
+
methodName: 'eval',
|
|
115
|
+
args: [{ value: strInfo.value, tracked: true }],
|
|
116
|
+
tags: strInfo.tags,
|
|
117
|
+
source: 'P0',
|
|
118
|
+
stacktraceOpts: {
|
|
119
|
+
contructorOpt: hooked,
|
|
120
|
+
prependFrames: [orig],
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (event) {
|
|
125
|
+
reportFindings({
|
|
126
|
+
ruleId,
|
|
127
|
+
sinkEvent: event,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return core.assess.dataflow.sinks.contrastEval;
|
|
138
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -81,7 +81,7 @@ module.exports = function(core) {
|
|
|
81
81
|
|
|
82
82
|
let urlPathTags = strInfo.tags;
|
|
83
83
|
if (url.indexOf('?') > -1) {
|
|
84
|
-
urlPathTags = createSubsetTags(strInfo.tags, 0, url.indexOf('?'));
|
|
84
|
+
urlPathTags = createSubsetTags(strInfo.tags, 0, url.indexOf('?') + 1);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (urlPathTags && isVulnerable(UNTRUSTED, safeTags, urlPathTags)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -31,6 +31,7 @@ const { createSubsetTags } = require('../../../tag-utils');
|
|
|
31
31
|
const { filterSafeTags, patchType } = require('../../common');
|
|
32
32
|
|
|
33
33
|
const ruleId = 'unvalidated-redirect';
|
|
34
|
+
|
|
34
35
|
const getURLArgument = (args) => {
|
|
35
36
|
if (!Array.isArray(args)) {
|
|
36
37
|
return { index: null, url: undefined };
|
|
@@ -98,7 +99,7 @@ module.exports = function(core) {
|
|
|
98
99
|
let urlPathTags = strInfo.tags;
|
|
99
100
|
const urlPathEndIdx = url.indexOf('?');
|
|
100
101
|
if (urlPathEndIdx > -1) {
|
|
101
|
-
urlPathTags = createSubsetTags(strInfo.tags, 0, urlPathEndIdx);
|
|
102
|
+
urlPathTags = createSubsetTags(strInfo.tags, 0, urlPathEndIdx + 1);
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
if (isVulnerable(UNTRUSTED, safeTags, urlPathTags)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -71,7 +71,7 @@ module.exports = function(core) {
|
|
|
71
71
|
const strInfo = tracker.getData(v);
|
|
72
72
|
return {
|
|
73
73
|
value: strInfo ? strInfo.value : v,
|
|
74
|
-
|
|
74
|
+
tracked: !!strInfo,
|
|
75
75
|
strInfo
|
|
76
76
|
};
|
|
77
77
|
});
|
|
@@ -92,9 +92,9 @@ module.exports = function(core) {
|
|
|
92
92
|
history: [strInfo],
|
|
93
93
|
object: {
|
|
94
94
|
value: 'fs',
|
|
95
|
-
|
|
95
|
+
tracked: false,
|
|
96
96
|
},
|
|
97
|
-
args: args.map(({ value,
|
|
97
|
+
args: args.map(({ value, tracked }) => ({ value, tracked })),
|
|
98
98
|
tags: strInfo.tags,
|
|
99
99
|
source: `P${i}`,
|
|
100
100
|
stacktraceOpts: {
|