@contrast/assess 1.9.0 → 1.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/dataflow/propagation/index.js +1 -0
- 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/querystring/parse.js +1 -1
- package/lib/dataflow/propagation/install/string/match.js +2 -2
- package/lib/dataflow/propagation/install/string/replace.js +1 -1
- package/lib/dataflow/propagation/install/string/slice.js +1 -1
- package/lib/dataflow/propagation/install/string/split.js +1 -1
- package/lib/dataflow/propagation/install/string/substring.js +2 -2
- package/lib/dataflow/propagation/install/string/trim.js +1 -1
- package/lib/dataflow/propagation/install/url/index.js +1 -0
- package/lib/dataflow/propagation/install/url/url.js +228 -0
- package/lib/dataflow/sinks/index.js +8 -4
- package/lib/dataflow/sinks/install/eval.js +138 -0
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +2 -1
- package/lib/dataflow/sinks/install/fs.js +3 -3
- 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} +2 -2
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/mongodb.js +4 -23
- package/lib/dataflow/sinks/install/mssql.js +44 -31
- package/lib/dataflow/sinks/install/vm.js +276 -0
- package/lib/dataflow/tag-utils.js +70 -1
- package/package.json +2 -2
|
@@ -0,0 +1,228 @@
|
|
|
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 { 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
|
+
'searchParams',
|
|
46
|
+
'hash'
|
|
47
|
+
]
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
function getPropagationEvent(strInfo, partInfo, data) {
|
|
51
|
+
const args = data.args.map((v) => {
|
|
52
|
+
const strInfo = tracker.getData(v);
|
|
53
|
+
return {
|
|
54
|
+
value: strInfo ? strInfo.value : v,
|
|
55
|
+
tracked: !!strInfo
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return createPropagationEvent({
|
|
60
|
+
name: 'url.URL',
|
|
61
|
+
moduleName: 'url',
|
|
62
|
+
methodName: 'URL',
|
|
63
|
+
context: `url.URL('${strInfo.value}')`,
|
|
64
|
+
object: {
|
|
65
|
+
value: 'url',
|
|
66
|
+
tracked: false
|
|
67
|
+
},
|
|
68
|
+
result: {
|
|
69
|
+
value: inspect(data.result),
|
|
70
|
+
tracked: true
|
|
71
|
+
},
|
|
72
|
+
args,
|
|
73
|
+
tags: partInfo.tags,
|
|
74
|
+
history: [partInfo],
|
|
75
|
+
source: 'P',
|
|
76
|
+
target: 'R',
|
|
77
|
+
stacktraceOpts: {
|
|
78
|
+
constructorOpt: data.hooked,
|
|
79
|
+
prependFrames: [data.orig]
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return core.assess.dataflow.propagation.urlInstrumentation.url = {
|
|
85
|
+
install() {
|
|
86
|
+
depHooks.resolve({ name: 'url' }, (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 searchParamsProxy = new Proxy(data.result.searchParams, {
|
|
120
|
+
set(obj, prop, value) {
|
|
121
|
+
return Reflect.set(obj, prop, value);
|
|
122
|
+
},
|
|
123
|
+
get(obj, prop, receiver) {
|
|
124
|
+
const val = obj[prop];
|
|
125
|
+
if (val instanceof Function) {
|
|
126
|
+
return function (query) {
|
|
127
|
+
if (typeof query === 'string') {
|
|
128
|
+
const trackedProp = Reflect.get(obj, `_contrast_${query}`);
|
|
129
|
+
if (trackedProp) return trackedProp;
|
|
130
|
+
}
|
|
131
|
+
return val.apply(this === receiver ? obj : this, query);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return Reflect.get(obj, prop, receiver);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const proxy = new Proxy(data.result, {
|
|
139
|
+
set(obj, prop, value) {
|
|
140
|
+
return Reflect.set(obj, prop, value);
|
|
141
|
+
},
|
|
142
|
+
get(obj, prop) {
|
|
143
|
+
if (prop === 'searchParams') {
|
|
144
|
+
return searchParamsProxy;
|
|
145
|
+
}
|
|
146
|
+
if (prop === 'toString' || prop === 'toJSON') {
|
|
147
|
+
return function() {
|
|
148
|
+
return Reflect.get(obj, '_contrast_href');
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (typeof prop === 'string') {
|
|
152
|
+
const trackedProp = Reflect.get(obj, `_contrast_${prop}`);
|
|
153
|
+
if (trackedProp) return trackedProp;
|
|
154
|
+
}
|
|
155
|
+
return Reflect.get(obj, prop);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const traverse = function(href, url, keys, idx = 0) {
|
|
160
|
+
let substr = href;
|
|
161
|
+
keys.forEach((key) => {
|
|
162
|
+
if (typeof key === 'string' && key !== 'searchParams') {
|
|
163
|
+
const part = url[key];
|
|
164
|
+
if (part !== 'null') {
|
|
165
|
+
|
|
166
|
+
if (key === 'origin') {
|
|
167
|
+
const [protocol, originWithoutProtocol] = part.split(new RegExp('(?<=//)'));
|
|
168
|
+
const idx1 = href.indexOf(protocol);
|
|
169
|
+
const idx2 = href.indexOf(originWithoutProtocol, idx - 1);
|
|
170
|
+
substr = href.substring(idx1, idx1 + protocol.length).concat(href.substring(idx2, idx2 + originWithoutProtocol.length));
|
|
171
|
+
} else {
|
|
172
|
+
const index = href.indexOf(part, idx - 1);
|
|
173
|
+
substr = href.substring(index, index + part.length);
|
|
174
|
+
idx += part.length;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const partInfo = tracker.getData(substr);
|
|
178
|
+
if (!partInfo) return;
|
|
179
|
+
|
|
180
|
+
const event = getPropagationEvent(strInfo, partInfo, data);
|
|
181
|
+
if (!event) return;
|
|
182
|
+
|
|
183
|
+
if (partInfo) {
|
|
184
|
+
Object.assign(partInfo, event);
|
|
185
|
+
}
|
|
186
|
+
const { extern } = partInfo || tracker.track(part, event);
|
|
187
|
+
|
|
188
|
+
if (extern) {
|
|
189
|
+
proxy[`_contrast_${key}`] = extern;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else if (key === 'searchParams') {
|
|
193
|
+
const queries = proxy.search.split('&');
|
|
194
|
+
queries.forEach((query) => {
|
|
195
|
+
const startIdx = query.indexOf('?') + 1;
|
|
196
|
+
const endIdx = query.indexOf('=');
|
|
197
|
+
const queryName = query.substring(startIdx, endIdx);
|
|
198
|
+
const queryString = query.substring(endIdx + 1, query.length);
|
|
199
|
+
const queryStringInfo = tracker.getData(queryString);
|
|
200
|
+
if (!queryStringInfo) return;
|
|
201
|
+
|
|
202
|
+
const event = getPropagationEvent(strInfo, queryStringInfo, data);
|
|
203
|
+
|
|
204
|
+
if (!event) return;
|
|
205
|
+
|
|
206
|
+
if (queryStringInfo) {
|
|
207
|
+
Object.assign(queryStringInfo, event);
|
|
208
|
+
}
|
|
209
|
+
const { extern } = queryStringInfo || tracker.track(queryString, event);
|
|
210
|
+
|
|
211
|
+
if (extern) {
|
|
212
|
+
searchParamsProxy[`_contrast_${queryName}`] = extern;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
traverse(substr, url, key, 0);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
traverse(url, result, keys, 0);
|
|
222
|
+
data.result = proxy;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
};
|
|
@@ -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: 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 {
|
|
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
|
+
};
|
|
@@ -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)) {
|
|
@@ -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)) {
|
|
@@ -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: {
|
|
@@ -0,0 +1,160 @@
|
|
|
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 {
|
|
19
|
+
isString,
|
|
20
|
+
inspect,
|
|
21
|
+
join,
|
|
22
|
+
DataflowTag: {
|
|
23
|
+
UNTRUSTED,
|
|
24
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION,
|
|
25
|
+
CUSTOM_ENCODED,
|
|
26
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION,
|
|
27
|
+
CUSTOM_VALIDATED,
|
|
28
|
+
LIMITED_CHARS,
|
|
29
|
+
},
|
|
30
|
+
} = require('@contrast/common');
|
|
31
|
+
const { patchType, filterSafeTags } = require('../common');
|
|
32
|
+
|
|
33
|
+
const ruleId = 'unsafe-code-execution';
|
|
34
|
+
const safeTags = [
|
|
35
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION,
|
|
36
|
+
CUSTOM_ENCODED,
|
|
37
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION,
|
|
38
|
+
CUSTOM_VALIDATED,
|
|
39
|
+
LIMITED_CHARS,
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
module.exports = function(core) {
|
|
43
|
+
const {
|
|
44
|
+
config,
|
|
45
|
+
logger,
|
|
46
|
+
patcher,
|
|
47
|
+
scopes: { sources, instrumentation },
|
|
48
|
+
assess: {
|
|
49
|
+
dataflow: {
|
|
50
|
+
tracker,
|
|
51
|
+
sinks: { isVulnerable, reportFindings, reportSafePositive },
|
|
52
|
+
eventFactory: { createSinkEvent },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
} = core;
|
|
56
|
+
|
|
57
|
+
core.assess.dataflow.sinks.contrastFunction = {
|
|
58
|
+
install() {
|
|
59
|
+
if (!global.ContrastMethods?.Function) {
|
|
60
|
+
logger.error(
|
|
61
|
+
'Cannot install `Function` instrumentation - Contrast method DNE'
|
|
62
|
+
);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Object.assign(global.ContrastMethods, {
|
|
67
|
+
Function: patcher.patch(global.ContrastMethods.Function, {
|
|
68
|
+
name: 'global.ContrastMethods.Function',
|
|
69
|
+
patchType,
|
|
70
|
+
pre({ args: origArgs, hooked, orig, name }) {
|
|
71
|
+
const store = sources.getStore()?.assess;
|
|
72
|
+
const fnBody = origArgs[origArgs.length - 1];
|
|
73
|
+
if (
|
|
74
|
+
!store ||
|
|
75
|
+
instrumentation.isLocked() ||
|
|
76
|
+
!fnBody ||
|
|
77
|
+
!isString(fnBody)
|
|
78
|
+
)
|
|
79
|
+
return;
|
|
80
|
+
|
|
81
|
+
const strInfo = tracker.getData(fnBody);
|
|
82
|
+
|
|
83
|
+
if (!strInfo) return;
|
|
84
|
+
|
|
85
|
+
const isArgVulnerable = isVulnerable(UNTRUSTED, safeTags, strInfo.tags);
|
|
86
|
+
|
|
87
|
+
if (!isArgVulnerable && config.assess.safe_positives.enable) {
|
|
88
|
+
const foundSafeTags = filterSafeTags(safeTags, strInfo);
|
|
89
|
+
const safeStrInfo = {
|
|
90
|
+
value: strInfo.value,
|
|
91
|
+
tags: strInfo.tags,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
reportSafePositive({
|
|
95
|
+
name,
|
|
96
|
+
ruleId,
|
|
97
|
+
safeTags: foundSafeTags,
|
|
98
|
+
strInfo: safeStrInfo,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isArgVulnerable) {
|
|
103
|
+
const args = origArgs.map((arg, idx) => {
|
|
104
|
+
if (idx === origArgs.length - 1) {
|
|
105
|
+
return {
|
|
106
|
+
value: strInfo.value,
|
|
107
|
+
tracked: true,
|
|
108
|
+
inspectedValue: `'${strInfo.value}'`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const inspectedValue = inspect(arg);
|
|
113
|
+
const argInfo = arg && isString(arg) ? tracker.getData(arg) : null;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
value: argInfo ? argInfo.value : inspectedValue,
|
|
117
|
+
tracked: !!argInfo,
|
|
118
|
+
inspectedValue
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
const event = createSinkEvent({
|
|
122
|
+
name,
|
|
123
|
+
context: `${name}(${join(
|
|
124
|
+
args.map((a) => a.inspectedValue),
|
|
125
|
+
', '
|
|
126
|
+
)})`,
|
|
127
|
+
history: [strInfo],
|
|
128
|
+
object: {
|
|
129
|
+
value: 'global.ContrastMethods',
|
|
130
|
+
tracked: false,
|
|
131
|
+
},
|
|
132
|
+
moduleName: 'global.ContrastMethods',
|
|
133
|
+
methodName: 'Function',
|
|
134
|
+
args: args.map((a) => ({
|
|
135
|
+
value: a.value,
|
|
136
|
+
tracked: a.tracked,
|
|
137
|
+
})),
|
|
138
|
+
tags: strInfo.tags,
|
|
139
|
+
source: `P${origArgs.length - 1}`,
|
|
140
|
+
stacktraceOpts: {
|
|
141
|
+
contructorOpt: hooked,
|
|
142
|
+
prependFrames: [orig],
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (event) {
|
|
147
|
+
reportFindings({
|
|
148
|
+
ruleId,
|
|
149
|
+
sinkEvent: event,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return core.assess.dataflow.sinks.contrastFunction;
|
|
160
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { callChildComponentMethodsSync } = require('@contrast/common');
|
|
19
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const http = core.assess.dataflow.sinks.http = {};
|
|
22
|
+
|
|
23
|
+
require('./request')(core);
|
|
24
|
+
require('./server-response')(core);
|
|
25
|
+
|
|
26
|
+
http.install = function() {
|
|
27
|
+
callChildComponentMethodsSync(http, 'install');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return http;
|
|
31
|
+
};
|