@contrast/assess 1.28.1 → 1.29.1
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/crypto-analysis/install/crypto.js +2 -2
- package/lib/dataflow/propagation/install/JSON/parse-fn.js +5 -5
- package/lib/dataflow/propagation/install/JSON/parse.js +1 -1
- package/lib/dataflow/propagation/install/JSON/stringify.js +17 -9
- package/lib/dataflow/propagation/install/array-prototype-join.js +7 -6
- package/lib/dataflow/propagation/install/buffer.js +60 -2
- package/lib/dataflow/propagation/install/ejs/template.js +4 -4
- package/lib/dataflow/propagation/install/joi/boolean.js +3 -1
- package/lib/dataflow/propagation/install/joi/expression.js +3 -1
- package/lib/dataflow/propagation/install/joi/keys.js +5 -4
- package/lib/dataflow/propagation/install/joi/number.js +3 -1
- package/lib/dataflow/propagation/install/joi/string-schema.js +1 -5
- package/lib/dataflow/propagation/install/joi/utils.js +9 -5
- package/lib/dataflow/propagation/install/joi/values.js +3 -6
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +2 -2
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +2 -2
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +2 -2
- package/lib/dataflow/propagation/install/path/basename.js +2 -2
- package/lib/dataflow/propagation/install/path/common.js +5 -5
- package/lib/dataflow/propagation/install/path/format.js +2 -2
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +2 -2
- package/lib/dataflow/propagation/install/pug/index.js +1 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +4 -3
- package/lib/dataflow/propagation/install/send.js +2 -2
- package/lib/dataflow/propagation/install/string/concat.js +3 -3
- package/lib/dataflow/propagation/install/string/index.js +3 -2
- package/lib/dataflow/propagation/install/string/match-all.js +0 -1
- package/lib/dataflow/propagation/install/string/match.js +2 -2
- package/lib/dataflow/propagation/install/string/replace.js +6 -6
- 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 +2 -2
- package/lib/dataflow/propagation/install/url/searchParams.js +74 -15
- package/lib/dataflow/sinks/index.js +1 -0
- package/lib/dataflow/sinks/install/child-process.js +3 -3
- package/lib/dataflow/sinks/install/fs.js +2 -2
- package/lib/dataflow/sinks/install/function.js +2 -2
- package/lib/dataflow/sinks/install/restify.js +208 -0
- package/lib/dataflow/sinks/install/vm.js +4 -4
- package/lib/dataflow/sources/handler.js +2 -2
- package/lib/dataflow/sources/index.js +1 -0
- package/lib/dataflow/sources/install/http.js +4 -4
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +85 -0
- package/lib/dataflow/sources/install/restify/index.js +32 -0
- package/lib/dataflow/sources/install/restify/jsonBodyParser.js +109 -0
- package/lib/dataflow/sources/install/restify/router.js +77 -0
- package/lib/dataflow/tag-utils.js +4 -4
- package/lib/dataflow/tracker.js +1 -0
- package/lib/event-factory.js +3 -3
- package/lib/get-policy.js +2 -2
- package/lib/index.d.ts +18 -0
- package/lib/make-source-context.js +2 -2
- package/lib/response-scanning/handlers/index.js +34 -34
- package/lib/response-scanning/handlers/utils.js +19 -12
- package/lib/response-scanning/install/http.js +34 -98
- package/lib/session-configuration/install/express-session.js +2 -2
- package/lib/session-configuration/install/fastify-cookie.js +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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 { InputType: { BODY } } = require('@contrast/common');
|
|
19
|
+
const { InstrumentationType: { SOURCE } } = require('../../../../constants');
|
|
20
|
+
const { patchType } = require('../../common');
|
|
21
|
+
|
|
22
|
+
module.exports = function init(core) {
|
|
23
|
+
const {
|
|
24
|
+
logger,
|
|
25
|
+
depHooks,
|
|
26
|
+
patcher,
|
|
27
|
+
assess: {
|
|
28
|
+
dataflow: { sources },
|
|
29
|
+
getSourceContext,
|
|
30
|
+
},
|
|
31
|
+
} = core;
|
|
32
|
+
|
|
33
|
+
return core.assess.dataflow.sources.restifyInstrumentation.fieldedTextBodyParser = {
|
|
34
|
+
install() {
|
|
35
|
+
depHooks.resolve(
|
|
36
|
+
{ name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8' },
|
|
37
|
+
(fieldedTextBodyParser) => patcher.patch(fieldedTextBodyParser, {
|
|
38
|
+
name: 'restify.plugins.fieldedTextBodyParser',
|
|
39
|
+
patchType,
|
|
40
|
+
post(data) {
|
|
41
|
+
data.result = patcher.patch(data.result, {
|
|
42
|
+
name: 'restify.plugins.fieldedTextBodyParser.parseFieldedText',
|
|
43
|
+
patchType,
|
|
44
|
+
pre(data) {
|
|
45
|
+
const { args: [req, , next], name, funcKey } = data;
|
|
46
|
+
data.args[2] = function contrastNext(...args) {
|
|
47
|
+
const sourceContext = getSourceContext(SOURCE);
|
|
48
|
+
|
|
49
|
+
if (!sourceContext) {
|
|
50
|
+
logger.error({ funcKey }, 'unable to handle source. Missing `sourceContext`');
|
|
51
|
+
return next(...args);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (sourceContext.parsedBody) {
|
|
55
|
+
logger.trace({ funcKey }, 'values already tracked');
|
|
56
|
+
return next(...args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
sources.handle({
|
|
61
|
+
context: 'req.body',
|
|
62
|
+
data: req.body,
|
|
63
|
+
inputType: BODY,
|
|
64
|
+
name,
|
|
65
|
+
stacktraceOpts: {
|
|
66
|
+
constructorOpt: contrastNext,
|
|
67
|
+
},
|
|
68
|
+
sourceContext,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
sourceContext.parsedBody = true;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
logger.error({ err, funcKey }, 'unable to handle Restify source');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return next(...args);
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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 init(core) {
|
|
21
|
+
core.assess.dataflow.sources.restifyInstrumentation = {
|
|
22
|
+
install() {
|
|
23
|
+
callChildComponentMethodsSync(this, 'install');
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
require('./fieldedTextBodyParser')(core);
|
|
28
|
+
require('./jsonBodyParser')(core);
|
|
29
|
+
require('./router')(core);
|
|
30
|
+
|
|
31
|
+
return core.assess.dataflow.sources.restifyInstrumentation;
|
|
32
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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 { InputType: { JSON_VALUE } } = require('@contrast/common');
|
|
19
|
+
const { InstrumentationType: { SOURCE } } = require('../../../../constants');
|
|
20
|
+
const { patchType } = require('../../common');
|
|
21
|
+
|
|
22
|
+
module.exports = function init(core) {
|
|
23
|
+
const {
|
|
24
|
+
logger,
|
|
25
|
+
depHooks,
|
|
26
|
+
patcher,
|
|
27
|
+
assess: {
|
|
28
|
+
dataflow: { sources },
|
|
29
|
+
getSourceContext,
|
|
30
|
+
},
|
|
31
|
+
} = core;
|
|
32
|
+
|
|
33
|
+
return core.assess.dataflow.sources.restifyInstrumentation.jsonBodyParser = {
|
|
34
|
+
install() {
|
|
35
|
+
depHooks.resolve(
|
|
36
|
+
{ name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8' },
|
|
37
|
+
(jsonBodyParser) => patcher.patch(jsonBodyParser, {
|
|
38
|
+
name: 'restify.plugins.jsonBodyParser',
|
|
39
|
+
patchType,
|
|
40
|
+
post(data) {
|
|
41
|
+
const { args: [opts] } = data;
|
|
42
|
+
const index = data.result.length - 1;
|
|
43
|
+
|
|
44
|
+
data.result[index] = patcher.patch(data.result[index], {
|
|
45
|
+
name: 'restify.plugins.jsonBodyParser.parseJson',
|
|
46
|
+
patchType,
|
|
47
|
+
pre(data) {
|
|
48
|
+
const { args: [req, , next], name, funcKey } = data;
|
|
49
|
+
|
|
50
|
+
data.args[2] = function contrastNext(...args) {
|
|
51
|
+
const sourceContext = getSourceContext(SOURCE);
|
|
52
|
+
|
|
53
|
+
if (!sourceContext) {
|
|
54
|
+
logger.error({ funcKey }, 'unable to handle source. Missing `sourceContext`');
|
|
55
|
+
return next(...args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (sourceContext.parsedBody) {
|
|
59
|
+
logger.trace({ funcKey }, 'values already tracked');
|
|
60
|
+
return next(...args);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
sources.handle({
|
|
65
|
+
context: 'req.body',
|
|
66
|
+
data: req.body,
|
|
67
|
+
inputType: JSON_VALUE,
|
|
68
|
+
name,
|
|
69
|
+
stacktraceOpts: {
|
|
70
|
+
constructorOpt: contrastNext,
|
|
71
|
+
},
|
|
72
|
+
sourceContext,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
sourceContext.parsedBody = true;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
logger.error({ err, funcKey }, 'unable to handle Restify source');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (opts?.mapParams) {
|
|
81
|
+
// we don't check for parsedParams first since these clobber
|
|
82
|
+
try {
|
|
83
|
+
sources.handle({
|
|
84
|
+
context: 'req.params',
|
|
85
|
+
data: req.params,
|
|
86
|
+
inputType: JSON_VALUE,
|
|
87
|
+
name,
|
|
88
|
+
stacktraceOpts: {
|
|
89
|
+
constructorOpt: contrastNext,
|
|
90
|
+
},
|
|
91
|
+
sourceContext,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
sourceContext.parsedParams = true;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
logger.error({ err, funcKey }, 'unable to handle Restify source');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return next(...args);
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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 { InputType: { URL_PARAMETER } } = require('@contrast/common');
|
|
19
|
+
const { InstrumentationType: { SOURCE } } = require('../../../../constants');
|
|
20
|
+
const { patchType } = require('../../common');
|
|
21
|
+
|
|
22
|
+
module.exports = function init(core) {
|
|
23
|
+
const {
|
|
24
|
+
logger,
|
|
25
|
+
depHooks,
|
|
26
|
+
patcher,
|
|
27
|
+
assess: {
|
|
28
|
+
dataflow: { sources },
|
|
29
|
+
getSourceContext,
|
|
30
|
+
},
|
|
31
|
+
} = core;
|
|
32
|
+
|
|
33
|
+
return core.assess.dataflow.sources.restifyInstrumentation.router = {
|
|
34
|
+
install() {
|
|
35
|
+
depHooks.resolve(
|
|
36
|
+
{ name: 'restify', file: 'lib/router.js', version: '>=8' },
|
|
37
|
+
(Router) => {
|
|
38
|
+
patcher.patch(Router.prototype, 'lookup', {
|
|
39
|
+
name: 'restify.Router.prototype.lookup',
|
|
40
|
+
patchType,
|
|
41
|
+
post({ args: [req], hooked, orig, name, funcKey }) {
|
|
42
|
+
const sourceContext = getSourceContext(SOURCE);
|
|
43
|
+
|
|
44
|
+
if (!sourceContext) {
|
|
45
|
+
logger.error({ funcKey }, 'unable to handle source. Missing `sourceContext`');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (sourceContext.parsedParams) {
|
|
50
|
+
logger.trace({ funcKey }, 'values already tracked');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
sources.handle({
|
|
56
|
+
context: 'req.params',
|
|
57
|
+
data: req.params,
|
|
58
|
+
inputType: URL_PARAMETER,
|
|
59
|
+
name,
|
|
60
|
+
stacktraceOpts: {
|
|
61
|
+
constructorOpt: hooked,
|
|
62
|
+
prependFrames: [orig],
|
|
63
|
+
},
|
|
64
|
+
sourceContext,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
sourceContext.parsedParams = true;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
logger.error({ err, funcKey }, 'unable to handle Restify source');
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const { StringPrototypeSplit } = require('@contrast/common');
|
|
18
18
|
|
|
19
19
|
//
|
|
20
20
|
// This module implements tag range manipulation functions. There are generally
|
|
@@ -485,8 +485,8 @@ function createAdjustedQueryTags(path, tags, value, argString) {
|
|
|
485
485
|
* - "?test=str","%3Ftest%3Dstr",{"UNTRUSTED":[0,8]} => {"UNTRUSTED":[3,6,10,12]}
|
|
486
486
|
*/
|
|
487
487
|
function createEscapeTagRanges(input, result, tags) {
|
|
488
|
-
const inputArr =
|
|
489
|
-
const escapedArr =
|
|
488
|
+
const inputArr = StringPrototypeSplit.call(input, '');
|
|
489
|
+
const escapedArr = StringPrototypeSplit.call(result, '');
|
|
490
490
|
const overlap = inputArr.filter((x) => {
|
|
491
491
|
if (escapedArr.includes(x)) {
|
|
492
492
|
return x;
|
|
@@ -533,7 +533,7 @@ function createEscapeTagRanges(input, result, tags) {
|
|
|
533
533
|
* @returns {string} the adjusted value for reporting
|
|
534
534
|
*/
|
|
535
535
|
function getAdjustedUntrackedValue(origValue) {
|
|
536
|
-
return origValue?.constructor?.name ?? (origValue === null ? 'null' : typeof
|
|
536
|
+
return origValue?.constructor?.name ?? (origValue === null ? 'null' : typeof origValue);
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
module.exports = {
|
package/lib/dataflow/tracker.js
CHANGED
package/lib/event-factory.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const { InputType,
|
|
18
|
+
const { InputType, StringPrototypeMatch } = require('@contrast/common');
|
|
19
19
|
const ANNOTATION_REGEX = /^(A|O|R|P|P\d+)$/;
|
|
20
20
|
const SOURCE_EVENT_MSG = 'Source event not created: %s';
|
|
21
21
|
const PROPAGATION_EVENT_MSG = 'Propagation event not created: %s';
|
|
@@ -113,12 +113,12 @@ module.exports = function (core) {
|
|
|
113
113
|
return null;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
if (!source || !
|
|
116
|
+
if (!source || !StringPrototypeMatch.call(source, ANNOTATION_REGEX)) {
|
|
117
117
|
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid source');
|
|
118
118
|
return null;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
if (!target || !
|
|
121
|
+
if (!target || !StringPrototypeMatch.call(target, ANNOTATION_REGEX)) {
|
|
122
122
|
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid target');
|
|
123
123
|
return null;
|
|
124
124
|
}
|
package/lib/get-policy.js
CHANGED
|
@@ -22,7 +22,7 @@ const {
|
|
|
22
22
|
Rule,
|
|
23
23
|
ResponseScanningRule,
|
|
24
24
|
SessionConfigurationRule,
|
|
25
|
-
|
|
25
|
+
ArrayPrototypeJoin,
|
|
26
26
|
} = require('@contrast/common');
|
|
27
27
|
|
|
28
28
|
const ASSESS_RULES = Object.values({
|
|
@@ -279,7 +279,7 @@ class UrlExclusion {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
if (regexSegments.length) {
|
|
282
|
-
this._urlRegex = new RegExp(`^${
|
|
282
|
+
this._urlRegex = new RegExp(`^${ArrayPrototypeJoin.call(regexSegments, '|')}$`);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,6 +17,20 @@ import {
|
|
|
17
17
|
Rule,
|
|
18
18
|
SessionConfigurationRule,
|
|
19
19
|
} from '@contrast/common';
|
|
20
|
+
import { Core as _Core } from '@contrast/core';
|
|
21
|
+
|
|
22
|
+
export interface Core extends _Core {
|
|
23
|
+
config: Config;
|
|
24
|
+
logger: Logger;
|
|
25
|
+
depHooks: RequireHook;
|
|
26
|
+
patcher: Patcher
|
|
27
|
+
rewriter: Rewriter;
|
|
28
|
+
scopes: Scopes;
|
|
29
|
+
deadzones: Deadzones;
|
|
30
|
+
reporter: ReporterBus;
|
|
31
|
+
instrumentation: any;
|
|
32
|
+
metrics: any;
|
|
33
|
+
}
|
|
20
34
|
|
|
21
35
|
export enum InstrumentationType {
|
|
22
36
|
SOURCE = 'source',
|
|
@@ -62,3 +76,7 @@ export interface Assess {
|
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
export function getSourceContext(instrType?: InstrumentationType, ops?: any): SourceContext;
|
|
79
|
+
|
|
80
|
+
declare function init(core: Core): Assess;
|
|
81
|
+
|
|
82
|
+
export = init;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const { StringPrototypeToLowerCase } = require('@contrast/common');
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {{
|
|
@@ -48,7 +48,7 @@ module.exports = function(core) {
|
|
|
48
48
|
// copy to avoid storing tracked values
|
|
49
49
|
const headers = { ...req.headers };
|
|
50
50
|
if (headers['content-type']) {
|
|
51
|
-
contentType =
|
|
51
|
+
contentType = StringPrototypeToLowerCase.call(headers['content-type']);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
return {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
StringPrototypeToLowerCase,
|
|
20
|
+
JSONStringify,
|
|
21
|
+
StringPrototypeSubstring,
|
|
22
22
|
ResponseScanningRule
|
|
23
23
|
} = require('@contrast/common');
|
|
24
24
|
const {
|
|
@@ -56,15 +56,15 @@ module.exports = function(core) {
|
|
|
56
56
|
}
|
|
57
57
|
} = core;
|
|
58
58
|
|
|
59
|
-
responseScanning.handleAutoCompleteMissing = function(sourceContext,
|
|
59
|
+
responseScanning.handleAutoCompleteMissing = function(sourceContext, resHeaders, resBody) {
|
|
60
60
|
if (
|
|
61
61
|
!isEnabled(AUTOCOMPLETE_MISSING, sourceContext) ||
|
|
62
|
-
!isHtmlContent(
|
|
62
|
+
!isHtmlContent(resHeaders)
|
|
63
63
|
) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const elements = getElements('form',
|
|
67
|
+
const elements = getElements('form', resBody);
|
|
68
68
|
|
|
69
69
|
for (let i = 0; i < elements.length; i++) {
|
|
70
70
|
const autocomplete = getAttribute('autocomplete', elements[i]);
|
|
@@ -84,24 +84,24 @@ module.exports = function(core) {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
responseScanning.handleCacheControlsMissing = function(sourceContext,
|
|
87
|
+
responseScanning.handleCacheControlsMissing = function(sourceContext, resHeaders, resBody) {
|
|
88
88
|
const instructions = [];
|
|
89
89
|
|
|
90
90
|
// de-dupe; this will be re-emitted for parseableBody handlers anyway
|
|
91
91
|
if (
|
|
92
92
|
!isEnabled(CACHE_CONTROLS_MISSING, sourceContext) ||
|
|
93
|
-
(isParseableResponse(
|
|
93
|
+
(isParseableResponse(resHeaders) && !resBody)
|
|
94
94
|
) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
const cacheControlHeader =
|
|
97
|
+
const cacheControlHeader = resHeaders['cache-control'];
|
|
98
98
|
|
|
99
99
|
// save the Pragma Header
|
|
100
|
-
if (
|
|
100
|
+
if (resHeaders['pragma']) {
|
|
101
101
|
instructions.push({
|
|
102
102
|
type: 'Header',
|
|
103
103
|
name: 'pragma',
|
|
104
|
-
value:
|
|
104
|
+
value: resHeaders['pragma']
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -124,27 +124,27 @@ module.exports = function(core) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// we checked the headers now time to check the HTML content
|
|
127
|
-
checkMetaTags({ body:
|
|
127
|
+
checkMetaTags({ body: resBody, cacheControlHeader, instructions });
|
|
128
128
|
|
|
129
129
|
if (instructions.length) {
|
|
130
130
|
reportFindings(sourceContext, {
|
|
131
131
|
ruleId: ResponseScanningRule.CACHE_CONTROLS_MISSING,
|
|
132
132
|
vulnerabilityMetadata: {
|
|
133
|
-
data:
|
|
133
|
+
data: JSONStringify(instructions)
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
responseScanning.handleClickJackingControlsMissing = function(sourceContext,
|
|
139
|
+
responseScanning.handleClickJackingControlsMissing = function(sourceContext, resHeaders) {
|
|
140
140
|
if (!isEnabled(CLICKJACKING_CONTROL_MISSING, sourceContext)) return;
|
|
141
141
|
|
|
142
142
|
// look for x-frame-options headers with deny or sameorigin
|
|
143
|
-
const xFrameHeaders =
|
|
143
|
+
const xFrameHeaders = resHeaders['x-frame-options'];
|
|
144
144
|
let hasFrameBusting = false;
|
|
145
145
|
|
|
146
146
|
if (xFrameHeaders) {
|
|
147
|
-
const xFrameHeadersLC =
|
|
147
|
+
const xFrameHeadersLC = StringPrototypeToLowerCase.call(xFrameHeaders);
|
|
148
148
|
hasFrameBusting =
|
|
149
149
|
xFrameHeadersLC.indexOf('deny') > -1 ||
|
|
150
150
|
xFrameHeadersLC.indexOf('sameorigin') > -1;
|
|
@@ -155,12 +155,12 @@ module.exports = function(core) {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
responseScanning.handleParameterPollution = function(sourceContext,
|
|
158
|
+
responseScanning.handleParameterPollution = function(sourceContext, resBody) {
|
|
159
159
|
if (!isEnabled(PARAMETER_POLLUTION, sourceContext)) return;
|
|
160
160
|
|
|
161
161
|
// look for form tag with missing action attribute.
|
|
162
162
|
// ex: <form method="post">..
|
|
163
|
-
const elements = getElements('form',
|
|
163
|
+
const elements = getElements('form', resBody);
|
|
164
164
|
|
|
165
165
|
for (let i = 0; i < elements.length; i++) {
|
|
166
166
|
const action = getAttribute('action', elements[i]);
|
|
@@ -180,11 +180,11 @@ module.exports = function(core) {
|
|
|
180
180
|
* Checks the response headers for the CSP. If found, and insecure, will return
|
|
181
181
|
* the evidence for reporting.
|
|
182
182
|
*
|
|
183
|
-
* @param {Object}
|
|
184
|
-
* @returns {Object}
|
|
183
|
+
* @param {Object} resHeaders HTTP headers object.
|
|
184
|
+
* @returns {Object} Evidence for insecure CSP header.
|
|
185
185
|
*/
|
|
186
|
-
responseScanning.handleCspHeader = function(sourceContext,
|
|
187
|
-
const cspHeaders = getCspHeaders(
|
|
186
|
+
responseScanning.handleCspHeader = function(sourceContext, resHeaders) {
|
|
187
|
+
const cspHeaders = getCspHeaders(resHeaders);
|
|
188
188
|
|
|
189
189
|
// Don't report if not set; this report belongs to 'csp-header-missing'
|
|
190
190
|
if (!cspHeaders && isEnabled(CSP_HEADER_MISSING, sourceContext)) {
|
|
@@ -213,23 +213,23 @@ module.exports = function(core) {
|
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
responseScanning.handleHstsHeaderMissing = function(sourceContext,
|
|
216
|
+
responseScanning.handleHstsHeaderMissing = function(sourceContext, resHeaders) {
|
|
217
217
|
if (!isEnabled(HSTS_HEADER_MISSING, sourceContext)) return;
|
|
218
218
|
|
|
219
|
-
let header =
|
|
219
|
+
let header = resHeaders['strict-transport-security'];
|
|
220
220
|
let maxAge;
|
|
221
221
|
|
|
222
222
|
if (header) {
|
|
223
|
-
header =
|
|
223
|
+
header = StringPrototypeToLowerCase.call(header);
|
|
224
224
|
const flag = header.indexOf('max-age');
|
|
225
225
|
if (flag > -1) {
|
|
226
226
|
const equal = header.indexOf('=', flag);
|
|
227
227
|
if (equal > -1) {
|
|
228
228
|
const semicolon = header.indexOf(';', equal);
|
|
229
229
|
if (semicolon > -1) {
|
|
230
|
-
maxAge =
|
|
230
|
+
maxAge = StringPrototypeSubstring.call(header, equal + 1, semicolon);
|
|
231
231
|
} else {
|
|
232
|
-
maxAge =
|
|
232
|
+
maxAge = StringPrototypeSubstring.call(header, equal + 1);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -245,14 +245,14 @@ module.exports = function(core) {
|
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
247
|
|
|
248
|
-
responseScanning.handleXContentTypeHeaderMissing = function(sourceContext,
|
|
248
|
+
responseScanning.handleXContentTypeHeaderMissing = function(sourceContext, resHeaders) {
|
|
249
249
|
if (!isEnabled(XCONTENTTYPE_HEADER_MISSING, sourceContext)) return;
|
|
250
250
|
|
|
251
251
|
const headerName = 'x-content-type-options';
|
|
252
|
-
let header =
|
|
252
|
+
let header = resHeaders[headerName];
|
|
253
253
|
|
|
254
254
|
if (header) {
|
|
255
|
-
header =
|
|
255
|
+
header = StringPrototypeToLowerCase.call(header);
|
|
256
256
|
if (header === 'nosniff') {
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
@@ -266,14 +266,14 @@ module.exports = function(core) {
|
|
|
266
266
|
});
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
-
responseScanning.handleXPoweredByHeader = function(sourceContext,
|
|
269
|
+
responseScanning.handleXPoweredByHeader = function(sourceContext, resHeaders) {
|
|
270
270
|
if (!isEnabled(X_POWERED_BY_HEADER, sourceContext)) return;
|
|
271
271
|
|
|
272
272
|
const headerName = 'x-powered-by';
|
|
273
|
-
let header =
|
|
273
|
+
let header = resHeaders[headerName];
|
|
274
274
|
|
|
275
275
|
if (header) {
|
|
276
|
-
header =
|
|
276
|
+
header = StringPrototypeToLowerCase.call(header);
|
|
277
277
|
|
|
278
278
|
reportFindings(sourceContext, {
|
|
279
279
|
ruleId: ResponseScanningRule.X_POWERED_BY_HEADER,
|
|
@@ -284,7 +284,7 @@ module.exports = function(core) {
|
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
|
|
287
|
-
responseScanning.handleXxsProtectionHeaderDisabled = function(sourceContext,
|
|
287
|
+
responseScanning.handleXxsProtectionHeaderDisabled = function(sourceContext, responseHeaders) {
|
|
288
288
|
if (!isEnabled(XXSPROTECTION_HEADER_DISABLED, sourceContext)) return;
|
|
289
289
|
|
|
290
290
|
const header = responseHeaders['x-xss-protection'];
|