@contrast/assess 1.28.1 → 1.29.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/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 +3 -3
- 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/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/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 +10 -10
- package/lib/response-scanning/handlers/utils.js +19 -12
- package/lib/response-scanning/install/http.js +9 -59
- 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,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 {
|
|
@@ -130,7 +130,7 @@ module.exports = function(core) {
|
|
|
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
|
}
|
|
@@ -144,7 +144,7 @@ module.exports = function(core) {
|
|
|
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;
|
|
@@ -220,16 +220,16 @@ module.exports = function(core) {
|
|
|
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
|
}
|
|
@@ -252,7 +252,7 @@ module.exports = function(core) {
|
|
|
252
252
|
let header = responseHeaders[headerName];
|
|
253
253
|
|
|
254
254
|
if (header) {
|
|
255
|
-
header =
|
|
255
|
+
header = StringPrototypeToLowerCase.call(header);
|
|
256
256
|
if (header === 'nosniff') {
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
@@ -273,7 +273,7 @@ module.exports = function(core) {
|
|
|
273
273
|
let header = responseHeaders[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,
|
|
@@ -15,7 +15,14 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
ArrayPrototypeJoin,
|
|
20
|
+
StringPrototypeSubstring,
|
|
21
|
+
StringPrototypeToLowerCase,
|
|
22
|
+
StringPrototypeSplit,
|
|
23
|
+
StringPrototypeTrim,
|
|
24
|
+
StringPrototypeReplace
|
|
25
|
+
} = require('@contrast/common');
|
|
19
26
|
|
|
20
27
|
//
|
|
21
28
|
// General HTML utils
|
|
@@ -32,7 +39,7 @@ const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
|
32
39
|
|
|
33
40
|
function escapeHtml(string) {
|
|
34
41
|
return (string && reHasUnescapedHtml.test(string))
|
|
35
|
-
?
|
|
42
|
+
? StringPrototypeReplace.call(string, reUnescapedHtml, (chr) => htmlEscapes[chr])
|
|
36
43
|
: (string || '');
|
|
37
44
|
}
|
|
38
45
|
|
|
@@ -54,7 +61,7 @@ function getElements(htmlTag, content = '') {
|
|
|
54
61
|
[htmlTagRangeStart, htmlTagRangeLength] = getHtmlTagRange(htmlTag, content, offset);
|
|
55
62
|
if (htmlTagRangeStart >= 0) {
|
|
56
63
|
offset = htmlTagRangeStart + htmlTagRangeLength;
|
|
57
|
-
elements.push(
|
|
64
|
+
elements.push(StringPrototypeSubstring.call(content, htmlTagRangeStart, offset));
|
|
58
65
|
}
|
|
59
66
|
} while (htmlTagRangeStart >= 0);
|
|
60
67
|
|
|
@@ -69,7 +76,7 @@ function isHtmlContent(responseHeaders) {
|
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
// we may want to do a case-insensitive search through object keys here
|
|
72
|
-
const contentType =
|
|
79
|
+
const contentType = StringPrototypeToLowerCase.call(responseHeaders['Content-Type'] || responseHeaders['content-type'] || '');
|
|
73
80
|
|
|
74
81
|
return (
|
|
75
82
|
!contentType ||
|
|
@@ -88,7 +95,7 @@ function isParseableResponse(responseHeaders) {
|
|
|
88
95
|
// we may want to do a case-insensitive search through object keys here
|
|
89
96
|
let contentType =
|
|
90
97
|
responseHeaders['Content-Type'] || responseHeaders['content-type'];
|
|
91
|
-
if (contentType) contentType =
|
|
98
|
+
if (contentType) contentType = StringPrototypeToLowerCase.call(contentType);
|
|
92
99
|
|
|
93
100
|
return (
|
|
94
101
|
!contentType ||
|
|
@@ -123,7 +130,7 @@ function getAttribute(attribute, htmlTag = '') {
|
|
|
123
130
|
}
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
return
|
|
133
|
+
return StringPrototypeSubstring.call(htmlTag, attrStart, attrEnd);
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
/**
|
|
@@ -213,16 +220,16 @@ function checkCacheControlValue(value = '') {
|
|
|
213
220
|
let noStore = false;
|
|
214
221
|
|
|
215
222
|
value.forEach((directive) => {
|
|
216
|
-
if (
|
|
223
|
+
if (StringPrototypeToLowerCase.call(directive).includes('no-cache')) {
|
|
217
224
|
noCache = true;
|
|
218
225
|
}
|
|
219
|
-
if (
|
|
226
|
+
if (StringPrototypeToLowerCase.call(directive).includes('no-store')) {
|
|
220
227
|
noStore = true;
|
|
221
228
|
}
|
|
222
229
|
});
|
|
223
230
|
return [noCache, noStore];
|
|
224
231
|
} else {
|
|
225
|
-
value =
|
|
232
|
+
value = StringPrototypeToLowerCase.call(value);
|
|
226
233
|
return [value.includes('no-cache'), value.includes('no-store')];
|
|
227
234
|
}
|
|
228
235
|
}
|
|
@@ -317,7 +324,7 @@ function formatSource({
|
|
|
317
324
|
}
|
|
318
325
|
|
|
319
326
|
data[`${key}Secure`] = isSecure;
|
|
320
|
-
data[`${key}Value`] =
|
|
327
|
+
data[`${key}Value`] = ArrayPrototypeJoin.call(sources, ' ');
|
|
321
328
|
}
|
|
322
329
|
|
|
323
330
|
/**
|
|
@@ -325,8 +332,8 @@ function formatSource({
|
|
|
325
332
|
*/
|
|
326
333
|
function policyParser(policy) {
|
|
327
334
|
const result = {};
|
|
328
|
-
for (const directive of
|
|
329
|
-
const [directiveKey, ...directiveValue] =
|
|
335
|
+
for (const directive of StringPrototypeSplit.call(policy, ';')) {
|
|
336
|
+
const [directiveKey, ...directiveValue] = StringPrototypeSplit.call(StringPrototypeTrim.call(directive), /\s+/g);
|
|
330
337
|
if (
|
|
331
338
|
directiveKey &&
|
|
332
339
|
!Object.prototype.hasOwnProperty.call(result, directiveKey)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const { StringPrototypeSplit, StringPrototypeSubstring, StringPrototypeToLowerCase, StringPrototypeTrim } = require('@contrast/common');
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {{
|
|
@@ -46,13 +46,13 @@ module.exports = function(core) {
|
|
|
46
46
|
|
|
47
47
|
function parseHeaders(rawHeaders) {
|
|
48
48
|
const headersToParse = rawHeaders || '';
|
|
49
|
-
const headersArray =
|
|
49
|
+
const headersArray = StringPrototypeSplit.call(headersToParse, '\r\n').filter(Boolean);
|
|
50
50
|
return headersArray.reduce((acc, header) => {
|
|
51
51
|
const idx = header.indexOf(':');
|
|
52
52
|
|
|
53
53
|
if (idx > -1) {
|
|
54
|
-
const name =
|
|
55
|
-
const value =
|
|
54
|
+
const name = StringPrototypeToLowerCase.call(StringPrototypeSubstring.call(header, 0, idx));
|
|
55
|
+
const value = StringPrototypeTrim.call(StringPrototypeSubstring.call(header, idx + 1));
|
|
56
56
|
const currentValue = acc[name];
|
|
57
57
|
acc[name] = currentValue
|
|
58
58
|
? Array.isArray(currentValue)
|
|
@@ -100,7 +100,7 @@ module.exports = function(core) {
|
|
|
100
100
|
if (!sourceContext) return;
|
|
101
101
|
|
|
102
102
|
const evaluationContext = {
|
|
103
|
-
responseBody:
|
|
103
|
+
responseBody: StringPrototypeToLowerCase.call(data.args[0] || ''),
|
|
104
104
|
responseHeaders: parseHeaders(data.result._header),
|
|
105
105
|
};
|
|
106
106
|
|
|
@@ -118,7 +118,7 @@ module.exports = function(core) {
|
|
|
118
118
|
if (!sourceContext) return;
|
|
119
119
|
|
|
120
120
|
const evaluationContext = {
|
|
121
|
-
responseBody:
|
|
121
|
+
responseBody: StringPrototypeToLowerCase.call(data.args[0] || ''),
|
|
122
122
|
responseHeaders: parseHeaders(data.result._header),
|
|
123
123
|
};
|
|
124
124
|
|
|
@@ -141,7 +141,7 @@ module.exports = function(core) {
|
|
|
141
141
|
|
|
142
142
|
const headersSymbol = Object.getOwnPropertySymbols(data.obj).find(symbol => symbol.toString().includes('headers'));
|
|
143
143
|
const evaluationContext = {
|
|
144
|
-
responseBody:
|
|
144
|
+
responseBody: StringPrototypeToLowerCase.call(data.args[0] || ''),
|
|
145
145
|
responseHeaders: data.obj[headersSymbol],
|
|
146
146
|
};
|
|
147
147
|
|
|
@@ -160,7 +160,7 @@ module.exports = function(core) {
|
|
|
160
160
|
|
|
161
161
|
const headersSymbol = Object.getOwnPropertySymbols(data.result).find(symbol => symbol.toString().includes('headers'));
|
|
162
162
|
const evaluationContext = {
|
|
163
|
-
responseBody:
|
|
163
|
+
responseBody: StringPrototypeToLowerCase.call(data.args[0] || ''),
|
|
164
164
|
responseHeaders: data.result[headersSymbol],
|
|
165
165
|
};
|
|
166
166
|
|
|
@@ -169,57 +169,7 @@ module.exports = function(core) {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
// patching the stream object
|
|
173
|
-
['createServer', 'createSecureServer'].forEach((server) => {
|
|
174
|
-
patcher.patch(http2, server, {
|
|
175
|
-
name: `http2.${server}`,
|
|
176
|
-
patchType,
|
|
177
|
-
post(data) {
|
|
178
|
-
// The other option is once again to patch the `emit` method of the server
|
|
179
|
-
// similar to how we patch it for creating sources, but take action only on
|
|
180
|
-
// `stream` events. I chose the currentt approach because the hook will only
|
|
181
|
-
// run on a `stream` event instead of checking and returning on each `request`
|
|
182
|
-
// connect.
|
|
183
|
-
data.result._events = patcher.patch(data.result._events, 'stream', {
|
|
184
|
-
name: 'stream',
|
|
185
|
-
patchType: 'stream-patch',
|
|
186
|
-
pre(data) {
|
|
187
|
-
patcher.patch(data.args[0], 'write', {
|
|
188
|
-
name: 'Http2Stream.write',
|
|
189
|
-
patchType,
|
|
190
|
-
post(data) {
|
|
191
|
-
const sourceContext = getSourceContext();
|
|
192
|
-
if (!sourceContext) return;
|
|
193
|
-
|
|
194
|
-
const evaluationContext = {
|
|
195
|
-
responseBody: toLowerCase(data.args[0] || ''),
|
|
196
|
-
responseHeaders: data.obj.sentHeaders,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
writeHookChecks(sourceContext, evaluationContext);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
patcher.patch(data.args[0], 'end', {
|
|
204
|
-
name: 'Http2Stream.end',
|
|
205
|
-
patchType,
|
|
206
|
-
post(data) {
|
|
207
|
-
const sourceContext = getSourceContext();
|
|
208
|
-
if (!sourceContext) return;
|
|
209
|
-
|
|
210
|
-
const evaluationContext = {
|
|
211
|
-
responseBody: toLowerCase(data.args[0] || ''),
|
|
212
|
-
responseHeaders: data.obj.sentHeaders,
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
endHookChecks(sourceContext, evaluationContext);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
172
|
+
// todo: patching the stream object (NODE-3467)
|
|
223
173
|
});
|
|
224
174
|
};
|
|
225
175
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const { StringPrototypeToLowerCase } = require('@contrast/common');
|
|
18
18
|
const { patchType } = require('../common');
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -102,7 +102,7 @@ module.exports = function (core) {
|
|
|
102
102
|
name: 'http.setHeader',
|
|
103
103
|
patchType,
|
|
104
104
|
pre({ args: [key, value] }) {
|
|
105
|
-
if (
|
|
105
|
+
if (StringPrototypeToLowerCase.call(key) !== 'set-cookie') return;
|
|
106
106
|
|
|
107
107
|
if (checkForHTTPOnly) {
|
|
108
108
|
handleHttpOnly(sourceContext, value, sessionEvent);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const { StringPrototypeToLowerCase } = require('@contrast/common');
|
|
18
18
|
const { patchType } = require('../common');
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -82,7 +82,7 @@ module.exports = function (core) {
|
|
|
82
82
|
name: 'fastify.Reply.header',
|
|
83
83
|
pre(data) {
|
|
84
84
|
const [key, value] = data.args;
|
|
85
|
-
if (
|
|
85
|
+
if (StringPrototypeToLowerCase.call(key) !== 'set-cookie') return;
|
|
86
86
|
|
|
87
87
|
const sourceContext = getSourceContext();
|
|
88
88
|
if (!sourceContext) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/assess",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.0",
|
|
4
4
|
"description": "Contrast service providing framework-agnostic Assess support",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"types": "lib/index.d.ts",
|
|
12
12
|
"engines": {
|
|
13
13
|
"npm": ">=6.13.7 <7 || >= 8.3.1",
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">= 16.9.1"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "../scripts/test.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@contrast/common": "1.21.
|
|
21
|
-
"@contrast/distringuish": "^
|
|
20
|
+
"@contrast/common": "1.21.1",
|
|
21
|
+
"@contrast/distringuish": "^5.0.0",
|
|
22
22
|
"@contrast/scopes": "1.4.1"
|
|
23
23
|
}
|
|
24
24
|
}
|