@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
@@ -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',
@@ -15,13 +15,13 @@
15
15
  'use strict';
16
16
 
17
17
  const { patchType } = require('../common');
18
- const { StringPrototypeSlice } = require('@contrast/common');
18
+ const { primordials: { StringPrototypeSlice } } = require('@contrast/common');
19
19
 
20
20
  module.exports = function (core) {
21
21
  const {
22
- scopes: { sources, instrumentation },
23
22
  depHooks,
24
- patcher
23
+ patcher,
24
+ assess: { getSourceContext }
25
25
  } = core;
26
26
 
27
27
  const send = {};
@@ -37,10 +37,7 @@ module.exports = function (core) {
37
37
  patchType,
38
38
  pre(data) {
39
39
  const { args } = data;
40
-
41
- if (!sources.getStore()?.assess || instrumentation.isLocked()) {
42
- return;
43
- }
40
+ if (!getSourceContext()) return;
44
41
 
45
42
  const untrackedPath = StringPrototypeSlice.call(` ${args[0]}`, 1);
46
43
  args[0] = untrackedPath;
@@ -51,9 +48,7 @@ module.exports = function (core) {
51
48
  }
52
49
 
53
50
  send.install = function () {
54
- depHooks.resolve({ name: 'send' }, (sendModule) =>
55
- patchSendModule(sendModule)
56
- );
51
+ depHooks.resolve({ name: 'send' }, patchSendModule);
57
52
  };
58
53
 
59
54
  return send;
@@ -14,9 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const {
18
- DataflowTag: { SQL_ENCODED }
19
- } = require('@contrast/common');
17
+ const { DataflowTag: { SQL_ENCODED } } = require('@contrast/common');
20
18
  const { patchType } = require('../../common');
21
19
 
22
20
  const DIALECTS = [
@@ -33,6 +31,7 @@ const DIALECTS = [
33
31
  module.exports = function(core) {
34
32
  const {
35
33
  assess: {
34
+ getSourceContext,
36
35
  eventFactory: { createPropagationEvent },
37
36
  dataflow: { tracker }
38
37
  },
@@ -53,7 +52,7 @@ module.exports = function(core) {
53
52
  patchType,
54
53
  post(data) {
55
54
  const strInfo = tracker.getData(data.result);
56
- if (!strInfo) return;
55
+ if (!strInfo || !getSourceContext()) return;
57
56
 
58
57
  const { value } = strInfo;
59
58
  const event = createPropagationEvent({
@@ -17,16 +17,17 @@
17
17
 
18
18
  const {
19
19
  isString,
20
+ primordials: { StringPrototypeMatchAll },
20
21
  DataflowTag: { SQL_ENCODED },
21
22
  } = require('@contrast/common');
22
23
  const { patchType, createModuleLabel } = require('../../common');
23
24
 
24
25
  module.exports = function(core) {
25
26
  const {
26
- scopes: { sources, instrumentation },
27
27
  patcher,
28
28
  depHooks,
29
29
  assess: {
30
+ getSourceContext,
30
31
  eventFactory: { createPropagationEvent },
31
32
  dataflow: { tracker },
32
33
  },
@@ -45,7 +46,7 @@ module.exports = function(core) {
45
46
 
46
47
  function getFormatNamedParametersPositions(str) {
47
48
  const regex = /:(\w+)(?=[\s,;)]|$)/g;
48
- const matches = str.matchAll(regex);
49
+ const matches = StringPrototypeMatchAll.call(str, regex);
49
50
 
50
51
  return Array.from(matches, (match) => ({ [match[1]]: match.index }));
51
52
  }
@@ -68,8 +69,7 @@ module.exports = function(core) {
68
69
  !result ||
69
70
  !args[0] ||
70
71
  !isString(args[0]) ||
71
- !sources.getStore()?.assess ||
72
- instrumentation.isLocked()
72
+ !getSourceContext()
73
73
  ) return;
74
74
 
75
75
  const argInfo = tracker.getData(args[0]);
@@ -123,10 +123,8 @@ module.exports = function(core) {
123
123
  !result ||
124
124
  !args[0] ||
125
125
  !isString(args[0]) ||
126
- !sources.getStore()?.assess ||
127
- instrumentation.isLocked()
128
- )
129
- return;
126
+ !getSourceContext()
127
+ ) return;
130
128
 
131
129
  const resultInfo = tracker.getData(result);
132
130
  if (!resultInfo) {
@@ -217,10 +215,8 @@ module.exports = function(core) {
217
215
  !result ||
218
216
  !args[0] ||
219
217
  !isString(args[0]) ||
220
- !sources.getStore()?.assess ||
221
- instrumentation.isLocked()
222
- )
223
- return;
218
+ !getSourceContext()
219
+ ) return;
224
220
 
225
221
  const resultInfo = tracker.getData(result);
226
222
  if (!resultInfo) {
@@ -40,7 +40,6 @@ describe('assess dataflow propagation sequelize sql-string', function () {
40
40
  core.depHooks.resolve.yield(mockSequelizeSqlString);
41
41
  });
42
42
 
43
-
44
43
  afterEach(function () {
45
44
  core.assess.dataflow.propagation.stringInstrumentation.uninstall();
46
45
  sinon.resetHistory();
@@ -96,7 +95,6 @@ describe('assess dataflow propagation sequelize sql-string', function () {
96
95
  describe(method, function () {
97
96
  it('sanitizes correctly', function () {
98
97
  simulateRequestScope(function () {
99
-
100
98
  const notTrackedResult = mockSequelizeSqlString[method](...notTrackedArgs);
101
99
  const notTrackedStrInfo = tracker.getData(notTrackedResult);
102
100
 
@@ -109,20 +107,11 @@ describe('assess dataflow propagation sequelize sql-string', function () {
109
107
  });
110
108
 
111
109
  if (!onlySanitizeCheck) {
112
- it('will not sanitize if there is no assess context', function () {
110
+ it('will not sanitize if there is no assess policy in request context', function () {
113
111
  simulateRequestScope(function () {
114
112
  const result = mockSequelizeSqlString[method](...args.map(a => a()));
115
113
  expect(tracker.getData(result)).to.be.null;
116
- }, {});
117
- });
118
-
119
- it('will not sanitize if there instrumentation is locked', function () {
120
- simulateRequestScope(function () {
121
- core.scopes.instrumentation.run({ lock: true }, function () {
122
- const result = mockSequelizeSqlString[method](...args.map(a => a()));
123
- expect(tracker.getData(result)?.tags || {}).to.not.haveOwnProperty(SQL_ENCODED);
124
- });
125
- });
114
+ }, { assess: { policy: null } });
126
115
  });
127
116
  }
128
117
  });