@contrast/assess 1.28.0 → 1.28.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.
Files changed (52) hide show
  1. package/lib/crypto-analysis/install/crypto.js +1 -1
  2. package/lib/dataflow/propagation/install/JSON/parse.js +2 -2
  3. package/lib/dataflow/propagation/install/JSON/stringify.js +10 -11
  4. package/lib/dataflow/propagation/install/array-prototype-join.js +6 -7
  5. package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -3
  6. package/lib/dataflow/propagation/install/joi/boolean.js +2 -4
  7. package/lib/dataflow/propagation/install/joi/expression.js +2 -4
  8. package/lib/dataflow/propagation/install/joi/index.js +1 -1
  9. package/lib/dataflow/propagation/install/joi/number.js +2 -4
  10. package/lib/dataflow/propagation/install/joi/string-schema.js +8 -3
  11. package/lib/dataflow/propagation/install/joi/values.js +5 -1
  12. package/lib/dataflow/propagation/install/path/format.js +7 -4
  13. package/lib/dataflow/propagation/install/path/parse.js +4 -5
  14. package/lib/dataflow/propagation/install/querystring/escape.js +1 -1
  15. package/lib/dataflow/propagation/install/querystring/parse.js +6 -7
  16. package/lib/dataflow/propagation/install/querystring/stringify.js +1 -1
  17. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +2 -3
  18. package/lib/dataflow/propagation/install/string/concat.js +19 -19
  19. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  20. package/lib/dataflow/propagation/install/string/index.js +3 -3
  21. package/lib/dataflow/propagation/install/string/match-all.js +4 -9
  22. package/lib/dataflow/propagation/install/string/match.js +5 -4
  23. package/lib/dataflow/propagation/install/string/replace.js +18 -12
  24. package/lib/dataflow/propagation/install/string/slice.js +4 -4
  25. package/lib/dataflow/propagation/install/string/split.js +13 -11
  26. package/lib/dataflow/propagation/install/string/substring.js +6 -5
  27. package/lib/dataflow/propagation/install/url/parse.js +1 -1
  28. package/lib/dataflow/propagation/install/url/searchParams.js +2 -1
  29. package/lib/dataflow/propagation/install/url/url.js +1 -1
  30. package/lib/dataflow/sinks/install/child-process.js +1 -1
  31. package/lib/dataflow/sinks/install/express/reflected-xss.js +7 -5
  32. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -2
  33. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -3
  34. package/lib/dataflow/sinks/install/fs.js +1 -1
  35. package/lib/dataflow/sinks/install/function.js +1 -1
  36. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.js +1 -2
  37. package/lib/dataflow/sinks/install/http/request.js +6 -5
  38. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +2 -2
  39. package/lib/dataflow/sinks/install/libxmljs.js +1 -1
  40. package/lib/dataflow/sinks/install/marsdb.js +1 -2
  41. package/lib/dataflow/sinks/install/mongodb.js +1 -1
  42. package/lib/dataflow/sinks/install/mysql.js +1 -1
  43. package/lib/dataflow/sinks/install/postgres.js +1 -3
  44. package/lib/dataflow/sinks/install/sequelize.js +1 -2
  45. package/lib/dataflow/sinks/install/vm.js +1 -1
  46. package/lib/dataflow/tag-utils.js +17 -1
  47. package/lib/index.js +13 -0
  48. package/lib/session-configuration/install/express-session.js +1 -3
  49. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  50. package/lib/session-configuration/install/hapi.js +1 -3
  51. package/lib/session-configuration/install/koa.js +1 -1
  52. package/package.json +1 -1
@@ -13,9 +13,9 @@
13
13
  * way not consistent with the End User License Agreement.
14
14
  */
15
15
  'use strict';
16
- const { inspect, join } = require('@contrast/common');
16
+ const { join } = require('@contrast/common');
17
17
  const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
