@contrast/assess 1.19.0 → 1.20.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/LICENSE +1 -1
- package/lib/constants.js +1 -1
- package/lib/crypto-analysis/common.js +1 -1
- package/lib/crypto-analysis/index.js +1 -1
- package/lib/crypto-analysis/install/crypto.js +8 -3
- package/lib/crypto-analysis/install/math.js +8 -3
- package/lib/dataflow/index.js +1 -1
- package/lib/dataflow/propagation/common.js +1 -1
- package/lib/dataflow/propagation/index.js +1 -1
- package/lib/dataflow/propagation/install/JSON/index.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse.js +3 -3
- package/lib/dataflow/propagation/install/JSON/stringify.js +1 -1
- package/lib/dataflow/propagation/install/array-prototype-join.js +1 -1
- package/lib/dataflow/propagation/install/buffer.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/number.js +4 -3
- package/lib/dataflow/propagation/install/contrast-methods/string.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/tag.js +1 -1
- package/lib/dataflow/propagation/install/decode-uri-component.js +1 -1
- package/lib/dataflow/propagation/install/ejs/escape-xml.js +1 -1
- package/lib/dataflow/propagation/install/ejs/index.js +1 -1
- package/lib/dataflow/propagation/install/ejs/template.js +7 -5
- package/lib/dataflow/propagation/install/encode-uri.js +1 -1
- package/lib/dataflow/propagation/install/escape-html.js +1 -1
- package/lib/dataflow/propagation/install/escape.js +1 -1
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +1 -1
- package/lib/dataflow/propagation/install/isnumeric-0.js +3 -3
- package/lib/dataflow/propagation/install/joi/any.js +1 -1
- package/lib/dataflow/propagation/install/joi/boolean.js +1 -1
- package/lib/dataflow/propagation/install/joi/expression.js +1 -1
- package/lib/dataflow/propagation/install/joi/index.js +1 -1
- package/lib/dataflow/propagation/install/joi/keys.js +1 -1
- package/lib/dataflow/propagation/install/joi/number.js +1 -1
- package/lib/dataflow/propagation/install/joi/object.js +1 -1
- package/lib/dataflow/propagation/install/joi/string-schema.js +1 -1
- package/lib/dataflow/propagation/install/joi/utils.js +1 -1
- package/lib/dataflow/propagation/install/joi/values.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/common.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/index.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +1 -1
- package/lib/dataflow/propagation/install/mustache-escape.js +1 -1
- package/lib/dataflow/propagation/install/mysql-connection-escape.js +1 -1
- package/lib/dataflow/propagation/install/parse-int.js +3 -3
- package/lib/dataflow/propagation/install/path/basename.js +1 -1
- package/lib/dataflow/propagation/install/path/common.js +1 -1
- package/lib/dataflow/propagation/install/path/dirname.js +1 -1
- package/lib/dataflow/propagation/install/path/extname.js +1 -1
- package/lib/dataflow/propagation/install/path/format.js +1 -1
- package/lib/dataflow/propagation/install/path/index.js +1 -1
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +1 -1
- package/lib/dataflow/propagation/install/path/normalize.js +1 -1
- package/lib/dataflow/propagation/install/path/parse.js +1 -1
- package/lib/dataflow/propagation/install/path/relative.js +1 -1
- package/lib/dataflow/propagation/install/path/toNamespacedPath.js +1 -1
- package/lib/dataflow/propagation/install/pug/index.js +3 -3
- package/lib/dataflow/propagation/install/pug-runtime-escape.js +1 -1
- package/lib/dataflow/propagation/install/querystring/escape.js +1 -1
- package/lib/dataflow/propagation/install/querystring/index.js +1 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +1 -1
- package/lib/dataflow/propagation/install/querystring/stringify.js +1 -1
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +1 -1
- package/lib/dataflow/propagation/install/send.js +1 -1
- package/lib/dataflow/propagation/install/sequelize/index.js +1 -1
- package/lib/dataflow/propagation/install/sequelize/query-generator.js +1 -1
- package/lib/dataflow/propagation/install/sequelize/sql-string.js +1 -1
- package/lib/dataflow/propagation/install/sql-template-strings.js +1 -1
- package/lib/dataflow/propagation/install/string/concat.js +1 -1
- package/lib/dataflow/propagation/install/string/format-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/index.js +1 -1
- package/lib/dataflow/propagation/install/string/match-all.js +1 -1
- package/lib/dataflow/propagation/install/string/match.js +1 -1
- 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 +1 -1
- package/lib/dataflow/propagation/install/string/trim.js +1 -1
- package/lib/dataflow/propagation/install/unescape.js +1 -1
- package/lib/dataflow/propagation/install/url/domain-parsers.js +1 -1
- package/lib/dataflow/propagation/install/url/index.js +1 -1
- package/lib/dataflow/propagation/install/url/parse.js +1 -1
- package/lib/dataflow/propagation/install/url/searchParams.js +1 -1
- package/lib/dataflow/propagation/install/url/url.js +1 -1
- package/lib/dataflow/propagation/install/util-format.js +1 -1
- package/lib/dataflow/propagation/install/validator/hooks.js +1 -1
- package/lib/dataflow/propagation/install/validator/index.js +1 -1
- package/lib/dataflow/propagation/install/validator/methods.js +1 -1
- package/lib/dataflow/sinks/common.js +1 -1
- package/lib/dataflow/sinks/index.js +1 -1
- package/lib/dataflow/sinks/install/child-process.js +1 -1
- package/lib/dataflow/sinks/install/eval.js +1 -1
- package/lib/dataflow/sinks/install/express/index.js +1 -1
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fastify/index.js +1 -1
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fs.js +1 -1
- package/lib/dataflow/sinks/install/function.js +1 -1
- package/lib/dataflow/sinks/install/http/index.js +1 -1
- package/lib/dataflow/sinks/install/http/request.js +1 -1
- package/lib/dataflow/sinks/install/http/server-response.js +1 -1
- package/lib/dataflow/sinks/install/koa/index.js +1 -1
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/libxmljs.js +1 -1
- package/lib/dataflow/sinks/install/marsdb.js +4 -4
- package/lib/dataflow/sinks/install/mongodb.js +7 -7
- package/lib/dataflow/sinks/install/mssql.js +1 -1
- package/lib/dataflow/sinks/install/mysql.js +1 -1
- package/lib/dataflow/sinks/install/node-serialize.js +1 -1
- package/lib/dataflow/sinks/install/postgres.js +1 -1
- package/lib/dataflow/sinks/install/sequelize.js +7 -8
- package/lib/dataflow/sinks/install/sqlite3.js +1 -1
- package/lib/dataflow/sinks/install/vm.js +1 -1
- package/lib/dataflow/sources/common.js +1 -1
- package/lib/dataflow/sources/handler.js +11 -10
- package/lib/dataflow/sources/index.js +2 -2
- package/lib/dataflow/sources/install/body-parser1.js +11 -13
- package/lib/dataflow/sources/install/{busboy1.js → busboy.js} +15 -15
- package/lib/dataflow/sources/install/cookie-parser1.js +7 -6
- package/lib/dataflow/sources/install/express/index.js +1 -1
- package/lib/dataflow/sources/install/express/params.js +9 -10
- package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
- package/lib/dataflow/sources/install/fastify/fastify.js +6 -7
- package/lib/dataflow/sources/install/fastify/index.js +1 -1
- package/lib/dataflow/sources/install/formidable1.js +8 -6
- package/lib/dataflow/sources/install/http.js +4 -4
- package/lib/dataflow/sources/install/koa/index.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +10 -9
- package/lib/dataflow/sources/install/koa/koa-multer.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-routers.js +6 -8
- package/lib/dataflow/sources/install/koa/koa2.js +42 -38
- package/lib/dataflow/sources/install/multer1.js +1 -1
- package/lib/dataflow/sources/install/qs6.js +7 -6
- package/lib/dataflow/sources/install/querystring.js +4 -4
- package/lib/dataflow/tag-utils.js +1 -1
- package/lib/dataflow/tracker.js +1 -1
- package/lib/dataflow/utils/is-safe-content-type.js +1 -1
- package/lib/dataflow/utils/is-vulnerable.js +1 -1
- package/lib/event-factory.js +30 -28
- package/lib/get-policy.js +1 -1
- package/lib/get-source-context.js +1 -1
- package/lib/index.d.ts +16 -2
- package/lib/index.js +1 -1
- package/lib/make-source-context.js +6 -2
- package/lib/response-scanning/handlers/index.js +1 -1
- package/lib/response-scanning/handlers/utils.js +1 -1
- package/lib/response-scanning/index.js +1 -1
- package/lib/response-scanning/install/http.js +1 -1
- package/lib/rule-scopes.js +1 -1
- package/lib/session-configuration/common.js +1 -1
- package/lib/session-configuration/handlers.js +67 -49
- package/lib/session-configuration/index.js +3 -1
- package/lib/session-configuration/install/express-session.js +15 -24
- package/lib/session-configuration/install/fastify-cookie.js +110 -0
- package/lib/session-configuration/install/hapi.js +8 -11
- package/lib/session-configuration/install/koa.js +101 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -17,70 +17,88 @@
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
Event,
|
|
20
|
-
SessionConfigurationRule
|
|
20
|
+
SessionConfigurationRule,
|
|
21
|
+
isString,
|
|
21
22
|
} = require('@contrast/common');
|
|
22
23
|
|
|
24
|
+
const { HTTPONLY, SECURE_FLAG_MISSING } = SessionConfigurationRule;
|
|
25
|
+
|
|
23
26
|
module.exports = function (core) {
|
|
24
27
|
const {
|
|
25
28
|
assess: { sessionConfiguration },
|
|
26
29
|
messages,
|
|
27
30
|
} = core;
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
properties: {
|
|
39
|
-
evidence: cookieValue,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
};
|
|
32
|
+
function* ensureIterable(value) {
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
for (let i = 0; i < value.length; i++) {
|
|
35
|
+
yield value[i];
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
yield value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @param {SessionConfigurationRule} ruleId
|
|
44
|
+
* @param {import('@contrast/assess').SourceContext} sourceContext
|
|
45
|
+
* @returns {import('@contrast/assess').SessionRuleState}
|
|
46
|
+
*/
|
|
47
|
+
function ensureState(ruleId, sourceContext) {
|
|
48
|
+
if (!sourceContext.ruleState[ruleId]) {
|
|
49
|
+
sourceContext.ruleState[ruleId] = {
|
|
50
|
+
reported: false,
|
|
51
|
+
valuesAnalyzed: new Set(),
|
|
52
|
+
};
|
|
54
53
|
}
|
|
54
|
+
return sourceContext.ruleState[ruleId];
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
function isVulnerable(ruleId, value) {
|
|
58
|
+
if (!isString(value)) return false;
|
|
59
|
+
|
|
60
|
+
const search = ruleId === HTTPONLY ? 'HttpOnly;'
|
|
61
|
+
: ruleId === SECURE_FLAG_MISSING ? 'Secure;'
|
|
62
|
+
: undefined;
|
|
63
|
+
|
|
64
|
+
return search && value.indexOf(search) === -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handle(ruleId, sourceContext, cookie, sessionEvent) {
|
|
68
|
+
const state = ensureState(ruleId, sourceContext);
|
|
69
|
+
|
|
70
|
+
if (!sourceContext?.policy?.enabledRules?.has?.(ruleId) || state.reported) return;
|
|
71
|
+
|
|
72
|
+
for (const value of ensureIterable(cookie)) {
|
|
73
|
+
if (state.valuesAnalyzed.has(value)) continue;
|
|
74
|
+
|
|
75
|
+
state.valuesAnalyzed.add(value);
|
|
76
|
+
if (!isVulnerable(ruleId, value)) continue;
|
|
77
|
+
|
|
78
|
+
else {
|
|
79
|
+
sessionConfiguration.reportFindings({
|
|
80
|
+
ruleId,
|
|
81
|
+
sinkEvent: sessionEvent,
|
|
82
|
+
properties: {
|
|
83
|
+
evidence: value,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
state.reported = true;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
58
91
|
|
|
59
|
-
sessionConfiguration.handleHttpOnly = function
|
|
60
|
-
sourceContext,
|
|
61
|
-
cookieValue,
|
|
62
|
-
sessionEvent
|
|
63
|
-
) {
|
|
64
|
-
handleCookie(sourceContext, cookieValue, HTTPONLY, sessionEvent);
|
|
92
|
+
sessionConfiguration.handleHttpOnly = function(sourceContext, cookie, sessionEvent) {
|
|
93
|
+
handle(HTTPONLY, sourceContext, cookie, sessionEvent);
|
|
65
94
|
};
|
|
66
95
|
|
|
67
|
-
sessionConfiguration.handleSecure = function (
|
|
68
|
-
sourceContext,
|
|
69
|
-
cookieValue,
|
|
70
|
-
sessionEvent
|
|
71
|
-
) {
|
|
72
|
-
handleCookie(sourceContext, cookieValue, SECURE_FLAG_MISSING, sessionEvent);
|
|
96
|
+
sessionConfiguration.handleSecure = function (sourceContext, cookie, sessionEvent) {
|
|
97
|
+
handle(SECURE_FLAG_MISSING, sourceContext, cookie, sessionEvent);
|
|
73
98
|
};
|
|
74
99
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_sourceContext,
|
|
78
|
-
vulnerabilityMetadata
|
|
79
|
-
) {
|
|
80
|
-
messages.emit(
|
|
81
|
-
Event.ASSESS_SESSION_CONFIGURATION_FINDING,
|
|
82
|
-
vulnerabilityMetadata
|
|
83
|
-
);
|
|
100
|
+
sessionConfiguration.reportFindings = function (finding) {
|
|
101
|
+
messages.emit(Event.ASSESS_SESSION_CONFIGURATION_FINDING, finding);
|
|
84
102
|
};
|
|
85
103
|
|
|
86
104
|
return sessionConfiguration;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -22,7 +22,9 @@ module.exports = function(core) {
|
|
|
22
22
|
|
|
23
23
|
require('./handlers')(core);
|
|
24
24
|
require('./install/express-session')(core);
|
|
25
|
+
require('./install/fastify-cookie')(core);
|
|
25
26
|
require('./install/hapi')(core);
|
|
27
|
+
require('./install/koa')(core);
|
|
26
28
|
|
|
27
29
|
sessionConfiguration.install = function() {
|
|
28
30
|
callChildComponentMethodsSync(sessionConfiguration, 'install');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -50,36 +50,27 @@ module.exports = function (core) {
|
|
|
50
50
|
patchType,
|
|
51
51
|
post(data) {
|
|
52
52
|
const options = data.args[0];
|
|
53
|
-
|
|
54
|
-
// obfuscate the cookie secret
|
|
55
|
-
if (Array.isArray(data.args) && data.args[0] && data.args[0].secret) {
|
|
56
|
-
data.args[0].secret = '[HIDDEN]';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { cookie } = options || {};
|
|
60
|
-
const hasOwnPropertyHttpOnly = cookie && Object.prototype.hasOwnProperty.call(
|
|
61
|
-
cookie,
|
|
62
|
-
'httpOnly'
|
|
63
|
-
);
|
|
53
|
+
const cookie = options?.cookie || {};
|
|
64
54
|
|
|
65
55
|
// httpOnly is true by default if it's not provided
|
|
66
|
-
const checkForHTTPOnly =
|
|
67
|
-
cookie && hasOwnPropertyHttpOnly
|
|
68
|
-
? !(cookie.httpOnly === true)
|
|
69
|
-
: false;
|
|
70
|
-
|
|
56
|
+
const checkForHTTPOnly = 'httpOnly' in cookie ? cookie.httpOnly !== true : false;
|
|
71
57
|
// secure is false by default
|
|
72
|
-
|
|
58
|
+
if (!checkForHTTPOnly && cookie?.secure) return;
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
const displayOptions = {
|
|
61
|
+
cookie: {
|
|
62
|
+
httpOnly: cookie?.httpOnly,
|
|
63
|
+
secure: cookie?.secure
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const optionsString = inspect(displayOptions);
|
|
76
67
|
|
|
77
68
|
const sessionEvent = createSessionEvent({
|
|
78
69
|
args: [{
|
|
79
70
|
tracked: false,
|
|
80
|
-
value:
|
|
71
|
+
value: optionsString,
|
|
81
72
|
}],
|
|
82
|
-
context: `expressSession(${
|
|
73
|
+
context: `expressSession(${optionsString})`,
|
|
83
74
|
history: [],
|
|
84
75
|
name: 'express.hookedSessionConstructor',
|
|
85
76
|
moduleName: 'express-session',
|
|
@@ -97,7 +88,7 @@ module.exports = function (core) {
|
|
|
97
88
|
constructorOpt: data.hooked,
|
|
98
89
|
},
|
|
99
90
|
framework: 'express',
|
|
100
|
-
options,
|
|
91
|
+
options: displayOptions,
|
|
101
92
|
});
|
|
102
93
|
|
|
103
94
|
patcher.patch(data, 'result', {
|
|
@@ -119,7 +110,7 @@ module.exports = function (core) {
|
|
|
119
110
|
handleHttpOnly(sourceContext, value, sessionEvent);
|
|
120
111
|
}
|
|
121
112
|
|
|
122
|
-
if (
|
|
113
|
+
if (!cookie?.secure) {
|
|
123
114
|
handleSecure(sourceContext, value, sessionEvent);
|
|
124
115
|
}
|
|
125
116
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { inspect } = require('util');
|
|
18
|
+
const { toLowerCase } = require('@contrast/common');
|
|
19
|
+
const { patchType } = require('../common');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{
|
|
23
|
+
* assess: import('@contrast/assess').Assess,
|
|
24
|
+
* scopes: import('@contrast/scopes').Scopes,
|
|
25
|
+
* }} core
|
|
26
|
+
*/
|
|
27
|
+
module.exports = function (core) {
|
|
28
|
+
const {
|
|
29
|
+
assess: {
|
|
30
|
+
getSourceContext,
|
|
31
|
+
eventFactory: { createSessionEvent },
|
|
32
|
+
sessionConfiguration: {
|
|
33
|
+
handleHttpOnly,
|
|
34
|
+
handleSecure,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
depHooks,
|
|
38
|
+
patcher,
|
|
39
|
+
} = core;
|
|
40
|
+
|
|
41
|
+
return core.assess.sessionConfiguration.fastifyCookie = {
|
|
42
|
+
install () {
|
|
43
|
+
depHooks.resolve({ name: '@fastify/cookie' }, (_export) => {
|
|
44
|
+
const patched = patcher.patch(_export, {
|
|
45
|
+
name: 'express.hookedSessionConstructor',
|
|
46
|
+
patchType,
|
|
47
|
+
pre(data) {
|
|
48
|
+
const [server, options] = data.args;
|
|
49
|
+
|
|
50
|
+
// neither default to safe (truthy) values
|
|
51
|
+
const httpOnly = options?.parseOptions?.httpOnly;
|
|
52
|
+
const secure = options?.parseOptions?.secure;
|
|
53
|
+
if (httpOnly && secure) return;
|
|
54
|
+
|
|
55
|
+
const displayArg = inspect({ parseOptions: { httpOnly, secure } });
|
|
56
|
+
const sessionEvent = createSessionEvent({
|
|
57
|
+
args: [{
|
|
58
|
+
tracked: false,
|
|
59
|
+
value: displayArg
|
|
60
|
+
}],
|
|
61
|
+
context: `fastifyCookie(${displayArg})`,
|
|
62
|
+
history: [],
|
|
63
|
+
name: 'fastifyCookie',
|
|
64
|
+
moduleName: '@fastify/cookie',
|
|
65
|
+
methodName: '',
|
|
66
|
+
object: {
|
|
67
|
+
tracked: false,
|
|
68
|
+
value: '@fastify/cookie',
|
|
69
|
+
},
|
|
70
|
+
result: {
|
|
71
|
+
tracked: false,
|
|
72
|
+
},
|
|
73
|
+
source: 'P0',
|
|
74
|
+
stack: [],
|
|
75
|
+
tags: {},
|
|
76
|
+
framework: '@fastify/cookie',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
server.addHook('onRequest', async (request, reply) => {
|
|
80
|
+
patcher.patch(reply, 'header', {
|
|
81
|
+
patchType,
|
|
82
|
+
name: 'fastify.Reply.header',
|
|
83
|
+
pre(data) {
|
|
84
|
+
const [key, value] = data.args;
|
|
85
|
+
if (toLowerCase(key) !== 'set-cookie') return;
|
|
86
|
+
|
|
87
|
+
const sourceContext = getSourceContext();
|
|
88
|
+
if (!sourceContext) return;
|
|
89
|
+
|
|
90
|
+
if (!httpOnly) {
|
|
91
|
+
handleHttpOnly(sourceContext, value, sessionEvent);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!secure) {
|
|
95
|
+
handleSecure(sourceContext, value, sessionEvent);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
_export.default = patched;
|
|
104
|
+
_export.fastifyCookie = patched;
|
|
105
|
+
|
|
106
|
+
return patched;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -36,7 +36,6 @@ module.exports = function (core) {
|
|
|
36
36
|
const inspect = patcher.unwrap(util.inspect);
|
|
37
37
|
|
|
38
38
|
hapiSession.install = function () {
|
|
39
|
-
|
|
40
39
|
return depHooks.resolve({ name: '@hapi/hapi', version: '>=18 <21' }, (hapi) => {
|
|
41
40
|
['server', 'Server'].forEach((server) => {
|
|
42
41
|
patcher.patch(hapi, server, {
|
|
@@ -47,14 +46,12 @@ module.exports = function (core) {
|
|
|
47
46
|
name: 'state',
|
|
48
47
|
patchType,
|
|
49
48
|
post(data) {
|
|
50
|
-
|
|
51
49
|
const options = data.args[1];
|
|
52
|
-
|
|
53
50
|
const httpOnly = Object.prototype.hasOwnProperty.call(options, 'isHttpOnly') ? options.isHttpOnly : true;
|
|
54
51
|
const isSecure = Object.prototype.hasOwnProperty.call(options, 'isSecure') ? options.isSecure : true;
|
|
55
|
-
|
|
52
|
+
|
|
56
53
|
if (httpOnly && isSecure) return;
|
|
57
|
-
|
|
54
|
+
|
|
58
55
|
const sessionEvent = createSessionEvent({
|
|
59
56
|
args: [{
|
|
60
57
|
tracked: false,
|
|
@@ -80,18 +77,18 @@ module.exports = function (core) {
|
|
|
80
77
|
framework: 'hapi',
|
|
81
78
|
options
|
|
82
79
|
});
|
|
83
|
-
|
|
80
|
+
|
|
84
81
|
data.obj.ext('onPostResponse', ({ response: { headers } }) => {
|
|
85
82
|
const value = headers?.['set-cookie']?.[0];
|
|
86
83
|
if (!value) return;
|
|
87
|
-
|
|
84
|
+
|
|
88
85
|
const sourceContext = sources.getStore()?.assess;
|
|
89
86
|
if (!sourceContext) return;
|
|
90
|
-
|
|
87
|
+
|
|
91
88
|
if (!httpOnly) {
|
|
92
89
|
handleHttpOnly(sourceContext, `set-cookie: ${value}`, sessionEvent);
|
|
93
90
|
}
|
|
94
|
-
|
|
91
|
+
|
|
95
92
|
if (!isSecure) {
|
|
96
93
|
handleSecure(sourceContext, `set-cookie: ${value}`, sessionEvent);
|
|
97
94
|
}
|
|
@@ -99,7 +96,7 @@ module.exports = function (core) {
|
|
|
99
96
|
}
|
|
100
97
|
});
|
|
101
98
|
}
|
|
102
|
-
});
|
|
99
|
+
});
|
|
103
100
|
});
|
|
104
101
|
});
|
|
105
102
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { inspect } = require('util');
|
|
18
|
+
const { patchType } = require('../common');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{
|
|
22
|
+
* assess: import('@contrast/assess').Assess,
|
|
23
|
+
* scopes: import('@contrast/scopes').Scopes,
|
|
24
|
+
* }} core
|
|
25
|
+
*/
|
|
26
|
+
module.exports = function (core) {
|
|
27
|
+
const {
|
|
28
|
+
assess: {
|
|
29
|
+
getSourceContext,
|
|
30
|
+
eventFactory: { createSessionEvent },
|
|
31
|
+
sessionConfiguration: {
|
|
32
|
+
handleHttpOnly,
|
|
33
|
+
handleSecure,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
depHooks,
|
|
37
|
+
patcher,
|
|
38
|
+
} = core;
|
|
39
|
+
|
|
40
|
+
return core.assess.sessionConfiguration.koa = {
|
|
41
|
+
install () {
|
|
42
|
+
depHooks.resolve({ name: 'koa', version: '>=2.3.0' }, (Koa) => {
|
|
43
|
+
patcher.patch(Koa.prototype, 'use', {
|
|
44
|
+
name: 'Koa.Application',
|
|
45
|
+
patchType,
|
|
46
|
+
pre(data) {
|
|
47
|
+
const origCtx = data.args[0];
|
|
48
|
+
data.args[0] = function(...args) {
|
|
49
|
+
patcher.patch(args[0].cookies, 'set', {
|
|
50
|
+
name: 'ctx.cookies',
|
|
51
|
+
patchType,
|
|
52
|
+
pre({ args }) {
|
|
53
|
+
const sourceContext = getSourceContext();
|
|
54
|
+
if (!sourceContext) return;
|
|
55
|
+
|
|
56
|
+
const [name,, options] = args;
|
|
57
|
+
|
|
58
|
+
const httpOnly = options?.httpOnly;
|
|
59
|
+
const secure = options?.secure;
|
|
60
|
+
if (httpOnly && secure) return;
|
|
61
|
+
|
|
62
|
+
const displayArg = inspect(options);
|
|
63
|
+
const sessionEvent = createSessionEvent({
|
|
64
|
+
args: [{
|
|
65
|
+
tracked: false,
|
|
66
|
+
value: displayArg
|
|
67
|
+
}],
|
|
68
|
+
context: `ctx.cookies.set(${displayArg})`,
|
|
69
|
+
history: [],
|
|
70
|
+
name: 'koaCookie',
|
|
71
|
+
moduleName: 'koa',
|
|
72
|
+
methodName: '',
|
|
73
|
+
object: {
|
|
74
|
+
tracked: false,
|
|
75
|
+
value: 'koa',
|
|
76
|
+
},
|
|
77
|
+
result: {
|
|
78
|
+
tracked: false,
|
|
79
|
+
},
|
|
80
|
+
source: 'P',
|
|
81
|
+
stack: [],
|
|
82
|
+
tags: {},
|
|
83
|
+
framework: 'koa',
|
|
84
|
+
});
|
|
85
|
+
if (!httpOnly) {
|
|
86
|
+
handleHttpOnly(sourceContext, name, sessionEvent);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!secure) {
|
|
90
|
+
handleSecure(sourceContext, name, sessionEvent);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return origCtx.apply(this, args);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/assess",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.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)",
|