@contrast/assess 1.34.0 → 1.36.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.
Files changed (171) hide show
  1. package/lib/crypto-analysis/install/crypto.js +1 -1
  2. package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
  3. package/lib/dataflow/propagation/install/JSON/parse.js +3 -2
  4. package/lib/dataflow/propagation/install/JSON/parse.test.js +2 -2
  5. package/lib/dataflow/propagation/install/JSON/stringify.js +11 -10
  6. package/lib/dataflow/propagation/install/JSON/stringify.test.js +3 -3
  7. package/lib/dataflow/propagation/install/array-prototype-join.js +4 -3
  8. package/lib/dataflow/propagation/install/array-prototype-join.test.js +3 -3
  9. package/lib/dataflow/propagation/install/buffer.js +2 -3
  10. package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +2 -2
  11. package/lib/dataflow/propagation/install/decode-uri-component.js +5 -8
  12. package/lib/dataflow/propagation/install/decode-uri-component.test.js +1 -1
  13. package/lib/dataflow/propagation/install/ejs/escape-xml.js +6 -9
  14. package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +2 -2
  15. package/lib/dataflow/propagation/install/ejs/template.js +2 -2
  16. package/lib/dataflow/propagation/install/encode-uri.js +4 -6
  17. package/lib/dataflow/propagation/install/encode-uri.test.js +2 -2
  18. package/lib/dataflow/propagation/install/escape-html.js +5 -8
  19. package/lib/dataflow/propagation/install/escape-html.test.js +3 -3
  20. package/lib/dataflow/propagation/install/escape.js +5 -8
  21. package/lib/dataflow/propagation/install/escape.test.js +2 -2
  22. package/lib/dataflow/propagation/install/fastify-send.js +3 -5
  23. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +6 -9
  24. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +1 -1
  25. package/lib/dataflow/propagation/install/joi/boolean.js +50 -52
  26. package/lib/dataflow/propagation/install/joi/expression.js +3 -10
  27. package/lib/dataflow/propagation/install/joi/index.js +98 -101
  28. package/lib/dataflow/propagation/install/joi/keys.js +10 -5
  29. package/lib/dataflow/propagation/install/joi/number.js +50 -52
  30. package/lib/dataflow/propagation/install/joi/string-schema.js +9 -14
  31. package/lib/dataflow/propagation/install/joi/utils.js +7 -4
  32. package/lib/dataflow/propagation/install/joi/values.js +5 -7
  33. package/lib/dataflow/propagation/install/mongoose/schema-map.js +5 -4
  34. package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +4 -4
  35. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +5 -4
  36. package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +4 -5
  37. package/lib/dataflow/propagation/install/mongoose/schema-string.js +3 -4
  38. package/lib/dataflow/propagation/install/mustache-escape.js +5 -8
  39. package/lib/dataflow/propagation/install/mustache-escape.test.js +2 -2
  40. package/lib/dataflow/propagation/install/mysql-connection-escape.js +5 -8
  41. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +2 -2
  42. package/lib/dataflow/propagation/install/parse-int.js +3 -3
  43. package/lib/dataflow/propagation/install/path/basename.js +7 -12
  44. package/lib/dataflow/propagation/install/path/basename.test.js +2 -2
  45. package/lib/dataflow/propagation/install/path/common.js +2 -2
  46. package/lib/dataflow/propagation/install/path/dirname.js +5 -10
  47. package/lib/dataflow/propagation/install/path/dirname.test.js +2 -2
  48. package/lib/dataflow/propagation/install/path/extname.js +6 -11
  49. package/lib/dataflow/propagation/install/path/extname.test.js +2 -2
  50. package/lib/dataflow/propagation/install/path/format.js +7 -13
  51. package/lib/dataflow/propagation/install/path/format.test.js +2 -2
  52. package/lib/dataflow/propagation/install/path/join-and-resolve.js +7 -12
  53. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +2 -2
  54. package/lib/dataflow/propagation/install/path/normalize.js +4 -11
  55. package/lib/dataflow/propagation/install/path/normalize.test.js +2 -2
  56. package/lib/dataflow/propagation/install/path/parse.js +3 -8
  57. package/lib/dataflow/propagation/install/path/parse.test.js +2 -2
  58. package/lib/dataflow/propagation/install/path/relative.js +5 -11
  59. package/lib/dataflow/propagation/install/path/relative.test.js +2 -2
  60. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +5 -11
  61. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +2 -2
  62. package/lib/dataflow/propagation/install/pug/index.js +8 -3
  63. package/lib/dataflow/propagation/install/pug-runtime-escape.js +5 -8
  64. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +1 -1
  65. package/lib/dataflow/propagation/install/querystring/escape.js +3 -3
  66. package/lib/dataflow/propagation/install/querystring/parse.js +7 -11
  67. package/lib/dataflow/propagation/install/querystring/stringify.js +3 -3
  68. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +4 -3
  69. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +5 -3
  70. package/lib/dataflow/propagation/install/send.js +5 -10
  71. package/lib/dataflow/propagation/install/sequelize/query-generator.js +3 -4
  72. package/lib/dataflow/propagation/install/sequelize/sql-string.js +8 -12
  73. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +2 -13
  74. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -5
  75. package/lib/dataflow/propagation/install/sql-template-strings.test.js +2 -2
  76. package/lib/dataflow/propagation/install/string/concat.js +2 -1
  77. package/lib/dataflow/propagation/install/string/concat.test.js +15 -2
  78. package/lib/dataflow/propagation/install/string/format-methods.js +4 -2
  79. package/lib/dataflow/propagation/install/string/format-methods.test.js +15 -2
  80. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  81. package/lib/dataflow/propagation/install/string/html-methods.test.js +15 -2
  82. package/lib/dataflow/propagation/install/string/index.js +2 -2
  83. package/lib/dataflow/propagation/install/string/match-all.js +2 -1
  84. package/lib/dataflow/propagation/install/string/match-all.test.js +13 -0
  85. package/lib/dataflow/propagation/install/string/match.js +11 -10
  86. package/lib/dataflow/propagation/install/string/match.test.js +13 -0
  87. package/lib/dataflow/propagation/install/string/replace.js +15 -9
  88. package/lib/dataflow/propagation/install/string/replace.test.js +13 -0
  89. package/lib/dataflow/propagation/install/string/slice.js +2 -1
  90. package/lib/dataflow/propagation/install/string/slice.test.js +13 -0
  91. package/lib/dataflow/propagation/install/string/split.js +2 -1
  92. package/lib/dataflow/propagation/install/string/split.test.js +13 -0
  93. package/lib/dataflow/propagation/install/string/substring.js +2 -1
  94. package/lib/dataflow/propagation/install/string/substring.test.js +13 -0
  95. package/lib/dataflow/propagation/install/string/trim.js +4 -1
  96. package/lib/dataflow/propagation/install/string/trim.test.js +13 -0
  97. package/lib/dataflow/propagation/install/unescape.js +5 -8
  98. package/lib/dataflow/propagation/install/unescape.test.js +2 -2
  99. package/lib/dataflow/propagation/install/url/domain-parsers.js +4 -5
  100. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +2 -2
  101. package/lib/dataflow/propagation/install/url/parse.js +3 -2
  102. package/lib/dataflow/propagation/install/url/parse.test.js +2 -2
  103. package/lib/dataflow/propagation/install/url/searchParams.js +5 -5
  104. package/lib/dataflow/propagation/install/url/searchParams.test.js +2 -2
  105. package/lib/dataflow/propagation/install/url/url.js +6 -3
  106. package/lib/dataflow/propagation/install/url/url.test.js +2 -2
  107. package/lib/dataflow/propagation/install/util-format.js +7 -6
  108. package/lib/dataflow/propagation/install/util-format.test.js +2 -2
  109. package/lib/dataflow/propagation/install/validator/hooks.js +7 -2
  110. package/lib/dataflow/sinks/install/child-process.js +1 -1
  111. package/lib/dataflow/sinks/install/child-process.test.js +1 -1
  112. package/lib/dataflow/sinks/install/fs.js +1 -1
  113. package/lib/dataflow/sinks/install/fs.test.js +1 -1
  114. package/lib/dataflow/sinks/install/function.js +1 -1
  115. package/lib/dataflow/sinks/install/http/request.js +2 -1
  116. package/lib/dataflow/sinks/install/http/request.test.js +1 -1
  117. package/lib/dataflow/sinks/install/http/server-response.test.js +3 -5
  118. package/lib/dataflow/sinks/install/restify.js +1 -1
  119. package/lib/dataflow/sinks/install/vm.js +4 -2
  120. package/lib/dataflow/sinks/install/vm.test.js +1 -1
  121. package/lib/dataflow/sources/handler.js +6 -3
  122. package/lib/dataflow/sources/handler.test.js +38 -0
  123. package/lib/dataflow/sources/install/body-parser1.test.js +4 -4
  124. package/lib/dataflow/sources/install/busboy.js +8 -3
  125. package/lib/dataflow/sources/install/busboy.test.js +2 -2
  126. package/lib/dataflow/sources/install/cookie-parser1.test.js +2 -2
  127. package/lib/dataflow/sources/install/express/params.js +14 -11
  128. package/lib/dataflow/sources/install/express/params.test.js +5 -7
  129. package/lib/dataflow/sources/install/express/parsedUrl.js +3 -2
  130. package/lib/dataflow/sources/install/fastify/fastify.js +7 -6
  131. package/lib/dataflow/sources/install/fastify/fastify.test.js +2 -2
  132. package/lib/dataflow/sources/install/formidable1.js +7 -6
  133. package/lib/dataflow/sources/install/formidable1.test.js +2 -2
  134. package/lib/dataflow/sources/install/hapi/hapi.js +8 -10
  135. package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -1
  136. package/lib/dataflow/sources/install/http.js +20 -16
  137. package/lib/dataflow/sources/install/http.test.js +28 -34
  138. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +7 -7
  139. package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +3 -4
  140. package/lib/dataflow/sources/install/koa/koa-multer.js +8 -4
  141. package/lib/dataflow/sources/install/koa/koa-routers.js +7 -6
  142. package/lib/dataflow/sources/install/koa/koa-routers.test.js +2 -2
  143. package/lib/dataflow/sources/install/koa/koa2.js +7 -3
  144. package/lib/dataflow/sources/install/koa/koa2.test.js +1 -1
  145. package/lib/dataflow/sources/install/multer1.js +6 -2
  146. package/lib/dataflow/sources/install/qs6.js +1 -1
  147. package/lib/dataflow/sources/install/querystring.js +1 -1
  148. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +1 -4
  149. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +6 -8
  150. package/lib/dataflow/sources/install/restify/jsonBodyParser.js +0 -1
  151. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +4 -8
  152. package/lib/dataflow/sources/install/restify/router.test.js +2 -2
  153. package/lib/dataflow/tag-utils.js +1 -1
  154. package/lib/dataflow/tracker.js +1 -1
  155. package/lib/dataflow/utils/is-safe-content-type.js +3 -2
  156. package/lib/event-factory.js +4 -4
  157. package/lib/event-factory.test.js +19 -14
  158. package/lib/get-policy.js +2 -2
  159. package/lib/index.d.ts +11 -6
  160. package/lib/index.js +18 -7
  161. package/lib/index.test.js +4 -0
  162. package/lib/make-source-context.js +37 -28
  163. package/lib/make-source-context.test.js +7 -7
  164. package/lib/response-scanning/handlers/index.js +7 -5
  165. package/lib/response-scanning/handlers/utils.js +11 -8
  166. package/lib/response-scanning/install/http.js +1 -1
  167. package/lib/sampler.js +136 -0
  168. package/lib/sampler.test.js +296 -0
  169. package/lib/session-configuration/install/express-session.js +1 -1
  170. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  171. package/package.json +10 -10
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const {
19
- isNonEmptyObject, isString, traverseValues, ArrayPrototypeJoin
19
+ isNonEmptyObject, isString, traverseValues, primordials: { ArrayPrototypeJoin }
20
20
  } = require('@contrast/common');
