@contrast/assess 1.35.0 → 1.37.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 (169) 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 +99 -5
  38. package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +41 -2
  39. package/lib/dataflow/propagation/install/mustache-escape.js +5 -8
  40. package/lib/dataflow/propagation/install/mustache-escape.test.js +2 -2
  41. package/lib/dataflow/propagation/install/mysql-connection-escape.js +5 -8
  42. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +2 -2
  43. package/lib/dataflow/propagation/install/parse-int.js +3 -3
  44. package/lib/dataflow/propagation/install/path/basename.js +7 -12
  45. package/lib/dataflow/propagation/install/path/basename.test.js +2 -2
  46. package/lib/dataflow/propagation/install/path/common.js +2 -2
  47. package/lib/dataflow/propagation/install/path/dirname.js +5 -10
  48. package/lib/dataflow/propagation/install/path/dirname.test.js +2 -2
  49. package/lib/dataflow/propagation/install/path/extname.js +6 -11
  50. package/lib/dataflow/propagation/install/path/extname.test.js +2 -2
  51. package/lib/dataflow/propagation/install/path/format.js +7 -13
  52. package/lib/dataflow/propagation/install/path/format.test.js +2 -2
  53. package/lib/dataflow/propagation/install/path/join-and-resolve.js +7 -12
  54. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +2 -2
  55. package/lib/dataflow/propagation/install/path/normalize.js +4 -11
  56. package/lib/dataflow/propagation/install/path/normalize.test.js +2 -2
  57. package/lib/dataflow/propagation/install/path/parse.js +3 -8
  58. package/lib/dataflow/propagation/install/path/parse.test.js +2 -2
  59. package/lib/dataflow/propagation/install/path/relative.js +5 -11
  60. package/lib/dataflow/propagation/install/path/relative.test.js +2 -2
  61. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +5 -11
  62. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +2 -2
  63. package/lib/dataflow/propagation/install/pug/index.js +8 -3
  64. package/lib/dataflow/propagation/install/pug-runtime-escape.js +5 -8
  65. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +1 -1
  66. package/lib/dataflow/propagation/install/querystring/escape.js +3 -3
  67. package/lib/dataflow/propagation/install/querystring/parse.js +7 -11
  68. package/lib/dataflow/propagation/install/querystring/stringify.js +3 -3
  69. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +4 -3
  70. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +5 -3
  71. package/lib/dataflow/propagation/install/send.js +5 -10
  72. package/lib/dataflow/propagation/install/sequelize/query-generator.js +3 -4
  73. package/lib/dataflow/propagation/install/sequelize/sql-string.js +8 -12
  74. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +2 -13
  75. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -5
  76. package/lib/dataflow/propagation/install/sql-template-strings.test.js +2 -2
  77. package/lib/dataflow/propagation/install/string/concat.js +2 -1
  78. package/lib/dataflow/propagation/install/string/concat.test.js +15 -2
  79. package/lib/dataflow/propagation/install/string/format-methods.js +4 -2
  80. package/lib/dataflow/propagation/install/string/format-methods.test.js +15 -2
  81. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  82. package/lib/dataflow/propagation/install/string/html-methods.test.js +15 -2
  83. package/lib/dataflow/propagation/install/string/index.js +2 -2
  84. package/lib/dataflow/propagation/install/string/match-all.js +2 -1
  85. package/lib/dataflow/propagation/install/string/match-all.test.js +13 -0
  86. package/lib/dataflow/propagation/install/string/match.js +11 -10
  87. package/lib/dataflow/propagation/install/string/match.test.js +13 -0
  88. package/lib/dataflow/propagation/install/string/replace.js +15 -9
  89. package/lib/dataflow/propagation/install/string/replace.test.js +13 -0
  90. package/lib/dataflow/propagation/install/string/slice.js +2 -1
  91. package/lib/dataflow/propagation/install/string/slice.test.js +13 -0
  92. package/lib/dataflow/propagation/install/string/split.js +2 -1
  93. package/lib/dataflow/propagation/install/string/split.test.js +13 -0
  94. package/lib/dataflow/propagation/install/string/substring.js +2 -1
  95. package/lib/dataflow/propagation/install/string/substring.test.js +13 -0
  96. package/lib/dataflow/propagation/install/string/trim.js +4 -1
  97. package/lib/dataflow/propagation/install/string/trim.test.js +13 -0
  98. package/lib/dataflow/propagation/install/unescape.js +5 -8
  99. package/lib/dataflow/propagation/install/unescape.test.js +2 -2
  100. package/lib/dataflow/propagation/install/url/domain-parsers.js +4 -5
  101. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +2 -2
  102. package/lib/dataflow/propagation/install/url/parse.js +3 -2
  103. package/lib/dataflow/propagation/install/url/parse.test.js +2 -2
  104. package/lib/dataflow/propagation/install/url/searchParams.js +5 -5
  105. package/lib/dataflow/propagation/install/url/searchParams.test.js +2 -2
  106. package/lib/dataflow/propagation/install/url/url.js +6 -3
  107. package/lib/dataflow/propagation/install/url/url.test.js +2 -2
  108. package/lib/dataflow/propagation/install/util-format.js +7 -6
  109. package/lib/dataflow/propagation/install/util-format.test.js +2 -2
  110. package/lib/dataflow/propagation/install/validator/hooks.js +7 -2
  111. package/lib/dataflow/sinks/install/child-process.js +1 -1
  112. package/lib/dataflow/sinks/install/child-process.test.js +1 -1
  113. package/lib/dataflow/sinks/install/fs.js +1 -1
  114. package/lib/dataflow/sinks/install/fs.test.js +1 -1
  115. package/lib/dataflow/sinks/install/function.js +1 -1
  116. package/lib/dataflow/sinks/install/http/request.js +2 -1
  117. package/lib/dataflow/sinks/install/http/request.test.js +1 -1
  118. package/lib/dataflow/sinks/install/http/server-response.test.js +3 -5
  119. package/lib/dataflow/sinks/install/restify.js +1 -1
  120. package/lib/dataflow/sinks/install/vm.js +4 -2
  121. package/lib/dataflow/sinks/install/vm.test.js +1 -1
  122. package/lib/dataflow/sources/handler.js +5 -2
  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/get-policy.js +2 -2
  158. package/lib/index.js +18 -7
  159. package/lib/index.test.js +4 -0
  160. package/lib/make-source-context.js +37 -28
  161. package/lib/make-source-context.test.js +7 -7
  162. package/lib/response-scanning/handlers/index.js +7 -5
  163. package/lib/response-scanning/handlers/utils.js +11 -8
  164. package/lib/response-scanning/install/http.js +1 -1
  165. package/lib/sampler.js +136 -0
  166. package/lib/sampler.test.js +296 -0
  167. package/lib/session-configuration/install/express-session.js +1 -1
  168. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  169. package/package.json +10 -10
