@contrast/assess 1.19.0 → 1.20.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/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 +2 -2
- 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 +35 -33
- 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
|
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
const { InputType } = require('@contrast/common');
|
|
19
19
|
const { patchType } = require('../../common');
|
|
20
20
|
|
|
21
|
+
const inputType = InputType.QUERYSTRING;
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* Function that exports an install method to patch Koa framework with our instrumentation
|
|
23
25
|
* @param {Object} core - the core Contrast object in v5
|
|
@@ -36,58 +38,60 @@ module.exports = (core) => {
|
|
|
36
38
|
*/
|
|
37
39
|
function install() {
|
|
38
40
|
depHooks.resolve({ name: 'koa', version: '>=2.3.0' }, (Koa) => {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const inputType = InputType.QUERYSTRING;
|
|
41
|
+
const createMiddleware = ({ name, funcKey }) => {
|
|
42
|
+
const contrastStartMiddleware = function contrastStartMiddleware(ctx, next) {
|
|
43
|
+
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return next();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// We check the contents mainly to trigger the getter for `ctx.query`
|
|
50
|
-
// that is eventually set up by `koa-qs`
|
|
51
|
-
if (ctx.query) {
|
|
52
|
-
if (sourceContext.parsedQuery) {
|
|
53
|
-
logger.trace({ name, inputType }, 'values already tracked');
|
|
45
|
+
if (!sourceContext) {
|
|
46
|
+
logger.error({ inputType, funcKey }, 'unable to handle Koa source. Missing `sourceContext`');
|
|
54
47
|
return next();
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
inputType,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
// We check the contents mainly to trigger the getter for `ctx.query`
|
|
51
|
+
// that is eventually set up by `koa-qs`
|
|
52
|
+
if (ctx.query) {
|
|
53
|
+
if (sourceContext.parsedQuery) {
|
|
54
|
+
logger.trace({ inputType, funcKey }, 'values already tracked');
|
|
55
|
+
return next();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
sources.handle({
|
|
60
|
+
context: 'ctx.query',
|
|
61
|
+
data: ctx.query,
|
|
62
|
+
inputType,
|
|
63
|
+
name,
|
|
64
|
+
stacktraceOpts: {
|
|
65
|
+
constructorOpt: contrastStartMiddleware,
|
|
66
|
+
},
|
|
67
|
+
sourceContext
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
sourceContext.parsedQuery = true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
logger.error({ err, inputType, funcKey }, 'unable to handle Koa source');
|
|
73
|
+
}
|
|
72
74
|
}
|
|
73
|
-
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
return next();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// mark these middleware as ours
|
|
80
|
+
contrastStartMiddleware._isContrastStartMiddleware = true;
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
return contrastStartMiddleware;
|
|
83
|
+
};
|
|
80
84
|
|
|
81
85
|
patcher.patch(Koa.prototype, 'use', {
|
|
82
86
|
name: 'Koa.Application',
|
|
83
87
|
patchType,
|
|
84
|
-
pre({ obj: app }) {
|
|
88
|
+
pre({ obj: app, name, funcKey }) {
|
|
85
89
|
// if not already inserted, insert the initial middleware.
|
|
86
90
|
if (
|
|
87
91
|
app.middleware &&
|
|
88
|
-
|
|
92
|
+
(!app.middleware[0] || !app.middleware[0]._isContrastStartMiddleware)
|
|
89
93
|
) {
|
|
90
|
-
app.middleware.
|
|
94
|
+
app.middleware.unshift(createMiddleware({ name, funcKey }));
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
});
|
|
@@ -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
|
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
const { InputType } = require('@contrast/common');
|
|
19
19
|
const { patchType } = require('../common');
|
|
20
20
|
|
|
21
|
+
const inputType = InputType.QUERYSTRING;
|
|
22
|
+
|
|
21
23
|
module.exports = (core) => {
|
|
22
24
|
const {
|
|
23
25
|
depHooks,
|
|
@@ -33,17 +35,16 @@ module.exports = (core) => {
|
|
|
33
35
|
(qs) => patcher.patch(qs, 'parse', {
|
|
34
36
|
name,
|
|
35
37
|
patchType,
|
|
36
|
-
post({ args, hooked, orig, result }) {
|
|
38
|
+
post({ args, hooked, orig, result, funcKey }) {
|
|
37
39
|
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
38
|
-
const inputType = InputType.QUERYSTRING;
|
|
39
40
|
|
|
40
41
|
if (!sourceContext) {
|
|
41
|
-
logger.error({ inputType,
|
|
42
|
+
logger.error({ inputType, funcKey }, 'unable to handle source. Missing `sourceContext`');
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (sourceContext.parsedQuery) {
|
|
46
|
-
logger.trace({ inputType,
|
|
47
|
+
logger.trace({ inputType, funcKey }, 'values already tracked');
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -67,7 +68,7 @@ module.exports = (core) => {
|
|
|
67
68
|
|
|
68
69
|
sourceContext.parsedQuery = true;
|
|
69
70
|
} catch (err) {
|
|
70
|
-
logger.error({ err, inputType,
|
|
71
|
+
logger.error({ err, inputType, funcKey }, 'unable to handle source');
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -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
|
|
|
@@ -28,14 +28,14 @@ module.exports = (core) => {
|
|
|
28
28
|
(querystring) => patcher.patch(querystring, 'parse', {
|
|
29
29
|
name,
|
|
30
30
|
patchType,
|
|
31
|
-
post({ args, hooked, orig, result }) {
|
|
31
|
+
post({ args, hooked, orig, result, funcKey }) {
|
|
32
32
|
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
33
33
|
const inputType = InputType.QUERYSTRING;
|
|
34
34
|
|
|
35
35
|
if (!sourceContext) return;
|
|
36
36
|
|
|
37
37
|
if (sourceContext.parsedQuery) {
|
|
38
|
-
logger.trace({
|
|
38
|
+
logger.trace({ funcKey }, 'values already tracked');
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -58,7 +58,7 @@ module.exports = (core) => {
|
|
|
58
58
|
// we do not set the `parsedQuery` value here so that frameworks
|
|
59
59
|
// may handle queries in their own more specific manner.
|
|
60
60
|
} catch (err) {
|
|
61
|
-
logger.error({ err,
|
|
61
|
+
logger.error({ err, funcKey }, 'unable to handle source');
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
package/lib/dataflow/tracker.js
CHANGED
package/lib/event-factory.js
CHANGED
|
@@ -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
|
|
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const { InputType, match } = require('@contrast/common');
|
|
19
|
-
const
|
|
19
|
+
const ANNOTATION_REGEX = /^(A|O|R|P|P\d+)$/;
|
|
20
|
+
const SOURCE_EVENT_MSG = 'Source event not created: %s';
|
|
21
|
+
const PROPAGATION_EVENT_MSG = 'Propagation event not created: %s';
|
|
20
22
|
|
|
21
|
-
module.exports = function(core) {
|
|
23
|
+
module.exports = function (core) {
|
|
22
24
|
const {
|
|
23
25
|
createSnapshot,
|
|
24
26
|
config,
|
|
@@ -30,7 +32,7 @@ module.exports = function(core) {
|
|
|
30
32
|
|
|
31
33
|
eventFactory.createdEvents = new WeakSet();
|
|
32
34
|
|
|
33
|
-
eventFactory.createSourceEvent = function(data = {}) {
|
|
35
|
+
eventFactory.createSourceEvent = function (data = {}) {
|
|
34
36
|
const {
|
|
35
37
|
name,
|
|
36
38
|
result = { value: null, tracked: false },
|
|
@@ -39,31 +41,29 @@ module.exports = function(core) {
|
|
|
39
41
|
stack,
|
|
40
42
|
} = data;
|
|
41
43
|
|
|
42
|
-
const baseMessage = 'Source event not created: %s';
|
|
43
|
-
|
|
44
44
|
if (!result.value) {
|
|
45
|
-
logger.debug({
|
|
45
|
+
logger.debug({ name }, SOURCE_EVENT_MSG, 'invalid result');
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
if (!name) {
|
|
50
|
-
logger.debug({
|
|
50
|
+
logger.debug({ name }, SOURCE_EVENT_MSG, 'invalid name');
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (!(inputType in InputType)) {
|
|
55
|
-
logger.debug({
|
|
55
|
+
logger.debug({ name }, SOURCE_EVENT_MSG, 'invalid inputType');
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (!tags) {
|
|
60
|
-
logger.debug({
|
|
60
|
+
logger.debug({ name }, SOURCE_EVENT_MSG, 'event has no tags');
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
if (!stack || !Array.isArray(stack)) {
|
|
66
|
-
logger.debug({
|
|
66
|
+
logger.debug({ name }, SOURCE_EVENT_MSG, 'invalid stack');
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -73,7 +73,7 @@ module.exports = function(core) {
|
|
|
73
73
|
return data;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
eventFactory.createPropagationEvent = function(data) {
|
|
76
|
+
eventFactory.createPropagationEvent = function (data) {
|
|
77
77
|
const {
|
|
78
78
|
name = '',
|
|
79
79
|
moduleName,
|
|
@@ -104,20 +104,22 @@ module.exports = function(core) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (!name) {
|
|
107
|
-
logger.debug({ name }, '
|
|
107
|
+
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid name');
|
|
108
108
|
return null;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (!history.length) {
|
|
112
|
-
logger.debug({ name
|
|
112
|
+
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid history');
|
|
113
113
|
return null;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
if (
|
|
117
|
-
(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
if (!source || !match(source, ANNOTATION_REGEX)) {
|
|
117
|
+
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid source');
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!target || !match(target, ANNOTATION_REGEX)) {
|
|
122
|
+
logger.debug({ name }, PROPAGATION_EVENT_MSG, 'invalid target');
|
|
121
123
|
return null;
|
|
122
124
|
}
|
|
123
125
|
|
|
@@ -152,7 +154,7 @@ module.exports = function(core) {
|
|
|
152
154
|
return event;
|
|
153
155
|
};
|
|
154
156
|
|
|
155
|
-
eventFactory.createSinkEvent = function(data) {
|
|
157
|
+
eventFactory.createSinkEvent = function (data) {
|
|
156
158
|
const {
|
|
157
159
|
context,
|
|
158
160
|
name = '',
|
|
@@ -169,21 +171,21 @@ module.exports = function(core) {
|
|
|
169
171
|
|
|
170
172
|
const sourceContext = sources.getStore()?.assess;
|
|
171
173
|
if (!sourceContext) {
|
|
172
|
-
logger.debug('no sourceContext found during sink event creation');
|
|
174
|
+
logger.debug({ name }, 'no sourceContext found during sink event creation');
|
|
173
175
|
return null;
|
|
174
176
|
}
|
|
175
177
|
if (!name) {
|
|
176
|
-
logger.debug({
|
|
178
|
+
logger.debug({ name }, 'no sink event name');
|
|
177
179
|
return null;
|
|
178
180
|
}
|
|
179
181
|
if (!history.length) {
|
|
180
|
-
logger.debug({
|
|
182
|
+
logger.debug({ name }, 'empty history for sink event');
|
|
181
183
|
return null;
|
|
182
184
|
}
|
|
183
185
|
if (
|
|
184
|
-
(!source || !source.match(
|
|
186
|
+
(!source || !source.match(ANNOTATION_REGEX))
|
|
185
187
|
) {
|
|
186
|
-
logger.debug({
|
|
188
|
+
logger.debug({ name }, 'malformed or missing sink event source field');
|
|
187
189
|
return null;
|
|
188
190
|
}
|
|
189
191
|
|
|
@@ -214,7 +216,7 @@ module.exports = function(core) {
|
|
|
214
216
|
return event;
|
|
215
217
|
};
|
|
216
218
|
|
|
217
|
-
eventFactory.createSessionEvent = function(data) {
|
|
219
|
+
eventFactory.createSessionEvent = function (data) {
|
|
218
220
|
const {
|
|
219
221
|
context,
|
|
220
222
|
name = '',
|
|
@@ -230,14 +232,14 @@ module.exports = function(core) {
|
|
|
230
232
|
} = data;
|
|
231
233
|
|
|
232
234
|
if (!name) {
|
|
233
|
-
logger.debug({
|
|
235
|
+
logger.debug({ name }, 'no sink event name');
|
|
234
236
|
return null;
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
if (
|
|
238
|
-
(!source || !source.match(
|
|
240
|
+
(!source || !source.match(ANNOTATION_REGEX))
|
|
239
241
|
) {
|
|
240
|
-
logger.debug({
|
|
242
|
+
logger.debug({ name }, 'malformed or missing sink event source field');
|
|
241
243
|
return null;
|
|
242
244
|
}
|
|
243
245
|
|
|
@@ -285,7 +287,7 @@ module.exports = function(core) {
|
|
|
285
287
|
* }} data
|
|
286
288
|
* @returns {any}
|
|
287
289
|
*/
|
|
288
|
-
eventFactory.createCryptoAnalysisEvent = function(data) {
|
|
290
|
+
eventFactory.createCryptoAnalysisEvent = function (data) {
|
|
289
291
|
const {
|
|
290
292
|
name = '',
|
|
291
293
|
source,
|
|
@@ -293,12 +295,12 @@ module.exports = function(core) {
|
|
|
293
295
|
} = data;
|
|
294
296
|
|
|
295
297
|
if (!name) {
|
|
296
|
-
logger.debug({
|
|
298
|
+
logger.debug({ name }, 'no sink event name');
|
|
297
299
|
return null;
|
|
298
300
|
}
|
|
299
301
|
|
|
300
|
-
if (!source || !source.match(
|
|
301
|
-
logger.debug({
|
|
302
|
+
if (!source || !source.match(ANNOTATION_REGEX)) {
|
|
303
|
+
logger.debug({ name }, 'malformed or missing sink event source field');
|
|
302
304
|
return null;
|
|
303
305
|
}
|
|
304
306
|
|
package/lib/get-policy.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -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
|
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
* way not consistent with the End User License Agreement.
|
|
14
14
|
*/
|
|
15
15
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
Rule,
|
|
18
|
+
SessionConfigurationRule,
|
|
19
|
+
} from '@contrast/common';
|
|
17
20
|
|
|
18
21
|
export enum InstrumentationType {
|
|
19
22
|
SOURCE = 'source',
|
|
@@ -40,11 +43,22 @@ export interface RuleScopes {
|
|
|
40
43
|
isLocked(ruleId: Rule): boolean;
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
export interface SessionRuleState {
|
|
47
|
+
reported: boolean,
|
|
48
|
+
valuesAnalyzed: Set<string>,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RuleState {
|
|
52
|
+
[SessionConfigurationRule.HTTPONLY]?: SessionRuleState,
|
|
53
|
+
[SessionConfigurationRule.SECURE_FLAG_MISSING]?: SessionRuleState,
|
|
54
|
+
}
|
|
55
|
+
|
|
43
56
|
export interface Assess {
|
|
44
57
|
getPolicy(): Policy,
|
|
45
58
|
getSourceContext(instrType?: InstrumentationType, opts?: any): SourceContext,
|
|
46
59
|
makeSourceContext(req: IncomingMessage, res: ServerResponse): SourceContext,
|
|
47
60
|
ruleScopes: RuleScopes,
|
|
61
|
+
ruleState: RuleState,
|
|
48
62
|
}
|
|
49
63
|
|
|
50
64
|
export function getSourceContext(instrType?: InstrumentationType, ops?: any): SourceContext;
|
package/lib/index.js
CHANGED
|
@@ -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
|
|
|
@@ -29,6 +29,9 @@ module.exports = function(core) {
|
|
|
29
29
|
logger,
|
|
30
30
|
} = core;
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @returns {import('@contrast/assess').SourceContext}
|
|
34
|
+
*/
|
|
32
35
|
return core.assess.makeSourceContext = function (req, res) {
|
|
33
36
|
let contentType, queries, uriPath;
|
|
34
37
|
|
|
@@ -61,7 +64,8 @@ module.exports = function(core) {
|
|
|
61
64
|
queries,
|
|
62
65
|
contentType,
|
|
63
66
|
},
|
|
64
|
-
responseData: {}
|
|
67
|
+
responseData: {},
|
|
68
|
+
ruleState: {},
|
|
65
69
|
};
|
|
66
70
|
} catch (err) {
|
|
67
71
|
logger.error(
|
package/lib/rule-scopes.js
CHANGED