21
21
  const { createMergedTags } = require('../../../tag-utils');
22
22
  const { patchType } = require('../../common');
@@ -24,9 +24,9 @@ const { patchType } = require('../../common');
24
24
  module.exports = function(core) {
25
25
  const {
26
26
  depHooks,
27
- scopes: { sources, instrumentation },
28
27
  patcher,
29
28
  assess: {
29
+ getSourceContext,
30
30
  inspect, // todo: remove
31
31
  eventFactory: { createPropagationEvent },
32
32
  dataflow: { tracker },
@@ -46,8 +46,7 @@ module.exports = function(core) {
46
46
  if (
47
47
  !value ||
48
48
  !result ||
49
- !sources.getStore()?.assess ||
50
- instrumentation.isLocked()
49
+ !getSourceContext()
51
50
  ) return;
52
51
 
53
52
  const metadata = {
@@ -56,7 +55,6 @@ module.exports = function(core) {
56
55
  orig: data.orig
57
56
  };
58
57
 
59
-
60
58
  if (result.ref) {
61
59
  const targetAbsolutePath = ArrayPrototypeJoin.call(result.ref.absolute(state), '.');
62
60
 
@@ -143,13 +141,13 @@ module.exports = function(core) {
143
141
  }
144
142
  }
145
143
 
146
- return (core.assess.dataflow.propagation.joiInstrumentation.values = {
144
+ return core.assess.dataflow.propagation.joiInstrumentation.values = {
147
145
  install() {
148
146
  depHooks.resolve(
149
147
  { name: 'joi', file: 'lib/values.js', version: '>=17.0.0' },
150
148
  instrumentJoiValues
151
149
  );
152
150
  },
153
- });
151
+ };
154
152
  };
155
153
 
@@ -13,17 +13,18 @@
13
13
  * way not consistent with the End User License Agreement.
14
14
  */
15
15
  'use strict';
16
+
17
+ const { traverseValues, DataflowTag, primordials: { StringPrototypeSubstring } } = require('@contrast/common');
16
18
  const { patchType } = require('../../common');
17
19
  const { userDefinedType } = require('./common');
18
- const { traverseValues, DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
19
20
 
20
21
  module.exports = function (core) {
21
22
  const {
22
23
  config: { assess },
23
- scopes: { sources },
24
24
  patcher,
25
25
  depHooks,
26
26
  assess: {
27
+ getSourceContext,
27
28
  eventFactory: { createPropagationEvent },
28
29
  dataflow: {
29
30
  tracker,
@@ -107,7 +108,7 @@ module.exports = function (core) {
107
108
  name: doValidateSyncName,
108
109
  patchType,
109
110
  post: (data) => {
110
- if (!assess.trust_custom_validators || data.result || !sources.getStore()?.assess) return;
111
+ if (!assess.trust_custom_validators || data.result || !getSourceContext()) return;
111
112
 
112
113
  mapInstrumentation(data, doValidateSyncName);
113
114
  },
@@ -125,7 +126,7 @@ module.exports = function (core) {
125
126
  if (
126
127
  !value ||
127
128
  typeof cb !== 'function' ||
128
- !sources.getStore()?.assess
129
+ !getSourceContext()
129
130
  ) {
130
131
  return;
131
132
  }
@@ -107,7 +107,7 @@ describe('assess dataflow propagation mongoose.MapSchema', function () {
107
107
  });
108
108
  });
109
109
 
110
- it('SchemaMap.doValidateSync skip instrumentation if there is no assess scope', function () {
110
+ it('SchemaMap.doValidateSync skip instrumentation if there is no assess policy in request scope', function () {
111
111
  simulateRequestScope(function () {
112
112
  const str = trackString('error');
113
113
 
@@ -115,7 +115,7 @@ describe('assess dataflow propagation mongoose.MapSchema', function () {
115
115
 
116
116
  const strInfo = tracker.getData(str);
117
117
  expect(strInfo).to.be.null;
118
- }, {});
118
+ }, { assess: { policy: null } });
119
119
  });
120
120
 
121
121
  it('SchemaMap.doValidateSync skip instrumentation if there is no custom validator', function () {
@@ -261,7 +261,7 @@ describe('assess dataflow propagation mongoose.MapSchema', function () {
261
261
  });
262
262
  });
263
263
 
264
- it('SchemaMap.doValidate skip instrumentation if there is no assess scope', function () {
264
+ it('SchemaMap.doValidate skip instrumentation if there is no assess policy in request scope', function () {
265
265
  simulateRequestScope(function () {
266
266
  const str = trackString('foo');
267
267
 
@@ -269,7 +269,7 @@ describe('assess dataflow propagation mongoose.MapSchema', function () {
269
269
 
270
270
  const strInfo = tracker.getData(str);
271
271
  expect(strInfo).to.be.null;
272
- }, {});
272
+ }, { assess: { policy: null } });
273
273
  });
274
274
 
275
275
  it('SchemaMap.doValidate skip instrumentation if there is a validation error', function () {
@@ -13,17 +13,18 @@
13
13
  * way not consistent with the End User License Agreement.
14
14
  */
15
15
  'use strict';
16
+
17
+ const { traverseValues, DataflowTag, primordials: { StringPrototypeSubstring } } = require('@contrast/common');
16
18
  const { patchType } = require('../../common');
17
19
  const { userDefinedType } = require('./common');
18
- const { traverseValues, DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
19
20
 
20
21
  module.exports = function (core) {
21
22
  const {
22
23
  config: { assess },
23
- scopes: { sources },
24
24
  patcher,
25
25
  depHooks,
26
26
  assess: {
27
+ getSourceContext,
27
28
  eventFactory: { createPropagationEvent },
28
29
  dataflow: {
29
30
  tracker,
@@ -119,7 +120,7 @@ module.exports = function (core) {
119
120
  if (
120
121
  !assess.trust_custom_validators ||
121
122
  data.result ||
122
- !sources.getStore()?.assess
123
+ !getSourceContext()
123
124
  ) {
124
125
  return;
125
126
  }
@@ -134,7 +135,7 @@ module.exports = function (core) {
134
135
  name: doValidateName,
135
136
  patchType,
136
137
  pre: (data) => {
137
- if (!assess.trust_custom_validators || !sources.getStore()?.assess) {
138
+ if (!assess.trust_custom_validators || !getSourceContext()) {
138
139
  return;
139
140
  }
140
141
 
@@ -110,7 +110,7 @@ describe('assess dataflow propagation mongoose.MixedSchema', function () {
110
110
  });
111
111
  });
112
112
 
113
- it('SchemaMixed.doValidateSync skip instrumentation if there is no assess scope', function () {
113
+ it('SchemaMixed.doValidateSync skip instrumentation if there is no assess policy in request scope', function () {
114
114
  simulateRequestScope(function () {
115
115
  const str = trackString('error');
116
116
 
@@ -118,7 +118,7 @@ describe('assess dataflow propagation mongoose.MixedSchema', function () {
118
118
 
119
119
  const strInfo = tracker.getData(str);
120
120
  expect(strInfo).to.be.null;
121
- }, {});
121
+ }, { assess: { policy: null } });
122
122
  });
123
123
 
124
124
  it('SchemaMixed.doValidateSync skip instrumentation if there is no custom validator', function () {
@@ -147,7 +147,6 @@ describe('assess dataflow propagation mongoose.MixedSchema', function () {
147
147
  value: 'foo',
148
148
  },
149
149
  value: 'foo',
150
-
151
150
  });
152
151
  });
153
152
  });
@@ -355,7 +354,7 @@ describe('assess dataflow propagation mongoose.MixedSchema', function () {
355
354
  });
356
355
  });
357
356
 
358
- it('SchemaMixed.doValidate skip instrumentation if there is no assess scope', function () {
357
+ it('SchemaMixed.doValidate skip instrumentation if there is no assess policy in request scope', function () {
359
358
  simulateRequestScope(function () {
360
359
  const str = trackString('foo');
361
360
 
@@ -363,7 +362,7 @@ describe('assess dataflow propagation mongoose.MixedSchema', function () {
363
362
 
364
363
  const strInfo = tracker.getData(str);
365
364
  expect(strInfo).to.be.null;
366
- }, {});
365
+ }, { assess: { policy: null } });
367
366
  });
368
367
 
369
368
  it('SchemaMixed.doValidate skip instrumentation if there is a validation error', function () {
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
18
+ const { DataflowTag, primordials: { StringPrototypeSubstring } } = require('@contrast/common');
19
19
  const { patchType } = require('../../common');
20
20
  const { userDefinedType } = require('./common');
21
21
 
@@ -28,6 +28,7 @@ module.exports = function (core) {
28
28
  patcher,
29
29
  depHooks,
30
30
  assess: {
31
+ getSourceContext,
31
32
  eventFactory: { createPropagationEvent },
32
33
  dataflow: { tracker },
33
34
  },
@@ -70,9 +71,7 @@ module.exports = function (core) {
70
71
  patchType,
71
72
  pre(data) {
72
73
  const [value, cb] = data.args;
73
- if (!value || typeof cb !== 'function' || !sources.getStore()?.assess) {
74
- return;
75
- }
74
+ if (!value || typeof cb !== 'function' || !getSourceContext()) return;
76
75
 
77
76
  const hasCustomValidator = data.obj.validators.some(
78
77
  (validator) => validator.type === userDefinedType
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { HTML_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createEscapeTagRanges
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { HTML_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createEscapeTagRanges } = require('../../tag-utils');
24
21
  const { patchType } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  depHooks,
31
27
  assess: {
28
+ getSourceContext,
32
29
  eventFactory: { createPropagationEvent },
33
30
  dataflow: { tracker }
34
31
  }
@@ -44,7 +41,7 @@ module.exports = function(core) {
44
41
  patchType,
45
42
  post(data) {
46
43
  const { args, result, hooked, orig } = data;
47
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
44
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
48
45
 
49
46
  const argInfo = tracker.getData(args[0]);
50
47
 
@@ -27,12 +27,12 @@ describe('assess dataflow propagation mustache.escape', function () {
27
27
  sinon.resetHistory();
28
28
  });
29
29
 
30
- it('will not propagate if there is no assess context', function () {
30
+ it('will not propagate if there is no assess policy in request context', function () {
31
31
  simulateRequestScope(function () {
32
32
  const value = trackString('<script>alert("hello");</script>');
33
33
  const result = mustache.escape(value);
34
34
  expect(tracker.getData(result)).to.be.null;
35
- }, {});
35
+ }, { assess: { policy: null } });
36
36
  });
37
37
 
38
38
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { SQL_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { SQL_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createFullLengthCopyTags } = require('../../tag-utils');
24
21
  const { patchType, createModuleLabel } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  depHooks,
31
27
  assess: {
28
+ getSourceContext,
32
29
  eventFactory: { createPropagationEvent },
33
30
  dataflow: { tracker }
34
31
  }
@@ -37,7 +34,7 @@ module.exports = function(core) {
37
34
  function createPostHook(eventName, objectValue) {
38
35
  return function(data) {
39
36
  const { args, result, hooked, orig } = data;
40
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
37
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
41
38
 
42
39
  const argInfo = tracker.getData(args[0]);
43
40
 
@@ -52,13 +52,13 @@ describe('assess dataflow propagation mysql.connection.escape', function () {
52
52
  });
53
53
  });
54
54
 
55
- it('will not propagate if there is no assess context', function () {
55
+ it('will not propagate if there is no assess policy in request context', function () {
56
56
  simulateRequestScope(function () {
57
57
  const value = trackString('foo');
58
58
  const connection = new mockConnection();
59
59
  const result = connection.escape(value);
60
60
  expect(tracker.getData(result)).to.be.null;
61
- }, {});
61
+ }, { assess: { policy: null } });
62
62
  });
63
63
 
64
64
  it('will not propagate if there instrumentation is locked', function () {
@@ -16,14 +16,15 @@
16
16
  'use strict';
17
17
 
18
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
19
20
  const { patchType } = require('../common');
20
21
 
21
22
  module.exports = function (core) {
22
23
  const {
23
24
  logger,
24
- scopes: { instrumentation, sources },
25
25
  patcher,
26
26
  assess: {
27
+ getSourceContext,
27
28
  dataflow: { tracker }
28
29
  }
29
30
  } = core;
@@ -41,8 +42,7 @@ module.exports = function (core) {
41
42
  isNaN(result) ||
42
43
  !value ||
43
44
  !isString(value) ||
44
- !sources.getStore()?.assess ||
45
- instrumentation.isLocked() ||
45
+ !getSourceContext(PROPAGATOR) ||
46
46
  !tracker.getData(value)
47
47
  ) return;
48
48
 
@@ -14,19 +14,18 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
- const { isString, ArrayPrototypeJoin } = require('@contrast/common');
17
+
18
+ const { isString, primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
20
  const { patchType } = require('../../common');
19
- const {
20
- excludeExtensionDotFromTags,
21
- createBasenameTagsInResult,
22
- } = require('./common');
21
+ const { excludeExtensionDotFromTags, createBasenameTagsInResult } = require('./common');
23
22
 
24
23
  module.exports = function(core) {
25
24
  const {
26
25
  depHooks,
27
26
  patcher,
28
- scopes: { sources, instrumentation },
29
27
  assess: {
28
+ getSourceContext,
30
29
  eventFactory: { createPropagationEvent },
31
30
  dataflow: { tracker },
32
31
  },
@@ -43,12 +42,8 @@ module.exports = function(core) {
43
42
  patchType,
44
43
  post(data) {
45
44
  const { args: origArgs, result, name, hooked, orig } = data;
46
- if (
47
- !result ||
48
- !sources.getStore()?.assess ||
49
- instrumentation.isLocked()
50
- )
51
- return;
45
+
46
+ if (!result || !getSourceContext(PROPAGATOR)) return;
52
47
 
53
48
  const [pathStr, suffixStr] = origArgs;
54
49
 
@@ -44,13 +44,13 @@ describe('assess dataflow propagation path basename', function () {
44
44
  });
45
45
  });
46
46
 
47
- it('will not propagate if there is no assess context', function () {
47
+ it('will not propagate if there is no assess policy in request context', function () {
48
48
  simulateRequestScope(function () {
49
49
  const myPath = trackString('/script.sh');
50
50
  const result = path.basename(myPath);
51
51
 
52
52
  expect(tracker.getData(result)).to.be.null;
53
- }, {});
53
+ }, { assess: { policy: null } });
54
54
  });
55
55
 
56
56
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { StringPrototypeMatchAll, StringPrototypeSubstring, StringPrototypeReplace } = require('@contrast/common');
18
+ const { primordials: { StringPrototypeMatchAll, StringPrototypeSubstring, StringPrototypeReplace } } = require('@contrast/common');
19
19
  const {
20
20
  createSubsetTags,
21
21
  createAppendTags,
@@ -86,7 +86,7 @@ function createArgTagsInResult({
86
86
  let { index: startIdx } = matchedSegments[i];
87
87
  if (
88
88
  ['.', '..'].includes(segment) &&
89
- result.substring(lastIndex - segment.length, lastIndex + 1) !== segment
89
+ StringPrototypeSubstring.call(result, lastIndex - segment.length, lastIndex + 1) !== segment
90
90
  )
91
91
  continue;
92
92
  let idxInResult = result.lastIndexOf(segment, lastIndex);
@@ -15,17 +15,16 @@
15
15
 
16
16
  'use strict';
17
17
  const { isString } = require('@contrast/common');
18
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
19
  const { patchType } = require('../../common');
19
- const {
20
- createArgTagsInResult
21
- } = require('./common');
20
+ const { createArgTagsInResult } = require('./common');
22
21
 
23
22
  module.exports = function(core) {
24
23
  const {
25
24
  depHooks,
26
25
  patcher,
27
- scopes: { sources, instrumentation },
28
26
  assess: {
27
+ getSourceContext,
29
28
  eventFactory: { createPropagationEvent },
30
29
  dataflow: { tracker },
31
30
  },
@@ -42,12 +41,8 @@ module.exports = function(core) {
42
41
  patchType,
43
42
  post(data) {
44
43
  const { args, result, name, hooked, orig } = data;
45
- if (
46
- !result ||
47
- !sources.getStore()?.assess ||
48
- instrumentation.isLocked()
49
- )
50
- return;
44
+
45
+ if (!result || !getSourceContext(PROPAGATOR)) return;
51
46
 
52
47
  const pathStr = args[0];
53
48
 
@@ -41,14 +41,14 @@ describe('assess dataflow propagation path dirname', function () {
41
41
  });
42
42
  });
43
43
 
44
- it('will not propagate if there is no assess context', function () {
44
+ it('will not propagate if there is no assess policy in request context', function () {
45
45
  simulateRequestScope(function () {
46
46
  const myPath = trackString('/path');
47
47
 
48
48
  const result = path.dirname(myPath);
49
49
 
50
50
  expect(tracker.getData(result)).to.be.null;
51
- }, {});
51
+ }, { assess: { policy: null } });
52
52
  });
53
53
 
54
54
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,19 +14,19 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
- const { patchType } = require('../../common');
17
+
18
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
20
  const { createSubsetTags } = require('../../../tag-utils');
20
- const {
21
- excludeExtensionDotFromTags
22
- } = require('./common');
21
+ const { patchType } = require('../../common');
22
+ const { excludeExtensionDotFromTags } = require('./common');
23
23
 
24
24
  module.exports = function(core) {
25
25
  const {
26
26
  depHooks,
27
27
  patcher,
28
- scopes: { sources, instrumentation },
29
28
  assess: {
29
+ getSourceContext,
30
30
  eventFactory: { createPropagationEvent },
31
31
  dataflow: { tracker },
32
32
  },
@@ -43,12 +43,7 @@ module.exports = function(core) {
43
43
  patchType,
44
44
  post(data) {
45
45
  const { args, result, name, hooked, orig } = data;
46
- if (
47
- !result ||
48
- !sources.getStore()?.assess ||
49
- instrumentation.isLocked()
50
- )
51
- return;
46
+ if (!result || !getSourceContext(PROPAGATOR)) return;
52
47
 
53
48
  const pathStr = args[0];
54
49
 
@@ -36,14 +36,14 @@ describe('assess dataflow propagation path extname', function () {
36
36
  });
37
37
  });
38
38
 
39
- it('will not propagate if there is no assess context', function () {
39
+ it('will not propagate if there is no assess policy in request context', function () {
40
40
  simulateRequestScope(function () {
41
41
  const myPath = trackString('/path/to/file.txt');
42
42
 
43
43
  const result = path.extname(myPath);
44
44
 
45
45
  expect(tracker.getData(result)).to.be.null;
46
- }, {});
46
+ }, { assess: { policy: null } });
47
47
  });
48
48
 
49
49
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,20 +14,19 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
- const { ArrayPrototypeJoin, isString } = require('@contrast/common');
18
- const { patchType } = require('../../common');
17
+
18
+ const { primordials: { ArrayPrototypeJoin }, isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
20
  const { createMergedTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
20
- const {
21
- createArgTagsInResult,
22
- excludeExtensionDotFromTags
23
- } = require('./common');
21
+ const { patchType } = require('../../common');
22
+ const { createArgTagsInResult, excludeExtensionDotFromTags } = require('./common');
24
23
 
25
24
  module.exports = function(core) {
26
25
  const {
27
26
  depHooks,
28
27
  patcher,
29
- scopes: { sources, instrumentation },
30
28
  assess: {
29
+ getSourceContext,
31
30
  eventFactory: { createPropagationEvent },
32
31
  dataflow: { tracker },
33
32
  },
@@ -44,12 +43,7 @@ module.exports = function(core) {
44
43
  patchType,
45
44
  post(data) {
46
45
  const { args, result, name: patchName, hooked, orig } = data;
47
- if (
48
- !result ||
49
- !sources.getStore()?.assess ||
50
- instrumentation.isLocked()
51
- )
52
- return;
46
+ if (!result || !getSourceContext(PROPAGATOR)) return;
53
47
 
54
48
  const pathProps = [];
55
49
  const { dir, root, base, name, ext } = args[0];
@@ -39,7 +39,7 @@ describe('assess dataflow propagation path format', function () {
39
39
  });
40
40
  });
41
41
 
42
- it('will not propagate if there is no assess context', function () {
42
+ it('will not propagate if there is no assess policy in request context', function () {
43
43
  simulateRequestScope(function () {
44
44
  const dir = trackString('/path/to');
45
45
 
@@ -49,7 +49,7 @@ describe('assess dataflow propagation path format', function () {
49
49
  });
50
50
 
51
51
  expect(tracker.getData(result)).to.be.null;
52
- }, {});
52
+ }, { assess: { policy: null } });
53
53
  });
54
54
 
55
55
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,20 +14,19 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
- const { isString, ArrayPrototypeJoin } = require('@contrast/common');
17
+
18
+ const { isString, primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
20
  const { createMergedTags } = require('../../../tag-utils');
19
21
  const { patchType } = require('../../common');
20
- const {
21
- createArgTagsInResult,
22
- excludeExtensionDotFromTags,
23
- } = require('./common');
22
+ const { createArgTagsInResult, excludeExtensionDotFromTags } = require('./common');
24
23
 
25
24
  module.exports = function(core) {
26
25
  const {
27
26
  depHooks,
28
27
  patcher,
29
- scopes: { sources, instrumentation },
30
28
  assess: {
29
+ getSourceContext,
31
30
  eventFactory: { createPropagationEvent },
32
31
  dataflow: { tracker },
33
32
  },
@@ -46,12 +45,8 @@ module.exports = function(core) {
46
45
  patchType,
47
46
  post(data) {
48
47
  const { args: origArgs, result, hooked, orig } = data;
49
- if (
50
- !result ||
51
- !sources.getStore()?.assess ||
52
- instrumentation.isLocked()
53
- )
54
- return;
48
+
49
+ if (!result || !getSourceContext(PROPAGATOR)) return;
55
50
 
56
51
  const pathSegments = [...origArgs].reverse();
57
52
  const args = [];