- const { createSubsetTags } = require('../../../tag-utils');
18
+ const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
19
19
  const { patchType } = require('../../common');
20
20
 
21
21
  module.exports = function(core) {
@@ -72,8 +72,8 @@ module.exports = function(core) {
72
72
  if (!tags) return;
73
73
 
74
74
  const args = origArgs.map((arg) => ({
75
- value: inspect(arg),
76
- tracked: false
75
+ tracked: false,
76
+ value: getAdjustedUntrackedValue(arg)
77
77
  }));
78
78
 
79
79
  const event = createPropagationEvent({
@@ -15,9 +15,9 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { join, inspect } = require('@contrast/common');
18
+ const { join } = require('@contrast/common');
19
19
  const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
- const { createSubsetTags } = require('../../../tag-utils');
20
+ const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
21
21
  const { patchType } = require('../../common');
22
22
 
23
23
  module.exports = function(core) {
@@ -54,17 +54,16 @@ module.exports = function(core) {
54
54
 
55
55
  const args = origArgs.map((arg) => {
56
56
  const argInfo = tracker.getData(arg);
57
- return {
58
- value: argInfo ? argInfo.value : inspect(arg),
59
- tracked: !!argInfo
60
- };
57
+ return argInfo ?
58
+ { tracked: true, value: argInfo.value } :
59
+ { tracked: false, value: `'${arg}'` };
61
60
  });
62
61
 
63
62
  const event = eventFactory.createPropagationEvent({
64
63
  name,
65
64
  moduleName: 'String',
66
65
  methodName: 'prototype.split',
67
- context: `'${objInfo.value}'.split(${join(args.map(a => a.value), ', ')})`,
66
+ context: `'${objInfo.value}'.split(${join(args.map(a => a.value))})`,
68
67
  history: [objInfo],
69
68
  object: {
70
69
  value: obj,
@@ -73,7 +72,7 @@ module.exports = function(core) {
73
72
  args,
74
73
  tags: {},
75
74
  result: {
76
- value: join(result),
75
+ value: getAdjustedUntrackedValue(result),
77
76
  tracked: false
78
77
  },
79
78
  stacktraceOpts: {
@@ -95,9 +94,13 @@ module.exports = function(core) {
95
94
  const objSubstrInfo = tracker.getData(objSubstr);
96
95
  if (objSubstrInfo) {
97
96
  const tags = createSubsetTags(objInfo.tags, start, res.length);
98
- if (!tags) continue;
99
97
 
100
- const metadata = { ...event, tags };
98
+ if (!tags) continue;
99
+ const metadata = {
100
+ ...event,
101
+ result: { tracked: true, value: res },
102
+ tags,
103
+ };
101
104
  eventFactory.createdEvents.add(metadata);
102
105
  const { extern } = tracker.track(res, metadata);
103
106
 
@@ -114,4 +117,3 @@ module.exports = function(core) {
114
117
  },
115
118
  };
116
119
  };
117
-
@@ -15,9 +15,9 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { join, inspect } = require('@contrast/common');
18
+ const { join } = require('@contrast/common');
19
19
  const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
- const { createSubsetTags } = require('../../../tag-utils');
20
+ const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
21
21
  const { patchType } = require('../../common');
22
22
 
23
23
  module.exports = function(core) {
@@ -82,14 +82,15 @@ module.exports = function(core) {
82
82
  if (!tags) return;
83
83
 
84
84
  const args = origArgs.map((arg) => ({
85
- value: inspect(arg),
86
- tracked: false
85
+ tracked: false,
86
+ value: getAdjustedUntrackedValue(arg)
87
87
  }));
88
+
88
89
  const event = createPropagationEvent({
89
90
  name,
90
91
  moduleName: 'String',
91
92
  methodName: 'prototype.substring',
92
- context: `'${objInfo.value}'.substring(${join(args.map(a => a.value), ', ')})`,
93
+ context: `'${objInfo.value}'.substring(${join(args.map(a => a.value))})`,
93
94
  history: [objInfo],
94
95
  object: {
95
96
  value: obj,
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { patchType } = require('../../common');
19
- const { inspect } = require('@contrast/common');
20
19
 
21
20
  module.exports = function(core) {
22
21
  const {
@@ -24,6 +23,7 @@ module.exports = function(core) {
24
23
  patcher,
25
24
  depHooks,
26
25
  assess: {
26
+ inspect, // todo: remove
27
27
  eventFactory: { createPropagationEvent },
28
28
  dataflow: { tracker }
29
29
  }
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const { patchType } = require('../../common');
19
- const { inspect, isString } = require('@contrast/common');
19
+ const { isString } = require('@contrast/common');
20
20
 
21
21
  module.exports = function(core) {
22
22
  const {
@@ -24,6 +24,7 @@ module.exports = function(core) {
24
24
  patcher,
25
25
  depHooks,
26
26
  assess: {
27
+ inspect, // todo: remove
27
28
  eventFactory: { createPropagationEvent },
28
29
  dataflow: { tracker }
29
30
  }
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { inspect } = require('@contrast/common');
19
18
  const { patchType } = require('../../common');
20
19
 
21
20
  module.exports = function(core) {
@@ -24,6 +23,7 @@ module.exports = function(core) {
24
23
  patcher,
25
24
  depHooks,
26
25
  assess: {
26
+ inspect, // todo: remove
27
27
  eventFactory: { createPropagationEvent },
28
28
  dataflow: { tracker }
29
29
  }
@@ -19,7 +19,6 @@ const {
19
19
  join,
20
20
  Rule: { CMD_INJECTION: ruleId },
21
21
  isString,
22
- inspect,
23
22
  } = require('@contrast/common');
24
23
  const { InstrumentationType: { RULE } } = require('../../../constants');
25
24
  const { patchType } = require('../common');
@@ -35,6 +34,7 @@ module.exports = function(core) {
35
34
  depHooks,
36
35
  patcher,
37
36
  assess: {
37
+ inspect, // todo: remove
38
38
  getSourceContext,
39
39
  eventFactory: { createSinkEvent },
40
40
  dataflow: {
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  Rule: { REFLECTED_XSS: ruleId },
21
20
  DataflowTag: {
@@ -52,14 +51,13 @@ module.exports = function(core) {
52
51
  eventFactory: { createSinkEvent },
53
52
  dataflow: {
54
53
  tracker,
55
- sinks: { isVulnerable, reportFindings, reportSafePositive }
54
+ sinks: { isVulnerable, reportFindings, reportSafePositive, isSafeContentType }
56
55
  },
57
56
  ruleScopes,
58
57
  },
59
58
  } = core;
60
59
 
61
60
  const reflectedXss = core.assess.dataflow.sinks.express.reflectedXss = {};
62
- const inspect = patcher.unwrap(util.inspect);
63
61
 
64
62
  const safeTags = [
65
63
  `excluded:${ruleId}`,
@@ -81,7 +79,11 @@ module.exports = function(core) {
81
79
  name,
82
80
  patchType,
83
81
  around: (next, data) => {
84
- if (!getSourceContext(RULE, ruleId)) return next();
82
+ const sourceContext = getSourceContext(RULE, ruleId);
83
+ if (!sourceContext) return next();
84
+
85
+ const { contentType } = sourceContext.responseData;
86
+ if (contentType && isSafeContentType(contentType)) return next();
85
87
 
86
88
  const [str] = data.args;
87
89
 
@@ -96,7 +98,7 @@ module.exports = function(core) {
96
98
  tracked: true,
97
99
  value: strInfo.value,
98
100
  }],
99
- context: `response.${method}(${inspect(strInfo.value)})`,
101
+ context: `response.${method}('${strInfo.value}')`,
100
102
  history: [strInfo],
101
103
  name,
102
104
  moduleName: 'express',
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  Rule: { UNVALIDATED_REDIRECT: ruleId },
21
20
  DataflowTag: {
@@ -46,6 +45,7 @@ module.exports = function(core) {
46
45
  patcher,
47
46
  config,
48
47
  assess: {
48
+ inspect, // todo: remove
49
49
  getSourceContext,
50
50
  eventFactory: { createSinkEvent },
51
51
  dataflow: {
@@ -56,7 +56,6 @@ module.exports = function(core) {
56
56
  } = core;
57
57
 
58
58
  const unvalidatedRedirect = core.assess.dataflow.sinks.express.unvalidatedRedirect = {};
59
- const inspect = patcher.unwrap(util.inspect);
60
59
 
61
60
  const safeTags = [
62
61
  `excluded:${ruleId}`,
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  Rule: { UNVALIDATED_REDIRECT: ruleId },
21
20
  DataflowTag: {
@@ -65,6 +64,7 @@ module.exports = function(core) {
65
64
  depHooks,
66
65
  patcher,
67
66
  assess: {
67
+ inspect, // todo: remove
68
68
  getSourceContext,
69
69
  eventFactory: { createSinkEvent },
70
70
  dataflow: {
@@ -76,8 +76,6 @@ module.exports = function(core) {
76
76
  const unvalidatedRedirect =
77
77
  (core.assess.dataflow.sinks.fastify.unvalidatedRedirect = {});
78
78
 
79
- const inspect = patcher.unwrap(util.inspect);
80
-
81
79
  const safeTags = [
82
80
  `excluded:${ruleId}`,
83
81
  CUSTOM_ENCODED,
@@ -25,7 +25,6 @@ const {
25
25
  },
26
26
  FS_METHODS,
27
27
  Rule: { PATH_TRAVERSAL: ruleId },
28
- inspect,
29
28
  isString,
30
29
  join,
31
30
  } = require('@contrast/common');
@@ -36,6 +35,7 @@ module.exports = function(core) {
36
35
  depHooks,
37
36
  patcher,
38
37
  assess: {
38
+ inspect, // todo: remove
39
39
  getSourceContext,
40
40
  eventFactory: { createSinkEvent },
41
41
  dataflow: {
@@ -17,7 +17,6 @@
17
17
 
18
18
  const {
19
19
  isString,
20
- inspect,
21
20
  join,
22
21
  DataflowTag: {
23
22
  UNTRUSTED,
@@ -47,6 +46,7 @@ module.exports = function (core) {
47
46
  logger,
48
47
  patcher,
49
48
  assess: {
49
+ inspect, // todo: remove
50
50
  getSourceContext,
51
51
  eventFactory: { createSinkEvent },
52
52
  dataflow: {
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  Rule: { UNVALIDATED_REDIRECT: ruleId },
21
20
  DataflowTag: {
@@ -46,6 +45,7 @@ module.exports = function(core) {
46
45
  patcher,
47
46
  config,
48
47
  assess: {
48
+ inspect, // todo: remove
49
49
  getSourceContext,
50
50
  eventFactory: { createSinkEvent },
51
51
  dataflow: {
@@ -56,7 +56,6 @@ module.exports = function(core) {
56
56
  } = core;
57
57
 
58
58
  const unvalidatedRedirect = core.assess.dataflow.sinks.hapi.unvalidatedRedirect = {};
59
- const inspect = patcher.unwrap(util.inspect);
60
59
 
61
60
  const safeTags = [
62
61
  `excluded:${ruleId}`,
@@ -17,7 +17,6 @@
17
17
 
18
18
  const Url = require('url');
19
19
  const {
20
- inspect,
21
20
  isString,
22
21
  DataflowTag: {
23
22
  UNTRUSTED,
@@ -46,6 +45,7 @@ module.exports = function(core) {
46
45
  depHooks,
47
46
  patcher,
48
47
  assess: {
48
+ inspect, // todo: remove
49
49
  getSourceContext,
50
50
  eventFactory: { createSinkEvent },
51
51
  dataflow: {
@@ -104,11 +104,12 @@ module.exports = function(core) {
104
104
  pre(data) {
105
105
  if (!getSourceContext(RULE, ruleId)) return;
106
106
 
107
- const [req] = data.args;
108
- if (!req) return;
107
+ // url <string> |<URL>
108
+ const [urlArg] = data.args;
109
+ if (!urlArg) return;
109
110
 
110
111
  ['host', 'hostname', 'localAddress', 'protocol'].forEach((key) => {
111
- const value = getValueFromReq(req, key);
112
+ const value = getValueFromReq(urlArg, key);
112
113
  if (!value) return;
113
114
 
114
115
  const strInfo = tracker.getData(value);
@@ -116,7 +117,7 @@ module.exports = function(core) {
116
117
 
117
118
  if (containsTrustedLib(strInfo.stack)) return;
118
119
 
119
- const arg0 = isString(req) ? req : inspect(req);
120
+ const arg0 = isString(urlArg) ? urlArg : inspect(urlArg);
120
121
  const idx = arg0.indexOf(value);
121
122
  const urlTags = createAppendTags({}, strInfo.tags, idx);
122
123
 
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  DataflowTag: {
21
20
  UNTRUSTED,
@@ -47,6 +46,7 @@ module.exports = function(core) {
47
46
  patcher,
48
47
  config,
49
48
  assess: {
49
+ inspect, // todo: remove
50
50
  getSourceContext,
51
51
  eventFactory: { createSinkEvent },
52
52
  dataflow: {
@@ -56,7 +56,7 @@ module.exports = function(core) {
56
56
  },
57
57
  } = core;
58
58
 
59
- const inspect = patcher.unwrap(util.inspect);
59
+
60
60
  const safeTags = [
61
61
  `excluded:${ruleId}`,
62
62
  CUSTOM_ENCODED,
@@ -23,7 +23,6 @@ const {
23
23
  ALPHANUM_SPACE_HYPHEN,
24
24
  LIMITED_CHARS,
25
25
  },
26
- inspect
27
26
  } = require('@contrast/common');
28
27
  const { InstrumentationType: { RULE } } = require('../../../constants');
29
28
  const { patchType } = require('../common');
@@ -48,6 +47,7 @@ module.exports = function(core) {
48
47
  depHooks,
49
48
  patcher,
50
49
  assess: {
50
+ inspect, // todo: remove
51
51
  getSourceContext,
52
52
  eventFactory: { createSinkEvent },
53
53
  dataflow: {
@@ -14,7 +14,6 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const util = require('util');
18
17
  const {
19
18
  traverseValues,
20
19
  Rule: { NOSQL_INJECTION_MONGO: ruleId },
@@ -51,6 +50,7 @@ module.exports = function (core) {
51
50
  logger,
52
51
  patcher,
53
52
  assess: {
53
+ inspect, // todo: remove
54
54
  getSourceContext,
55
55
  eventFactory: { createSinkEvent },
56
56
  dataflow: {
@@ -61,7 +61,6 @@ module.exports = function (core) {
61
61
  } = core;
62
62
 
63
63
  const instr = core.assess.dataflow.sinks.marsdb = {};
64
- const inspect = patcher.unwrap(util.inspect);
65
64
 
66
65
  function getVulnerabilityInfo(query) {
67
66
  let vulnInfo = null;
@@ -28,7 +28,6 @@ const {
28
28
  isNonEmptyObject,
29
29
  traverseValues,
30
30
  isString,
31
- inspect
32
31
  } = require('@contrast/common');
33
32
  const { InstrumentationType: { RULE } } = require('../../../constants');
34
33
  const utils = require('../../tag-utils');
@@ -83,6 +82,7 @@ module.exports = function (core) {
83
82
  logger,
84
83
  patcher,
85
84
  assess: {
85
+ inspect, // todo: remove
86
86
  getSourceContext,
87
87
  eventFactory: { createSinkEvent },
88
88
  dataflow: {
@@ -28,7 +28,6 @@ const {
28
28
  UNTRUSTED
29
29
  },
30
30
  isString,
31
- inspect,
32
31
  } = require('@contrast/common');
33
32
  const { InstrumentationType: { RULE } } = require('../../../constants');
34
33
 
@@ -54,6 +53,7 @@ module.exports = function(core) {
54
53
  depHooks,
55
54
  patcher,
56
55
  assess: {
56
+ inspect, // todo: remove
57
57
  getSourceContext,
58
58
  eventFactory: { createSinkEvent },
59
59
  dataflow: {
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  DataflowTag: {
21
20
  CUSTOM_VALIDATED,
@@ -43,6 +42,7 @@ module.exports = function(core) {
43
42
  depHooks,
44
43
  patcher,
45
44
  assess: {
45
+ inspect, // todo: remove
46
46
  getSourceContext,
47
47
  eventFactory: { createSinkEvent },
48
48
  dataflow: {
@@ -60,8 +60,6 @@ module.exports = function(core) {
60
60
  CUSTOM_ENCODED,
61
61
  ];
62
62
 
63
- const inspect = patcher.unwrap(util.inspect);
64
-
65
63
  const postgres = core.assess.dataflow.sinks.postgres = {};
66
64
 
67
65
  const preHook = (methodSignature) => (data) => {
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const util = require('util');
19
18
  const {
20
19
  Rule: { SQL_INJECTION: ruleId },
21
20
  DataflowTag: {
@@ -42,6 +41,7 @@ module.exports = function (core) {
42
41
  patcher,
43
42
  config,
44
43
  assess: {
44
+ inspect, // todo: remove
45
45
  getSourceContext,
46
46
  eventFactory: { createSinkEvent },
47
47
  dataflow: {
@@ -59,7 +59,6 @@ module.exports = function (core) {
59
59
  CUSTOM_ENCODED
60
60
  ];
61
61
  const requiredTag = UNTRUSTED;
62
- const inspect = patcher.unwrap(util.inspect);
63
62
 
64
63
  const sequelize = (core.assess.dataflow.sinks.sequelize = {});
65
64
 
@@ -25,7 +25,6 @@ const {
25
25
  LIMITED_CHARS,
26
26
  },
27
27
  Rule: { UNSAFE_CODE_EXECUTION: ruleId },
28
- inspect,
29
28
  isNonEmptyObject,
30
29
  isString,
31
30
  join,
@@ -56,6 +55,7 @@ module.exports = function (core) {
56
55
  depHooks,
57
56
  patcher,
58
57
  assess: {
58
+ inspect, // todo: remove
59
59
  getSourceContext,
60
60
  eventFactory: { createSinkEvent },
61
61
  dataflow: {
@@ -520,6 +520,21 @@ function createEscapeTagRanges(input, result, tags) {
520
520
  return ret;
521
521
  }
522
522
 
523
+ /**
524
+ * In reporting args, object, and return values, often the exact value isn't important.
525
+ * For untracked values that appear in call contexts it can be enough to just try to
526
+ * report the type of the arg/obj/result.
527
+ * Example: the call
528
+ * http.request('http://tracked-url', { method: 'post' });
529
+ * would have event context string limited to
530
+ * http.request('http://tracked-url,Object);
531
+ *
532
+ * @param {any} origValue value of event result, object, or arg
533
+ * @returns {string} the adjusted value for reporting
534
+ */
535
+ function getAdjustedUntrackedValue(origValue) {
536
+ return origValue?.constructor?.name ?? (origValue === null ? 'null' : typeof arg);
537
+ }
523
538
 
524
539
  module.exports = {
525
540
  createSubsetTags,
@@ -529,5 +544,6 @@ module.exports = {
529
544
  createTagsWithExclusion,
530
545
  createAdjustedQueryTags,
531
546
  createOverlappingTags,
532
- createEscapeTagRanges
547
+ createEscapeTagRanges,
548
+ getAdjustedUntrackedValue,
533
549
  };
package/lib/index.js CHANGED
@@ -15,9 +15,12 @@
15
15
 
16
16
  'use strict';
17
17
 
18
+ const { inspect } = require('util');
18
19
  const { callChildComponentMethodsSync } = require('@contrast/common');
19
20
 
20
21
  module.exports = function assess(core) {
22
+ const { scopes: { instrumentation } } = core;
23
+
21
24
  const assess = core.assess = {
22
25
  install() {
23
26
  if (!core.config.getEffectiveValue('assess.enable')) {
@@ -30,6 +33,16 @@ module.exports = function assess(core) {
30
33
  },
31
34
  };
32
35
 
36
+ // todo: this is temporary fix for using inspect during creation of event
37
+ // data. once all uses of inspect are refactored out of remaining sinks and
38
+ // propagators etc, this can also be removed.
39
+ const store = { lock: true, name: 'assess.inspect' };
40
+ assess.inspect = function(val, opts) {
41
+ return instrumentation.isLocked() ?
42
+ inspect(val, opts) :
43
+ instrumentation.run(store, inspect, val, opts);
44
+ };
45
+
33
46
  require('./rule-scopes')(core);
34
47
  require('./get-policy')(core);
35
48
  require('./make-source-context')(core);
@@ -14,7 +14,6 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const util = require('util');
18
17
  const { toLowerCase } = require('@contrast/common');
19
18
  const { patchType } = require('../common');
20
19
 
@@ -27,6 +26,7 @@ const { patchType } = require('../common');
27
26
  module.exports = function (core) {
28
27
  const {
29
28
  assess: {
29
+ inspect, // todo: remove
30
30
  getSourceContext,
31
31
  eventFactory: { createSessionEvent },
32
32
  sessionConfiguration: {
@@ -40,8 +40,6 @@ module.exports = function (core) {
40
40
 
41
41
  const expressSession = core.assess.sessionConfiguration.expressSession = {};
42
42
 
43
- const inspect = patcher.unwrap(util.inspect);
44
-
45
43
  expressSession.install = function () {
46
44
  return depHooks.resolve({ name: 'express-session' }, (session) => {
47
45
  // Return the hooked function as the export.
@@ -14,7 +14,6 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { inspect } = require('util');
18
17
  const { toLowerCase } = require('@contrast/common');
19
18
  const { patchType } = require('../common');
20
19
 
@@ -27,6 +26,7 @@ const { patchType } = require('../common');
27
26
  module.exports = function (core) {
28
27
  const {
29
28
  assess: {
29
+ inspect, // todo: remove
30
30
  getSourceContext,
31
31
  eventFactory: { createSessionEvent },
32
32
  sessionConfiguration: {
@@ -14,12 +14,12 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const util = require('util');
18
17
  const { patchType } = require('../common');
19
18
 
20
19
  module.exports = function (core) {
21
20
  const {
22
21
  assess: {
22
+ inspect, // todo: remove
23
23
  eventFactory: { createSessionEvent },
24
24
  sessionConfiguration: {
25
25
  handleHttpOnly,
@@ -33,8 +33,6 @@ module.exports = function (core) {
33
33
 
34
34
  const hapiSession = core.assess.sessionConfiguration.hapiSession = {};
35
35
 
36
- const inspect = patcher.unwrap(util.inspect);
37
-
38
36
  hapiSession.install = function () {
39
37
  return depHooks.resolve({ name: '@hapi/hapi', version: '>=18 <22' }, (hapi) => {
40
38
  ['server', 'Server'].forEach((server) => {