@@ -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 = [];
@@ -45,7 +45,7 @@ describe('assess dataflow propagation path', function () {
45
45
  });
46
46
  });
47
47
 
48
- it('will not propagate if there is no assess context', function () {
48
+ it('will not propagate if there is no assess policy in request context', function () {
49
49
  simulateRequestScope(function () {
50
50
  const seg1 = trackString('/path');
51
51
  const seg2 = trackString('/to');
@@ -54,7 +54,7 @@ describe('assess dataflow propagation path', function () {
54
54
  const result = path[method](seg1, seg2, seg3);
55
55
 
56
56
  expect(tracker.getData(result)).to.be.null;
57
- }, {});
57
+ }, { assess: { policy: null } });
58
58
  });
59
59
 
60
60
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,18 +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
- excludeExtensionDotFromTags,
22
- } = require('./common');
20
+ const { createArgTagsInResult, excludeExtensionDotFromTags, } = require('./common');
23
21
 
24
22
  module.exports = function(core) {
25
23
  const {
26
24
  depHooks,
27
25
  patcher,
28
- scopes: { sources, instrumentation },
29
26
  assess: {
27
+ getSourceContext,
30
28
  eventFactory: { createPropagationEvent },
31
29
  dataflow: { tracker },
32
30
  },
@@ -43,12 +41,7 @@ module.exports = function(core) {
43
41
  patchType,
44
42
  post(data) {
45
43
  const { args, result, name, hooked, orig } = data;
46
- if (
47
- !result ||
48
- !sources.getStore()?.assess ||
49
- instrumentation.isLocked()
50
- )
51
- return;
44
+ if (!result || !getSourceContext(PROPAGATOR)) return;
52
45
 
53
46
  const pathStr = args[0];
54
47
 
@@ -42,14 +42,14 @@ describe('assess dataflow propagation path normalize', function () {
42
42
  });
43
43
  });
44
44
 
45
- it('will not propagate if there is no assess context', function () {
45
+ it('will not propagate if there is no assess policy in request context', function () {
46
46
  simulateRequestScope(function () {
47
47
  const myPath = trackString('/path');
48
48
 
49
49
  const result = path.normalize(myPath);
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 () {
@@ -15,6 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
  const { isString } = require('@contrast/common');
18
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
19
  const { createSubsetTags } = require('../../../tag-utils');
19
20
  const { patchType } = require('../../common');
20
21
  const { excludeExtensionDotFromTags } = require('./common');
@@ -23,8 +24,8 @@ module.exports = function(core) {
23
24
  const {
24
25
  depHooks,
25
26
  patcher,
26
- scopes: { sources, instrumentation },
27
27
  assess: {
28
+ getSourceContext,
28
29
  inspect, // todo: remove
29
30
  eventFactory: { createPropagationEvent },
30
31
  dataflow: { tracker },
@@ -42,15 +43,9 @@ module.exports = function(core) {
42
43
  patchType,
43
44
  post(data) {
44
45
  const { args, result, name: patchName, hooked, orig } = data;
45
- if (
46
- !result ||
47
- !sources.getStore()?.assess ||
48
- instrumentation.isLocked()
49
- )
50
- return;
46
+ if (!result || !getSourceContext(PROPAGATOR)) return;
51
47
 
52
48
  const [path] = args;
53
-
54
49
  if (!path || !isString(path)) return;
55
50
 
56
51
  const strInfo = tracker.getData(path);
@@ -40,7 +40,7 @@ describe('assess dataflow propagation path parse', function () {
40
40
  });
41
41
  });
42
42
 
43
- it('will not propagate if there is no assess context', function () {
43
+ it('will not propagate if there is no assess policy in request context', function () {
44
44
  simulateRequestScope(function () {
45
45
  const str = trackString('/path/to/file.txt');
46
46
  const result = path.parse(str);
@@ -48,7 +48,7 @@ describe('assess dataflow propagation path parse', function () {
48
48
  const valInfo = tracker.getData(result[key]);
49
49
  expect(valInfo).to.be.null;
50
50
  });
51
- }, {});
51
+ }, { assess: { policy: null } });
52
52
  });
53
53
 
54
54
  it('will not propagate if instrumentation is locked', function () {
@@ -14,19 +14,18 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
+
17
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
20
  const { patchType } = require('../../common');
19
- const {
20
- createArgTagsInResult,
21
- excludeExtensionDotFromTags,
22
- } = require('./common');
21
+ const { createArgTagsInResult, excludeExtensionDotFromTags, } = 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,7 @@ module.exports = function(core) {
43
42
  patchType,
44
43
  post(data) {
45
44
  const { args, result, name, hooked, orig } = data;
46
- if (
47
- !result ||
48
- !sources.getStore()?.assess ||
49
- instrumentation.isLocked()
50
- )
51
- return;
45
+ if (!result || !getSourceContext(PROPAGATOR)) return;
52
46
 
53
47
  const [fromStr, toStr] = args;
54
48
 
@@ -41,14 +41,14 @@ describe('assess dataflow propagation path relative', 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.relative('/to', 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,18 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
+
17
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
20
  const { patchType } = require('../../common');
19
- const {
20
- createArgTagsInResult,
21
- excludeExtensionDotFromTags
22
- } = require('./common');
21
+ const { createArgTagsInResult, excludeExtensionDotFromTags } = 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
  },
@@ -42,12 +41,7 @@ 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
+ if (!result || !getSourceContext(PROPAGATOR)) return;
51
45
 
52
46
  const pathStr = args[0];
53
47
 
@@ -35,14 +35,14 @@ describe('assess dataflow propagation path toNamespacedPath', function () {
35
35
  });
36
36
  });
37
37
 
38
- it('will not propagate if there is no assess context', function () {
38
+ it('will not propagate if there is no assess policy in request context', function () {
39
39
  simulateRequestScope(function () {
40
40
  const myPath = trackString('C:\\path\\to\\file.txt');
41
41
 
42
42
  const result = path.toNamespacedPath(myPath);
43
43
 
44
44
  expect(tracker.getData(result)).to.be.null;
45
- }, {});
45
+ }, { assess: { policy: null } });
46
46
  });
47
47
 
48
48
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,6 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
17
18
  const { patchType } = require('../../common');
18
19
 
19
20
  /** @type {import('@contrast/rewriter').RewriteOpts} */
@@ -22,8 +23,12 @@ const REWRITE_OPTS = { isModule: false, inject: false, wrap: false };
22
23
  module.exports = function (core) {
23
24
  const store = { lock: true, name: 'assess:propagators:pug-compile' };
24
25
  const {
25
- scopes: { sources, instrumentation },
26
- patcher, logger, rewriter, depHooks,
26
+ patcher,
27
+ logger,
28
+ rewriter,
29
+ depHooks,
30
+ scopes: { instrumentation },
31
+ assess: { getSourceContext },
27
32
  } = core;
28
33
 
29
34
  const pugInstrumentation = {
@@ -34,7 +39,7 @@ module.exports = function (core) {
34
39
  name: 'pug.compile',
35
40
  patchType,
36
41
  pre(data) {
37
- if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+ if (!getSourceContext(PROPAGATOR)) return;
38
43
 
39
44
  const opts = data.args[1] || {};
40
45
  const plugins = opts.plugins || [];
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { WEAK_URL_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { WEAK_URL_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
  }
@@ -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
 
@@ -54,7 +54,7 @@ describe('assess dataflow propagation pugRuntime.escape', function () {
54
54
  const value = trackString('foo');
55
55
  const result = mockPugRuntime.escape(value);
56
56
  expect(tracker.getData(result)).to.be.null;
57
- }, {});
57
+ }, { assess: { policy: null } });
58
58
  });
59
59
 
60
60
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,19 +15,20 @@
15
15
  'use strict';
16
16
 
17
17
  const { DataflowTag: { URL_ENCODED } } = require('@contrast/common');
18
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
19
  const { createFullLengthCopyTags } = require('../../../tag-utils');
19
20
  const { patchType } = require('../../common');
20
21
 
21
22
  module.exports = function(core) {
22
23
  const {
23
24
  assess: {
25
+ getSourceContext,
24
26
  inspect, // todo: remove
25
27
  eventFactory: { createPropagationEvent },
26
28
  dataflow: { tracker }
27
29
  },
28
30
  depHooks,
29
31
  patcher,
30
- scopes,
31
32
  } = core;
32
33
 
33
34
  return core.assess.dataflow.propagation.querystringInstrumentation.escape = {
@@ -43,8 +44,7 @@ module.exports = function(core) {
43
44
  const strInfo = tracker.getData(value);
44
45
  if (!strInfo) return;
45
46
 
46
- const sourceContext = scopes.sources.getStore()?.assess;
47
- if (!sourceContext) return;
47
+ if (!getSourceContext(PROPAGATOR)) return;
48
48
 
49
49
  let tags;
50
50
  if (value !== data.result) {
@@ -18,17 +18,18 @@
18
18
  const querystring = require('querystring');
19
19
  const {
20
20
  DataflowTag: { URL_ENCODED },
21
- ArrayPrototypeJoin,
21
+ primordials: { ArrayPrototypeJoin },
22
22
  } = require('@contrast/common');
23
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
23
24
  const { createSubsetTags, createAppendTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
24
25
  const { patchType } = require('../../common');
25
26
 
26
27
  module.exports = function(core) {
27
28
  const {
28
- scopes: { sources, instrumentation },
29
29
  patcher,
30
30
  depHooks,
31
31
  assess: {
32
+ getSourceContext,
32
33
  eventFactory: { createPropagationEvent },
33
34
  dataflow: { tracker }
34
35
  }
@@ -105,15 +106,10 @@ module.exports = function(core) {
105
106
  name: `querystring.${method}`,
106
107
  patchType,
107
108
  pre(data) {
108
- if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
109
- const input = data.args[0];
110
- if (!input) {
111
- return;
112
- }
113
- const trackingData = tracker.getData(input);
114
- if (!trackingData) {
115
- return;
116
- }
109
+ if (!data.args[0] || !getSourceContext(PROPAGATOR)) return;
110
+
111
+ const trackingData = tracker.getData(data.args[0]);
112
+ if (!trackingData) return;
117
113
 
118
114
  data.idx = 0;
119
115
  data.origArgs = [...data.args];
@@ -16,6 +16,7 @@
16
16
 
17
17
  const querystring = require('querystring');
18
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
20
  const utils = require('../../../tag-utils');
20
21
  const { patchType } = require('../../common');
21
22
 
@@ -24,21 +25,20 @@ const moduleName = 'querystring';
24
25
  module.exports = function(core) {
25
26
  const {
26
27
  assess: {
28
+ getSourceContext,
27
29
  inspect, // todo: remove
28
30
  dataflow: { tracker },
29
31
  eventFactory: { createPropagationEvent },
30
32
  },
31
33
  depHooks,
32
34
  patcher,
33
- scopes,
34
35
  } = core;
35
36
 
36
37
  /**
37
38
  * Adds custom encoding function to capture key/value tags and history during stringification
38
39
  */
39
40
  function pre(data) {
40
- const sourceContext = scopes.sources.getStore()?.assess;
41
- if (!sourceContext) return;
41
+ if (!getSourceContext(PROPAGATOR)) return;
42
42
 
43
43
  const [input] = data.args;
44
44
  const escape = typeof data.args[3]?.encodeURIComponent === 'function'
@@ -14,14 +14,16 @@
14
14
  */
15
15
 
16
16
  'use strict';
17
+
18
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
17
19
  const { createSubsetTags, getAdjustedUntrackedValue } = require('../../tag-utils');
18
20
  const { patchType } = require('../common');
19
21
 
20
22
  module.exports = function(core) {
21
23
  const {
22
- scopes: { sources, instrumentation },
23
24
  patcher,
24
25
  assess: {
26
+ getSourceContext,
25
27
  eventFactory: { createPropagationEvent },
26
28
  dataflow: { tracker },
27
29
  },
@@ -83,8 +85,7 @@ module.exports = function(core) {
83
85
  !obj ||
84
86
  !args[0] ||
85
87
  !result?.length ||
86
- !sources.getStore()?.assess ||
87
- instrumentation.isLocked()
88
+ !getSourceContext(PROPAGATOR)
88
89
  )
89
90
  return;
90
91
 
@@ -104,11 +104,12 @@ describe('assess dataflow propagation RegExp exec', function () {
104
104
  it.skip('propagates strings when iteratively called', function() {
105
105
  simulateRequestScope(() => {
106
106
  const re = /^\/?$/i;
107
- // 0123456789*1234567
107
+ // eslint-disable-next-line
108
108
  const extern = trackString('');
109
109
 
110
110
  let ret;
111
111
  while ((ret = re.exec(''))) {
112
+ // eslint-disable-next-line
112
113
  const matchInfo = tracker.getData(ret[0]);
113
114
  // console.log(re.lastIndex, ret.index, ret.indices);
114
115
  re.lastIndex += 1;
@@ -153,6 +154,8 @@ describe('assess dataflow propagation RegExp exec', function () {
153
154
 
154
155
  it('does not propagate if we exeeded the maximum propagation count for a group', function () {
155
156
  simulateRequestScope(() => {
157
+ core.scopes.sources.getStore().assess.propagationEventsCount = 498;
158
+
156
159
  const re = /foo(?<bar>bar)/;
157
160
  const extern = trackString('foobar');
158
161
 
@@ -173,7 +176,7 @@ describe('assess dataflow propagation RegExp exec', function () {
173
176
  [UNTRUSTED]: [0, 2]
174
177
  });
175
178
  expect(barGroupInfo).to.be.null;
176
- }, { assess: { propagationEventsCount: 498 } });
179
+ });
177
180
  });
178
181
 
179
182
 
@@ -251,7 +254,6 @@ describe('assess dataflow propagation RegExp exec', function () {
251
254
  const blackInfo = tracker.getData(ret[3]);
252
255
  const colorGroupInfo = tracker.getData(ret.groups.color);
253
256
 
254
-
255
257
  expect(ret).to.deep.equal([
256
258
  'Quick Brown Fox Jumps Over The Lazy Black',
257
259
  'Brown',