@contrast/assess 1.1.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/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +266 -0
- package/coverage/lcov-report/lib/dataflow/common.js.html +154 -0
- package/coverage/lcov-report/lib/dataflow/event-factory.js.html +598 -0
- package/coverage/lcov-report/lib/dataflow/index.html +191 -0
- package/coverage/lcov-report/lib/dataflow/index.js.html +190 -0
- package/coverage/lcov-report/lib/dataflow/propagation/common.js.html +145 -0
- package/coverage/lcov-report/lib/dataflow/propagation/index.html +131 -0
- package/coverage/lcov-report/lib/dataflow/propagation/index.js.html +190 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.html +131 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.js.html +184 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/plus.js.html +397 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/concat.js.html +478 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.html +176 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.js.html +202 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/replace.js.html +496 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/substring.js.html +415 -0
- package/coverage/lcov-report/lib/dataflow/propagation/install/string/trim.js.html +403 -0
- package/coverage/lcov-report/lib/dataflow/signatures.js.html +5923 -0
- package/coverage/lcov-report/lib/dataflow/sinks/common.js.html +145 -0
- package/coverage/lcov-report/lib/dataflow/sinks/index.html +131 -0
- package/coverage/lcov-report/lib/dataflow/sinks/index.js.html +211 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.html +146 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.js.html +172 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js.html +319 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/xss.js.html +721 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/http.js.html +340 -0
- package/coverage/lcov-report/lib/dataflow/sinks/install/index.html +116 -0
- package/coverage/lcov-report/lib/dataflow/sources/common.js.html +145 -0
- package/coverage/lcov-report/lib/dataflow/sources/index.html +131 -0
- package/coverage/lcov-report/lib/dataflow/sources/index.js.html +226 -0
- package/coverage/lcov-report/lib/dataflow/sources/install/fastify.js.html +379 -0
- package/coverage/lcov-report/lib/dataflow/sources/install/http.js.html +502 -0
- package/coverage/lcov-report/lib/dataflow/sources/install/index.html +146 -0
- package/coverage/lcov-report/lib/dataflow/sources/install/qs.js.html +322 -0
- package/coverage/lcov-report/lib/dataflow/tag-utils.js.html +418 -0
- package/coverage/lcov-report/lib/dataflow/tracker.js.html +466 -0
- package/coverage/lcov-report/lib/dataflow/utils/index.html +116 -0
- package/coverage/lcov-report/lib/dataflow/utils/is-vulnerable.js.html +424 -0
- package/coverage/lcov-report/lib/index.html +116 -0
- package/coverage/lcov-report/lib/index.js.html +193 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +4856 -0
- package/coverage/tmp/coverage-9548-1675168551025-0.json +1 -0
- package/coverage/tmp/coverage-9551-1675168550963-0.json +1 -0
- package/coverage/tmp/coverage-9552-1675168550969-0.json +1 -0
- package/coverage/tmp/coverage-9553-1675168550970-0.json +1 -0
- package/coverage/tmp/coverage-9554-1675168550962-0.json +1 -0
- package/coverage/tmp/coverage-9555-1675168550965-0.json +1 -0
- package/coverage/tmp/coverage-9556-1675168550964-0.json +1 -0
- package/coverage/tmp/coverage-9557-1675168550969-0.json +1 -0
- package/coverage/tmp/coverage-9558-1675168550964-0.json +1 -0
- package/coverage/tmp/coverage-9559-1675168550971-0.json +1 -0
- package/lib/dataflow/event-factory.js +256 -0
- package/lib/dataflow/index.js +35 -0
- package/lib/dataflow/propagation/common.js +26 -0
- package/lib/dataflow/propagation/index.js +50 -0
- package/lib/dataflow/propagation/install/array-prototype-join.js +125 -0
- package/lib/dataflow/propagation/install/contrast-methods/add.js +104 -0
- package/lib/dataflow/propagation/install/contrast-methods/index.js +34 -0
- package/lib/dataflow/propagation/install/contrast-methods/tag.js +102 -0
- package/lib/dataflow/propagation/install/decode-uri-component.js +88 -0
- package/lib/dataflow/propagation/install/ejs/escape-xml.js +89 -0
- package/lib/dataflow/propagation/install/ejs/index.js +30 -0
- package/lib/dataflow/propagation/install/encode-uri-component.js +87 -0
- package/lib/dataflow/propagation/install/escape-html.js +89 -0
- package/lib/dataflow/propagation/install/escape.js +89 -0
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +89 -0
- package/lib/dataflow/propagation/install/mysql-connection-escape.js +111 -0
- package/lib/dataflow/propagation/install/pug/index.js +64 -0
- package/lib/dataflow/propagation/install/pug-runtime-escape.js +89 -0
- package/lib/dataflow/propagation/install/sql-template-strings.js +103 -0
- package/lib/dataflow/propagation/install/string/concat.js +108 -0
- package/lib/dataflow/propagation/install/string/format-methods.js +83 -0
- package/lib/dataflow/propagation/install/string/html-methods.js +163 -0
- package/lib/dataflow/propagation/install/string/index.js +38 -0
- package/lib/dataflow/propagation/install/string/replace.js +197 -0
- package/lib/dataflow/propagation/install/string/substring.js +117 -0
- package/lib/dataflow/propagation/install/string/trim.js +115 -0
- package/lib/dataflow/propagation/install/unescape.js +90 -0
- package/lib/dataflow/propagation/install/url/domain-parsers.js +89 -0
- package/lib/dataflow/propagation/install/url/index.js +33 -0
- package/lib/dataflow/propagation/install/validator/hooks.js +172 -0
- package/lib/dataflow/propagation/install/validator/index.js +28 -0
- package/lib/dataflow/propagation/install/validator/methods.js +82 -0
- package/lib/dataflow/signatures.js +2022 -0
- package/lib/dataflow/sinks/common.js +20 -0
- package/lib/dataflow/sinks/index.js +44 -0
- package/lib/dataflow/sinks/install/fastify/index.js +30 -0
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +107 -0
- package/lib/dataflow/sinks/install/http.js +119 -0
- package/lib/dataflow/sinks/install/postgres/index.js +129 -0
- package/lib/dataflow/sources/common.js +20 -0
- package/lib/dataflow/sources/handler.js +114 -0
- package/lib/dataflow/sources/index.js +35 -0
- package/lib/dataflow/sources/install/fastify/cookie.js +61 -0
- package/lib/dataflow/sources/install/fastify/fastify.js +89 -0
- package/lib/dataflow/sources/install/fastify/index.js +31 -0
- package/lib/dataflow/sources/install/http.js +181 -0
- package/lib/dataflow/sources/install/qs.js +88 -0
- package/lib/dataflow/tag-utils.js +122 -0
- package/lib/dataflow/tracker.js +127 -0
- package/lib/dataflow/utils/is-safe-content-type.js +30 -0
- package/lib/dataflow/utils/is-vulnerable.js +113 -0
- package/lib/index.js +36 -0
- package/package.json +21 -0
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
createFullLengthCopyTags
|
|
20
|
+
} = require('../../tag-utils');
|
|
21
|
+
const { patchType, createModuleLabel } = require('../common');
|
|
22
|
+
|
|
23
|
+
module.exports = function(core) {
|
|
24
|
+
const {
|
|
25
|
+
scopes: { sources, instrumentation },
|
|
26
|
+
patcher,
|
|
27
|
+
depHooks,
|
|
28
|
+
assess: {
|
|
29
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
30
|
+
}
|
|
31
|
+
} = core;
|
|
32
|
+
|
|
33
|
+
function createPostHook(eventName, objectValue) {
|
|
34
|
+
return function(data) {
|
|
35
|
+
const { args, result, hooked, orig } = data;
|
|
36
|
+
if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
37
|
+
|
|
38
|
+
const argInfo = tracker.getData(args[0]);
|
|
39
|
+
|
|
40
|
+
if (!argInfo) return;
|
|
41
|
+
|
|
42
|
+
const resultInfo = tracker.getData(result);
|
|
43
|
+
const history = [argInfo];
|
|
44
|
+
const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
|
|
45
|
+
|
|
46
|
+
newTags['sql-encoded'] = [0, result.length - 1];
|
|
47
|
+
|
|
48
|
+
const event = createPropagationEvent({
|
|
49
|
+
name: eventName,
|
|
50
|
+
object: {
|
|
51
|
+
value: objectValue,
|
|
52
|
+
isTracked: false
|
|
53
|
+
},
|
|
54
|
+
result: {
|
|
55
|
+
value: resultInfo ? resultInfo.value : result,
|
|
56
|
+
isTracked: true
|
|
57
|
+
},
|
|
58
|
+
args: [{ value: argInfo.value, isTracked: true }],
|
|
59
|
+
tags: newTags,
|
|
60
|
+
addedTags: ['sql-encoded'],
|
|
61
|
+
history,
|
|
62
|
+
stacktraceOpts: {
|
|
63
|
+
constructorOpt: hooked,
|
|
64
|
+
prependFrames: [orig]
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (!event) return;
|
|
69
|
+
|
|
70
|
+
if (resultInfo) {
|
|
71
|
+
Object.assign(resultInfo, event);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { extern } = resultInfo || tracker.track(result, event);
|
|
75
|
+
|
|
76
|
+
if (extern) {
|
|
77
|
+
data.result = extern;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return core.assess.dataflow.propagation.mysqlEscape = {
|
|
83
|
+
install() {
|
|
84
|
+
['mysql', 'mysql2'].forEach((lib) => {
|
|
85
|
+
depHooks.resolve({ name: lib }, (mysql, version) => {
|
|
86
|
+
patcher.patch(mysql, 'escape', {
|
|
87
|
+
name: `${lib}.escape`,
|
|
88
|
+
patchType,
|
|
89
|
+
post: createPostHook(`${lib}.escape`, `${createModuleLabel(lib, version)}`)
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
depHooks.resolve({ name: 'mysql', file: 'lib/Connection.js' }, (mysqlConnection, version) => {
|
|
95
|
+
patcher.patch(mysqlConnection.prototype, 'escape', {
|
|
96
|
+
name: 'mysql.Connection.prototype.escape',
|
|
97
|
+
patchType,
|
|
98
|
+
post: createPostHook('mysql/lib/Connection.escape', `[${createModuleLabel('mysql', version)}].Connection`)
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
depHooks.resolve({ name: 'mysql2', file: 'lib/connection.js' }, (mysqlConnection, version) => {
|
|
103
|
+
patcher.patch(mysqlConnection.prototype, 'escape', {
|
|
104
|
+
name: 'mysql.Connection.prototype.escape',
|
|
105
|
+
patchType,
|
|
106
|
+
post: createPostHook('mysql2/lib/connection.Connection.escape', `[${createModuleLabel('mysql2', version)}].Connection`)
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { patchType } = require('../../common');
|
|
18
|
+
|
|
19
|
+
module.exports = function(core) {
|
|
20
|
+
const store = { lock: true, name: 'assess:propagators:pug-compile' };
|
|
21
|
+
const {
|
|
22
|
+
scopes: { sources, instrumentation },
|
|
23
|
+
patcher, logger, rewriter, depHooks,
|
|
24
|
+
} = core;
|
|
25
|
+
|
|
26
|
+
const rewriterOpts = { isModule: false, wrap: false };
|
|
27
|
+
|
|
28
|
+
const pugInstrumentation = {
|
|
29
|
+
install() {
|
|
30
|
+
depHooks.resolve(
|
|
31
|
+
{ name: 'pug', file: 'lib/index.js' },
|
|
32
|
+
(pug) => patcher.patch(pug, 'compile', {
|
|
33
|
+
name: 'pug.compile',
|
|
34
|
+
patchType,
|
|
35
|
+
pre(data) {
|
|
36
|
+
if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
37
|
+
|
|
38
|
+
const opts = data.args[1] || {};
|
|
39
|
+
const plugins = opts.plugins || [];
|
|
40
|
+
|
|
41
|
+
plugins.push({
|
|
42
|
+
postCodeGen: (value, options) => {
|
|
43
|
+
try {
|
|
44
|
+
return instrumentation.run(store,
|
|
45
|
+
() => rewriter.rewrite(value, rewriterOpts).code
|
|
46
|
+
);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
logger.warn(`Failed to rewrite pug code. ${e}`);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
opts.plugins = plugins;
|
|
55
|
+
data.args[1] = opts;
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
core.assess.dataflow.propagation.pugInstrumentation = pugInstrumentation;
|
|
63
|
+
return core.assess.dataflow.propagation.pugInstrumentation;
|
|
64
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
createFullLengthCopyTags
|
|
20
|
+
} = require('../../tag-utils');
|
|
21
|
+
const { patchType, createModuleLabel } = require('../common');
|
|
22
|
+
|
|
23
|
+
module.exports = function(core) {
|
|
24
|
+
const {
|
|
25
|
+
scopes: { sources, instrumentation },
|
|
26
|
+
patcher,
|
|
27
|
+
depHooks,
|
|
28
|
+
assess: {
|
|
29
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
30
|
+
}
|
|
31
|
+
} = core;
|
|
32
|
+
|
|
33
|
+
return core.assess.dataflow.propagation.pugRuntimeEscape = {
|
|
34
|
+
install() {
|
|
35
|
+
depHooks.resolve({ name: 'pug-runtime' }, (pugRuntime, version) => {
|
|
36
|
+
patcher.patch(pugRuntime, 'escape', {
|
|
37
|
+
name: 'pug-runtime.escape',
|
|
38
|
+
patchType,
|
|
39
|
+
post(data) {
|
|
40
|
+
const { args, result, hooked, orig } = data;
|
|
41
|
+
if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
42
|
+
|
|
43
|
+
const argInfo = tracker.getData(args[0]);
|
|
44
|
+
|
|
45
|
+
if (!argInfo) return;
|
|
46
|
+
|
|
47
|
+
const resultInfo = tracker.getData(result);
|
|
48
|
+
const history = [argInfo];
|
|
49
|
+
const newTags = createFullLengthCopyTags(argInfo.tags, result.length);
|
|
50
|
+
|
|
51
|
+
newTags['weak-url-encoded'] = [0, result.length - 1];
|
|
52
|
+
|
|
53
|
+
const event = createPropagationEvent({
|
|
54
|
+
name: 'pug-runtime.escape',
|
|
55
|
+
object: {
|
|
56
|
+
value: createModuleLabel('pug-runtime', version),
|
|
57
|
+
isTracked: false
|
|
58
|
+
},
|
|
59
|
+
result: {
|
|
60
|
+
value: resultInfo ? resultInfo.value : result,
|
|
61
|
+
isTracked: true
|
|
62
|
+
},
|
|
63
|
+
args: [{ value: argInfo.value, isTracked: true }],
|
|
64
|
+
tags: newTags,
|
|
65
|
+
addedTags: ['weak-url-encoded'],
|
|
66
|
+
history,
|
|
67
|
+
stacktraceOpts: {
|
|
68
|
+
constructorOpt: hooked,
|
|
69
|
+
prependFrames: [orig]
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!event) return;
|
|
74
|
+
|
|
75
|
+
if (resultInfo) {
|
|
76
|
+
Object.assign(resultInfo, event);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { extern } = resultInfo || tracker.track(result, event);
|
|
80
|
+
|
|
81
|
+
if (extern) {
|
|
82
|
+
data.result = extern;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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, createModuleLabel } = require('../common');
|
|
19
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const {
|
|
22
|
+
scopes: { sources, instrumentation },
|
|
23
|
+
patcher,
|
|
24
|
+
depHooks,
|
|
25
|
+
assess: {
|
|
26
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
27
|
+
}
|
|
28
|
+
} = core;
|
|
29
|
+
|
|
30
|
+
return core.assess.dataflow.propagation.sqlTemplateStrings = {
|
|
31
|
+
install() {
|
|
32
|
+
depHooks.resolve({ name: 'sql-template-strings' }, (sqlTemplateStrings, version) => {
|
|
33
|
+
patcher.patch(sqlTemplateStrings, 'SQL', {
|
|
34
|
+
name: 'sql-template-strings.SQL',
|
|
35
|
+
patchType,
|
|
36
|
+
post(data) {
|
|
37
|
+
const { args, result, hooked, orig } = data;
|
|
38
|
+
if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
39
|
+
|
|
40
|
+
const argInfo = tracker.getData(args[0]);
|
|
41
|
+
|
|
42
|
+
if (!argInfo) return;
|
|
43
|
+
|
|
44
|
+
const isResultStringsArray = Array.isArray(result.strings);
|
|
45
|
+
const resultStrings = isResultStringsArray ? result.strings : [result.strings];
|
|
46
|
+
|
|
47
|
+
[...resultStrings, ...result.values].forEach((resultValue, idx) => {
|
|
48
|
+
const resultInfo = tracker.getData(resultValue);
|
|
49
|
+
if (!resultInfo) return;
|
|
50
|
+
const history = [argInfo];
|
|
51
|
+
// const newTags = createFullLengthCopyTags(argInfo.tags, resultValue.length);
|
|
52
|
+
const newTags = { ...resultInfo.tags };
|
|
53
|
+
|
|
54
|
+
newTags['sql-encoded'] = [0, resultValue.length - 1];
|
|
55
|
+
|
|
56
|
+
const event = createPropagationEvent({
|
|
57
|
+
name: 'sql-template-strings.SQL',
|
|
58
|
+
object: {
|
|
59
|
+
value: createModuleLabel('sql-template-strings', version),
|
|
60
|
+
isTracked: false
|
|
61
|
+
},
|
|
62
|
+
result: {
|
|
63
|
+
value: resultInfo ? resultInfo.value : resultValue,
|
|
64
|
+
isTracked: true
|
|
65
|
+
},
|
|
66
|
+
args: [{ value: argInfo.value, isTracked: true }],
|
|
67
|
+
tags: newTags,
|
|
68
|
+
addedTags: ['sql-encoded'],
|
|
69
|
+
history,
|
|
70
|
+
stacktraceOpts: {
|
|
71
|
+
constructorOpt: hooked,
|
|
72
|
+
prependFrames: [orig]
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (!event) return;
|
|
77
|
+
|
|
78
|
+
if (resultInfo) {
|
|
79
|
+
Object.assign(resultInfo, event);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { extern } = resultInfo || tracker.track(resultValue, event);
|
|
83
|
+
|
|
84
|
+
if (extern) {
|
|
85
|
+
if (idx === 0 && !isResultStringsArray) {
|
|
86
|
+
data.result.strings = extern;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (idx < resultStrings.length && isResultStringsArray) {
|
|
90
|
+
data.result.strings[idx] = extern;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (idx >= resultStrings.length) {
|
|
94
|
+
data.result.values[idx - resultStrings.length] = extern;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
createAppendTags
|
|
20
|
+
} = require('../../../tag-utils');
|
|
21
|
+
const { patchType } = require('../../common');
|
|
22
|
+
|
|
23
|
+
module.exports = function(core) {
|
|
24
|
+
const {
|
|
25
|
+
scopes: { sources, instrumentation },
|
|
26
|
+
patcher,
|
|
27
|
+
assess: {
|
|
28
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
29
|
+
}
|
|
30
|
+
} = core;
|
|
31
|
+
|
|
32
|
+
return core.assess.dataflow.propagation.stringInstrumentation.concat = {
|
|
33
|
+
install() {
|
|
34
|
+
patcher.patch(String.prototype, 'concat', {
|
|
35
|
+
name: 'String.prototype.concat',
|
|
36
|
+
patchType,
|
|
37
|
+
post(data) {
|
|
38
|
+
const { args, obj, result, hooked, orig } = data;
|
|
39
|
+
if (!result || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
40
|
+
|
|
41
|
+
const rInfo = tracker.getData(result);
|
|
42
|
+
|
|
43
|
+
if (rInfo) {
|
|
44
|
+
// this may happen w/ trackedStr.concat('') => trackedStr
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const argsData = [];
|
|
49
|
+
const objInfo = tracker.getData(obj);
|
|
50
|
+
const history = objInfo ? new Set([objInfo]) : new Set();
|
|
51
|
+
const newTags = { ...objInfo?.tags };
|
|
52
|
+
let globalOffset = typeof obj !== 'function' ? obj.length : 0;
|
|
53
|
+
|
|
54
|
+
for (const str of args) {
|
|
55
|
+
const strInfo = tracker.getData(str);
|
|
56
|
+
|
|
57
|
+
if (strInfo) {
|
|
58
|
+
const strTags = strInfo?.tags || {};
|
|
59
|
+
history.add(strInfo);
|
|
60
|
+
Object.assign(newTags, createAppendTags(newTags, strTags, globalOffset));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
argsData.push({
|
|
64
|
+
value: strInfo?.value ?? str,
|
|
65
|
+
isTracked: !!strInfo
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
globalOffset += str.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (history.size) {
|
|
72
|
+
const event = createPropagationEvent({
|
|
73
|
+
name: 'String.prototype.concat',
|
|
74
|
+
object: {
|
|
75
|
+
value: objInfo?.value || String(obj),
|
|
76
|
+
isTracked: !!objInfo
|
|
77
|
+
},
|
|
78
|
+
result: {
|
|
79
|
+
value: result,
|
|
80
|
+
isTracked: true
|
|
81
|
+
},
|
|
82
|
+
args: argsData,
|
|
83
|
+
tags: newTags,
|
|
84
|
+
history: Array.from(history),
|
|
85
|
+
source: objInfo ? (history.size > 1 ? 'A' : 'O') : 'P',
|
|
86
|
+
target: 'R',
|
|
87
|
+
stacktraceOpts: {
|
|
88
|
+
constructorOpt: hooked,
|
|
89
|
+
prependFrames: [orig]
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!event) return;
|
|
94
|
+
|
|
95
|
+
const { extern } = tracker.track(result, event);
|
|
96
|
+
|
|
97
|
+
if (extern) {
|
|
98
|
+
data.result = extern;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
uninstall() {
|
|
105
|
+
String.prototype.concat = patcher.unwrap(String.prototype.concat);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const {
|
|
22
|
+
scopes: { sources, instrumentation },
|
|
23
|
+
patcher,
|
|
24
|
+
assess: {
|
|
25
|
+
dataflow: { tracker, eventFactory: { createPropagationEvent } }
|
|
26
|
+
}
|
|
27
|
+
} = core;
|
|
28
|
+
|
|
29
|
+
return core.assess.dataflow.propagation.stringInstrumentation.formatMethods = {
|
|
30
|
+
install() {
|
|
31
|
+
['toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].forEach((method) => {
|
|
32
|
+
patcher.patch(String.prototype, method, {
|
|
33
|
+
name: `String.prototype.${method}`,
|
|
34
|
+
patchType,
|
|
35
|
+
post(data) {
|
|
36
|
+
const { obj, result, hooked, orig } = data;
|
|
37
|
+
if (!result || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
38
|
+
|
|
39
|
+
const objInfo = tracker.getData(obj);
|
|
40
|
+
|
|
41
|
+
if (!objInfo) return;
|
|
42
|
+
|
|
43
|
+
const history = [objInfo];
|
|
44
|
+
|
|
45
|
+
const event = createPropagationEvent({
|
|
46
|
+
name: `String.prototype.${method}`,
|
|
47
|
+
object: {
|
|
48
|
+
value: objInfo.value,
|
|
49
|
+
isTracked: true
|
|
50
|
+
},
|
|
51
|
+
result: {
|
|
52
|
+
value: result,
|
|
53
|
+
isTracked: true
|
|
54
|
+
},
|
|
55
|
+
args: [],
|
|
56
|
+
tags: objInfo.tags,
|
|
57
|
+
history,
|
|
58
|
+
source: 'O',
|
|
59
|
+
target: 'R',
|
|
60
|
+
stacktraceOpts: {
|
|
61
|
+
constructorOpt: hooked,
|
|
62
|
+
prependFrames: [orig]
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!event) return;
|
|
67
|
+
|
|
68
|
+
const { extern } = tracker.track(result, event);
|
|
69
|
+
|
|
70
|
+
if (extern) {
|
|
71
|
+
data.result = extern;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
uninstall() {
|
|
78
|
+
['toLowerCase', 'toUpperCase', 'toLocaleLowerCase', 'toLocaleUpperCase'].forEach((method) => {
|
|
79
|
+
String.prototype[method] = patcher.unwrap(String.prototype[method]);
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
};
|