@contrast/assess 1.41.0 → 1.42.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 (162) hide show
  1. package/lib/crypto-analysis/install/crypto.js +4 -5
  2. package/lib/crypto-analysis/install/crypto.test.js +1 -1
  3. package/lib/crypto-analysis/install/math.js +2 -4
  4. package/lib/dataflow/propagation/install/JSON/parse.js +2 -3
  5. package/lib/dataflow/propagation/install/JSON/stringify.js +3 -4
  6. package/lib/dataflow/propagation/install/array-prototype-join.js +2 -3
  7. package/lib/dataflow/propagation/install/buffer.js +3 -4
  8. package/lib/dataflow/propagation/install/contrast-methods/add.js +2 -3
  9. package/lib/dataflow/propagation/install/contrast-methods/number.js +2 -3
  10. package/lib/dataflow/propagation/install/contrast-methods/string.js +2 -3
  11. package/lib/dataflow/propagation/install/contrast-methods/tag.js +2 -3
  12. package/lib/dataflow/propagation/install/decode-uri-component.js +2 -3
  13. package/lib/dataflow/propagation/install/ejs/escape-xml.js +3 -4
  14. package/lib/dataflow/propagation/install/ejs/template.js +3 -4
  15. package/lib/dataflow/propagation/install/ejs/template.test.js +1 -1
  16. package/lib/dataflow/propagation/install/encode-uri.js +2 -3
  17. package/lib/dataflow/propagation/install/escape-html.js +3 -4
  18. package/lib/dataflow/propagation/install/escape.js +2 -3
  19. package/lib/dataflow/propagation/install/fastify-send.js +3 -3
  20. package/lib/dataflow/propagation/install/fastify-send.test.js +1 -3
  21. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +3 -4
  22. package/lib/dataflow/propagation/install/isnumeric-0.js +1 -1
  23. package/lib/dataflow/propagation/install/joi/any.js +1 -1
  24. package/lib/dataflow/propagation/install/joi/any.test.js +1 -1
  25. package/lib/dataflow/propagation/install/joi/array.test.js +5 -5
  26. package/lib/dataflow/propagation/install/joi/boolean.js +3 -3
  27. package/lib/dataflow/propagation/install/joi/boolean.test.js +1 -1
  28. package/lib/dataflow/propagation/install/joi/expression.js +3 -3
  29. package/lib/dataflow/propagation/install/joi/expression.test.js +1 -1
  30. package/lib/dataflow/propagation/install/joi/index.js +3 -3
  31. package/lib/dataflow/propagation/install/joi/keys.js +3 -3
  32. package/lib/dataflow/propagation/install/joi/number.js +3 -3
  33. package/lib/dataflow/propagation/install/joi/number.test.js +1 -1
  34. package/lib/dataflow/propagation/install/joi/object.js +1 -1
  35. package/lib/dataflow/propagation/install/joi/object.test.js +1 -1
  36. package/lib/dataflow/propagation/install/joi/ref.test.js +4 -4
  37. package/lib/dataflow/propagation/install/joi/string-schema.js +4 -4
  38. package/lib/dataflow/propagation/install/joi/string-schema.test.js +4 -4
  39. package/lib/dataflow/propagation/install/joi/values.js +3 -3
  40. package/lib/dataflow/propagation/install/mongoose/schema-map.js +4 -4
  41. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +4 -4
  42. package/lib/dataflow/propagation/install/mongoose/schema-string.js +4 -4
  43. package/lib/dataflow/propagation/install/mustache-escape.js +3 -4
  44. package/lib/dataflow/propagation/install/mustache-escape.test.js +1 -1
  45. package/lib/dataflow/propagation/install/mysql-connection-escape.js +22 -14
  46. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +1 -1
  47. package/lib/dataflow/propagation/install/parse-int.js +2 -3
  48. package/lib/dataflow/propagation/install/path/basename.js +3 -4
  49. package/lib/dataflow/propagation/install/path/dirname.js +3 -4
  50. package/lib/dataflow/propagation/install/path/extname.js +3 -4
  51. package/lib/dataflow/propagation/install/path/format.js +3 -4
  52. package/lib/dataflow/propagation/install/path/join-and-resolve.js +3 -4
  53. package/lib/dataflow/propagation/install/path/normalize.js +4 -5
  54. package/lib/dataflow/propagation/install/path/parse.js +3 -4
  55. package/lib/dataflow/propagation/install/path/relative.js +4 -5
  56. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +3 -4
  57. package/lib/dataflow/propagation/install/pug/index.js +3 -4
  58. package/lib/dataflow/propagation/install/pug-runtime-escape.js +3 -4
  59. package/lib/dataflow/propagation/install/querystring/escape.js +3 -4
  60. package/lib/dataflow/propagation/install/querystring/escape.test.js +1 -1
  61. package/lib/dataflow/propagation/install/querystring/parse.js +3 -4
  62. package/lib/dataflow/propagation/install/querystring/parse.test.js +1 -1
  63. package/lib/dataflow/propagation/install/querystring/stringify.js +3 -4
  64. package/lib/dataflow/propagation/install/querystring/stringify.test.js +1 -1
  65. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +2 -3
  66. package/lib/dataflow/propagation/install/send.js +3 -3
  67. package/lib/dataflow/propagation/install/sequelize/query-generator.js +3 -3
  68. package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +2 -1
  69. package/lib/dataflow/propagation/install/sequelize/sql-string.js +5 -5
  70. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -3
  71. package/lib/dataflow/propagation/install/string/concat.js +2 -3
  72. package/lib/dataflow/propagation/install/string/format-methods.js +2 -3
  73. package/lib/dataflow/propagation/install/string/html-methods.js +3 -4
  74. package/lib/dataflow/propagation/install/string/match-all.js +2 -3
  75. package/lib/dataflow/propagation/install/string/match.js +2 -3
  76. package/lib/dataflow/propagation/install/string/replace.js +2 -3
  77. package/lib/dataflow/propagation/install/string/slice.js +2 -3
  78. package/lib/dataflow/propagation/install/string/split.js +2 -3
  79. package/lib/dataflow/propagation/install/string/substring.js +2 -3
  80. package/lib/dataflow/propagation/install/string/trim.js +2 -3
  81. package/lib/dataflow/propagation/install/unescape.js +2 -3
  82. package/lib/dataflow/propagation/install/url/domain-parsers.js +3 -4
  83. package/lib/dataflow/propagation/install/url/parse.js +3 -4
  84. package/lib/dataflow/propagation/install/url/parse.test.js +2 -2
  85. package/lib/dataflow/propagation/install/url/searchParams.js +3 -4
  86. package/lib/dataflow/propagation/install/url/url.js +3 -4
  87. package/lib/dataflow/propagation/install/util-format.js +3 -4
  88. package/lib/dataflow/propagation/install/validator/hooks.js +9 -9
  89. package/lib/dataflow/sinks/install/child-process.js +5 -6
  90. package/lib/dataflow/sinks/install/eval.js +2 -3
  91. package/lib/dataflow/sinks/install/express/reflected-xss.js +2 -3
  92. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +2 -3
  93. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +3 -4
  94. package/lib/dataflow/sinks/install/fs.js +4 -5
  95. package/lib/dataflow/sinks/install/fs.test.js +2 -2
  96. package/lib/dataflow/sinks/install/function.js +2 -3
  97. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.js +3 -4
  98. package/lib/dataflow/sinks/install/http/request.js +3 -4
  99. package/lib/dataflow/sinks/install/http/request.test.js +2 -2
  100. package/lib/dataflow/sinks/install/http/server-response.js +5 -6
  101. package/lib/dataflow/sinks/install/http/server-response.test.js +3 -3
  102. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +3 -4
  103. package/lib/dataflow/sinks/install/libxmljs.js +4 -5
  104. package/lib/dataflow/sinks/install/libxmljs.test.js +2 -2
  105. package/lib/dataflow/sinks/install/marsdb.js +3 -4
  106. package/lib/dataflow/sinks/install/marsdb.test.js +3 -3
  107. package/lib/dataflow/sinks/install/mongodb.js +3 -4
  108. package/lib/dataflow/sinks/install/mongodb.test.js +2 -6
  109. package/lib/dataflow/sinks/install/mssql.js +4 -5
  110. package/lib/dataflow/sinks/install/mssql.test.js +2 -2
  111. package/lib/dataflow/sinks/install/mysql.js +4 -5
  112. package/lib/dataflow/sinks/install/mysql.test.js +2 -11
  113. package/lib/dataflow/sinks/install/node-serialize.js +3 -4
  114. package/lib/dataflow/sinks/install/node-serialize.test.js +1 -3
  115. package/lib/dataflow/sinks/install/postgres.js +5 -6
  116. package/lib/dataflow/sinks/install/postgres.test.js +3 -9
  117. package/lib/dataflow/sinks/install/restify.js +3 -4
  118. package/lib/dataflow/sinks/install/restify.test.js +3 -5
  119. package/lib/dataflow/sinks/install/sequelize.js +3 -4
  120. package/lib/dataflow/sinks/install/sqlite3.js +3 -4
  121. package/lib/dataflow/sinks/install/vm.js +3 -4
  122. package/lib/dataflow/sources/install/body-parser1.js +2 -3
  123. package/lib/dataflow/sources/install/busboy.js +3 -4
  124. package/lib/dataflow/sources/install/busboy.test.js +2 -2
  125. package/lib/dataflow/sources/install/cookie-parser1.js +2 -3
  126. package/lib/dataflow/sources/install/express/params.js +1 -2
  127. package/lib/dataflow/sources/install/express/parsedUrl.js +1 -2
  128. package/lib/dataflow/sources/install/express/parsedUrl.test.js +9 -8
  129. package/lib/dataflow/sources/install/fastify/fastify.js +2 -3
  130. package/lib/dataflow/sources/install/fastify/fastify.test.js +3 -6
  131. package/lib/dataflow/sources/install/formidable1.js +2 -3
  132. package/lib/dataflow/sources/install/hapi/hapi.js +1 -2
  133. package/lib/dataflow/sources/install/http.js +2 -3
  134. package/lib/dataflow/sources/install/http.test.js +2 -2
  135. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +3 -5
  136. package/lib/dataflow/sources/install/koa/koa-multer.js +3 -4
  137. package/lib/dataflow/sources/install/koa/koa-multer.test.js +1 -1
  138. package/lib/dataflow/sources/install/koa/koa-routers.js +3 -4
  139. package/lib/dataflow/sources/install/koa/koa2.js +2 -4
  140. package/lib/dataflow/sources/install/multer1.js +2 -3
  141. package/lib/dataflow/sources/install/multer1.test.js +1 -3
  142. package/lib/dataflow/sources/install/qs6.js +2 -3
  143. package/lib/dataflow/sources/install/querystring.js +2 -3
  144. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +2 -3
  145. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +1 -1
  146. package/lib/dataflow/sources/install/restify/jsonBodyParser.js +2 -3
  147. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +1 -1
  148. package/lib/dataflow/sources/install/restify/router.js +2 -3
  149. package/lib/dataflow/sources/install/restify/router.test.js +1 -1
  150. package/lib/get-source-context.js +58 -39
  151. package/lib/get-source-context.test.js +103 -78
  152. package/lib/index.d.ts +3 -9
  153. package/lib/response-scanning/install/http.js +3 -3
  154. package/lib/response-scanning/install/http.test.js +2 -2
  155. package/lib/session-configuration/install/express-session.js +1 -1
  156. package/lib/session-configuration/install/express-session.test.js +1 -3
  157. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  158. package/lib/session-configuration/install/fastify-cookie.test.js +1 -3
  159. package/lib/session-configuration/install/koa.js +1 -1
  160. package/lib/session-configuration/install/koa.test.js +1 -1
  161. package/package.json +11 -11
  162. package/lib/constants.js +0 -26
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
19
  const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
21
20
  const { patchType } = require('../../common');
22
21
 
@@ -25,7 +24,7 @@ module.exports = function(core) {
25
24
  scopes,
26
25
  patcher,
27
26
  assess: {
28
- getSourceContext,
27
+ getPropagatorContext,
29
28
  eventFactory: { createPropagationEvent },
30
29
  dataflow: {
31
30
  tracker,
@@ -87,7 +86,7 @@ module.exports = function(core) {
87
86
  !args.length ||
88
87
  typeof obj !== 'string' ||
89
88
  (args.length === 1 && !args[0]) ||
90
- !getSourceContext(PROPAGATOR)
89
+ !getPropagatorContext()
91
90
  ) return origFn();
92
91
  const objInfo = tracker.getData(obj);
93
92
 
@@ -25,7 +25,6 @@ const {
25
25
  StringPrototypeReplace
26
26
  }
27
27
  } = require('@contrast/common');
28
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
29
28
  const {
30
29
  createSubsetTags,
31
30
  createAppendTags,
@@ -37,7 +36,7 @@ module.exports = function(core) {
37
36
  const {
38
37
  patcher,
39
38
  assess: {
40
- getSourceContext,
39
+ getPropagatorContext,
41
40
  eventFactory: { createPropagationEvent },
42
41
  dataflow: { tracker }
43
42
  },
@@ -152,7 +151,7 @@ module.exports = function(core) {
152
151
  patchType,
153
152
  usePerf: 'sync',
154
153
  pre(data) {
155
- if (!getSourceContext(PROPAGATOR)) return;
154
+ if (!getPropagatorContext()) return;
156
155
 
157
156
  // setup state
158
157
  data._objInfo = tracker.getData(data.obj);
@@ -14,7 +14,6 @@
14
14
  */
15
15
  'use strict';
16
16
  const { primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
17
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
18
17
  const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
19
18
  const { patchType } = require('../../common');
20
19
 
@@ -22,7 +21,7 @@ module.exports = function(core) {
22
21
  const {
23
22
  patcher,
24
23
  assess: {
25
- getSourceContext,
24
+ getPropagatorContext,
26
25
  eventFactory: { createPropagationEvent },
27
26
  dataflow: { tracker }
28
27
  }
@@ -57,7 +56,7 @@ module.exports = function(core) {
57
56
  usePerf: 'sync',
58
57
  post(data) {
59
58
  const { name, args: origArgs, obj, result, hooked, orig } = data;
60
- if (!result || !getSourceContext(PROPAGATOR)) return;
59
+ if (!result || !getPropagatorContext()) return;
61
60
 
62
61
  const objInfo = tracker.getData(obj);
63
62
  if (!objInfo) return;
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
19
  const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
21
20
  const { patchType } = require('../../common');
22
21
 
@@ -24,7 +23,7 @@ module.exports = function(core) {
24
23
  const {
25
24
  patcher,
26
25
  assess: {
27
- getSourceContext,
26
+ getPropagatorContext,
28
27
  eventFactory,
29
28
  dataflow: { tracker }
30
29
  }
@@ -47,7 +46,7 @@ module.exports = function(core) {
47
46
  result.length === 0 ||
48
47
  typeof obj !== 'string' ||
49
48
  (origArgs.length === 1 && origArgs[0] == null) ||
50
- !getSourceContext(PROPAGATOR)
49
+ !getPropagatorContext()
51
50
  ) return;
52
51
 
53
52
  const objInfo = tracker.getData(obj);
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
19
  const { createSubsetTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
21
20
  const { patchType } = require('../../common');
22
21
 
@@ -24,7 +23,7 @@ module.exports = function(core) {
24
23
  const {
25
24
  patcher,
26
25
  assess: {
27
- getSourceContext,
26
+ getPropagatorContext,
28
27
  eventFactory: { createPropagationEvent },
29
28
  dataflow: { tracker }
30
29
  }
@@ -65,7 +64,7 @@ module.exports = function(core) {
65
64
  usePerf: 'sync',
66
65
  post(data) {
67
66
  const { obj, args: origArgs, result, name, hooked, orig } = data;
68
- if (!result || !getSourceContext(PROPAGATOR)) return;
67
+ if (!result || !getPropagatorContext()) return;
69
68
 
70
69
  const objInfo = tracker.getData(obj);
71
70
  if (!objInfo) return;
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
18
  const { createSubsetTags } = require('../../../tag-utils');
20
19
  const { patchType } = require('../../common');
21
20
 
@@ -23,7 +22,7 @@ module.exports = function(core) {
23
22
  const {
24
23
  patcher,
25
24
  assess: {
26
- getSourceContext,
25
+ getPropagatorContext,
27
26
  eventFactory: { createPropagationEvent },
28
27
  dataflow: { tracker }
29
28
  }
@@ -33,7 +32,7 @@ module.exports = function(core) {
33
32
  return function(data) {
34
33
  const { obj, result, hooked, orig } = data;
35
34
 
36
- if (!result?.length || !getSourceContext(PROPAGATOR)) {
35
+ if (!result?.length || !getPropagatorContext()) {
37
36
  return;
38
37
  }
39
38
  const rInfo = tracker.getData(result);
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { DataflowTag: { WEAK_URL_ENCODED } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
19
  const { createFullLengthCopyTags } = require('../../tag-utils');
21
20
  const { patchType, createObjectLabel } = require('../common');
22
21
 
@@ -24,7 +23,7 @@ module.exports = function(core) {
24
23
  const {
25
24
  patcher,
26
25
  assess: {
27
- getSourceContext,
26
+ getPropagatorContext,
28
27
  eventFactory: { createPropagationEvent },
29
28
  dataflow: { tracker }
30
29
  }
@@ -40,7 +39,7 @@ module.exports = function(core) {
40
39
  usePerf: 'sync',
41
40
  post(data) {
42
41
  const { args, result, hooked, orig } = data;
43
- if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
42
+ if (!result || !args[0] || !getPropagatorContext()) return;
44
43
 
45
44
  const argInfo = tracker.getData(args[0]);
46
45
 
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
18
  const { createFullLengthCopyTags } = require('../../../tag-utils');
20
19
  const { patchType, createModuleLabel } = require('../../common');
21
20
 
@@ -24,7 +23,7 @@ module.exports = function(core) {
24
23
  patcher,
25
24
  depHooks,
26
25
  assess: {
27
- getSourceContext,
26
+ getPropagatorContext,
28
27
  eventFactory: { createPropagationEvent },
29
28
  dataflow: { tracker }
30
29
  }
@@ -32,7 +31,7 @@ module.exports = function(core) {
32
31
 
33
32
  return core.assess.dataflow.propagation.urlInstrumentation.domainParsers = {
34
33
  install() {
35
- depHooks.resolve({ name: 'url' }, (url, version) => {
34
+ depHooks.resolve({ name: 'url', version: '*' }, (url, version) => {
36
35
  ['domainToASCII', 'domainToUnicode'].forEach((method) => {
37
36
  const name = `url.${method}`;
38
37
 
@@ -42,7 +41,7 @@ module.exports = function(core) {
42
41
  usePerf: 'sync',
43
42
  post(data) {
44
43
  const { args, result, hooked, orig } = data;
45
- if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
44
+ if (!result || !args[0] || !getPropagatorContext()) return;
46
45
 
47
46
  const argInfo = tracker.getData(args[0]);
48
47
 
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
18
  const { patchType } = require('../../common');
20
19
 
21
20
  module.exports = function(core) {
@@ -23,7 +22,7 @@ module.exports = function(core) {
23
22
  patcher,
24
23
  depHooks,
25
24
  assess: {
26
- getSourceContext,
25
+ getPropagatorContext,
27
26
  inspect, // TODO NODE-3455: remove
28
27
  eventFactory: { createPropagationEvent },
29
28
  dataflow: { tracker }
@@ -80,7 +79,7 @@ module.exports = function(core) {
80
79
 
81
80
  return core.assess.dataflow.propagation.urlInstrumentation.parse = {
82
81
  install() {
83
- depHooks.resolve({ name: 'url' }, (url) => {
82
+ depHooks.resolve({ name: 'url', version: '*' }, (url) => {
84
83
 
85
84
  const name = 'url.parse';
86
85
 
@@ -90,7 +89,7 @@ module.exports = function(core) {
90
89
  usePerf: 'sync',
91
90
  post(data) {
92
91
  const { args, result, hooked, orig } = data;
93
- if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
92
+ if (!result || !args[0] || !getPropagatorContext()) return;
94
93
 
95
94
  const [url, parseQueryString] = args;
96
95
  const argInfo = tracker.getData(url);
@@ -35,8 +35,8 @@ describe('assess dataflow propagation url.parse', function () {
35
35
  core.assess.dataflow.propagation.querystringInstrumentation.parse.install();
36
36
  core.assess.dataflow.propagation.urlInstrumentation.parse.install();
37
37
 
38
- core.depHooks.resolve.withArgs({ name: 'url' }).yield(url);
39
- core.depHooks.resolve.withArgs({ name: 'querystring' }).yield(querystring);
38
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'url' })).yield(url);
39
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'querystring' })).yield(querystring);
40
40
 
41
41
  matchURL = {
42
42
  href: 'https://user:pass@foo.com:3000/path?query=input#hash',
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { isString, primordials: { StringPrototypeConcat, StringPrototypeReplaceAll } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
19
  const { createAppendTags } = require('../../../tag-utils');
21
20
  const { patchType } = require('../../common');
22
21
 
@@ -26,7 +25,7 @@ module.exports = function(core) {
26
25
  depHooks,
27
26
  assess: {
28
27
  inspect, // TODO NODE-3455: remove
29
- getSourceContext,
28
+ getPropagatorContext,
30
29
  eventFactory: { createPropagationEvent },
31
30
  dataflow: { tracker }
32
31
  }
@@ -60,7 +59,7 @@ module.exports = function(core) {
60
59
 
61
60
  return core.assess.dataflow.propagation.urlInstrumentation.searchParams = {
62
61
  install() {
63
- depHooks.resolve({ name: 'url' }, (url) => {
62
+ depHooks.resolve({ name: 'url', version: '*' }, (url) => {
64
63
  const name = 'url.URLSearchParams';
65
64
 
66
65
  patcher.patch(url, 'URLSearchParams', {
@@ -69,7 +68,7 @@ module.exports = function(core) {
69
68
  usePerf: 'sync',
70
69
  post(data) {
71
70
  const { args, obj, result } = data;
72
- if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
71
+ if (!result || !args[0] || !getPropagatorContext()) return;
73
72
 
74
73
  const [params] = args;
75
74
 
@@ -15,7 +15,6 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
18
  const { patchType } = require('../../common');
20
19
 
21
20
  const { primordials: { StringPrototypeSplit } } = require('@contrast/common');
@@ -25,7 +24,7 @@ module.exports = function(core) {
25
24
  patcher,
26
25
  depHooks,
27
26
  assess: {
28
- getSourceContext,
27
+ getPropagatorContext,
29
28
  inspect, // TODO NODE-3455: remove
30
29
  eventFactory: { createPropagationEvent },
31
30
  dataflow: { tracker }
@@ -86,7 +85,7 @@ module.exports = function(core) {
86
85
 
87
86
  return core.assess.dataflow.propagation.urlInstrumentation.url = {
88
87
  install() {
89
- depHooks.resolve({ name: 'url' }, (url) => {
88
+ depHooks.resolve({ name: 'url', version: '*' }, (url) => {
90
89
  const { URLSearchParams } = url;
91
90
  const name = 'url.URL';
92
91
  patcher.patch(url, 'URL', {
@@ -95,7 +94,7 @@ module.exports = function(core) {
95
94
  usePerf: 'sync',
96
95
  post(data) {
97
96
  const { args, result } = data;
98
- if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
97
+ if (!result || !args[0] || !getPropagatorContext()) return;
99
98
 
100
99
  const [input, basename] = args;
101
100
  let url = input;
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { isString, primordials: { StringPrototypeMatch, StringPrototypeToLowerCase } } = require('@contrast/common');
19
- const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
19
  const { createAppendTags } = require('../../tag-utils');
21
20
  const { patchType } = require('../common');
22
21
 
@@ -25,7 +24,7 @@ module.exports = function(core) {
25
24
  patcher,
26
25
  depHooks,
27
26
  assess: {
28
- getSourceContext,
27
+ getPropagatorContext,
29
28
  eventFactory: { createPropagationEvent },
30
29
  dataflow: { tracker }
31
30
  }
@@ -33,7 +32,7 @@ module.exports = function(core) {
33
32
 
34
33
  return core.assess.dataflow.propagation.utilFormat = {
35
34
  install() {
36
- depHooks.resolve({ name: 'util' }, (util) => {
35
+ depHooks.resolve({ name: 'util', version: '*' }, (util) => {
37
36
  const name = 'util.format';
38
37
 
39
38
  return patcher.patch(util, 'format', {
@@ -42,7 +41,7 @@ module.exports = function(core) {
42
41
  usePerf: 'sync',
43
42
  post(data) {
44
43
  const { args, result, hooked, orig } = data;
45
- if (!result || !args[0] || !isString(args[0]) || !getSourceContext(PROPAGATOR)) return;
44
+ if (!result || !args[0] || !isString(args[0]) || !getPropagatorContext()) return;
46
45
 
47
46
  let idx = 0;
48
47
  let newTags = {};
@@ -26,7 +26,7 @@ module.exports = function (core) {
26
26
  depHooks,
27
27
  patcher,
28
28
  assess: {
29
- getSourceContext,
29
+ getPropagatorContext,
30
30
  eventFactory: { createPropagationEvent },
31
31
  dataflow: { tracker }
32
32
  }
@@ -64,7 +64,7 @@ module.exports = function (core) {
64
64
  install() {
65
65
  for (const validator in validators) {
66
66
  depHooks.resolve(
67
- { name: 'validator', file: `lib/${validator}` },
67
+ { name: 'validator', version: '<14', file: `lib/${validator}` },
68
68
  (index) => {
69
69
  const name = `validator.${validator}`;
70
70
  return patcher.patch(...getPatcherArgs(index), {
@@ -76,7 +76,7 @@ module.exports = function (core) {
76
76
  if (
77
77
  data.result &&
78
78
  (!matches || (matches && core.config.assess.trust_custom_validators)) &&
79
- getSourceContext()
79
+ getPropagatorContext()
80
80
  ) {
81
81
  const trackingData = tracker.getData(data.args[0]);
82
82
  if (trackingData) {
@@ -102,13 +102,13 @@ module.exports = function (core) {
102
102
 
103
103
  untrackers.forEach((untracker) => {
104
104
  depHooks.resolve(
105
- { name: 'validator', file: `lib/${untracker}` },
105
+ { name: 'validator', version: '<14', file: `lib/${untracker}` },
106
106
  (index) => patcher.patch(...getPatcherArgs(index), {
107
107
  name: `validator.${untracker}`,
108
108
  patchType,
109
109
  usePerf: 'sync',
110
110
  post(data) {
111
- if (data.result && getSourceContext()) {
111
+ if (data.result && getPropagatorContext()) {
112
112
  const trackingData = tracker.getData(data.args[0]);
113
113
  if (trackingData) {
114
114
  tracker.untrack(data.args[0]);
@@ -120,12 +120,12 @@ module.exports = function (core) {
120
120
 
121
121
  for (const sanitizer in sanitizers) {
122
122
  depHooks.resolve(
123
- { name: 'validator', file: `lib/${sanitizer}` },
123
+ { name: 'validator', version: '<14', file: `lib/${sanitizer}` },
124
124
  (index) => patcher.patch(...getPatcherArgs(index), {
125
125
  name: `validator.${sanitizer}`,
126
126
  patchType,
127
127
  post(data) {
128
- if (!getSourceContext()) return;
128
+ if (!getPropagatorContext()) return;
129
129
  const trackingData = tracker.getData(data.args[0]);
130
130
  if (trackingData) {
131
131
  const newTags = {};
@@ -153,12 +153,12 @@ module.exports = function (core) {
153
153
 
154
154
  for (const method in custom) {
155
155
  depHooks.resolve(
156
- { name: 'validator', file: `lib/${method}` },
156
+ { name: 'validator', version: '<14', file: `lib/${method}` },
157
157
  (index) => patcher.patch(...getPatcherArgs(index), {
158
158
  name: `validator.${method}`,
159
159
  patchType,
160
160
  post(data) {
161
- if (!getSourceContext()) return;
161
+ if (!getPropagatorContext()) return;
162
162
 
163
163
  const options = data.args[1];
164
164
  const trackingData = tracker.getData(data.args[0]);
@@ -20,7 +20,6 @@ const {
20
20
  Rule: { CMD_INJECTION: ruleId },
21
21
  isString,
22
22
  } = require('@contrast/common');
23
- const { InstrumentationType: { RULE } } = require('../../../constants');
24
23
  const { patchType } = require('../common');
25
24
 
26
25
  /**
@@ -35,7 +34,7 @@ module.exports = function(core) {
35
34
  patcher,
36
35
  assess: {
37
36
  inspect, // TODO NODE-3455: remove
38
- getSourceContext,
37
+ getSinkContext,
39
38
  eventFactory: { createSinkEvent },
40
39
  dataflow: {
41
40
  tracker,
@@ -192,14 +191,14 @@ module.exports = function(core) {
192
191
 
193
192
  core.assess.dataflow.sinks.cmdInjection = {
194
193
  install() {
195
- depHooks.resolve({ name: 'child_process' }, (cp) => {
194
+ depHooks.resolve({ name: 'child_process', version: '*' }, (cp) => {
196
195
  ['spawn', 'spawnSync'].forEach((method) => {
197
196
  const name = `child_process.${method}`;
198
197
  patcher.patch(cp, method, {
199
198
  name,
200
199
  patchType,
201
200
  pre(data) {
202
- if (!getSourceContext(RULE, ruleId)) return;
201
+ if (!getSinkContext(ruleId)) return;
203
202
 
204
203
  const [command] = data.args;
205
204
  if (!command || !isString(command)) return;
@@ -239,7 +238,7 @@ module.exports = function(core) {
239
238
  name,
240
239
  patchType,
241
240
  pre(data) {
242
- if (!getSourceContext(RULE, ruleId)) return;
241
+ if (!getSinkContext(ruleId)) return;
243
242
 
244
243
  const [command, secondArg, thirdArg] = data.args;
245
244
  if (!command || !isString(command)) return;
@@ -263,7 +262,7 @@ module.exports = function(core) {
263
262
  name,
264
263
  patchType,
265
264
  pre(data) {
266
- if (!getSourceContext(RULE, ruleId)) return;
265
+ if (!getSinkContext(ruleId)) return;
267
266
 
268
267
  const [command] = data.args;
269
268
  if (!command || !isString(command)) return;
@@ -27,7 +27,6 @@ const {
27
27
  },
28
28
  Rule: { UNSAFE_CODE_EXECUTION: ruleId },
29
29
  } = require('@contrast/common');
30
- const { InstrumentationType: { RULE } } = require('../../../constants');
31
30
  const { patchType, filterSafeTags } = require('../common');
32
31
 
33
32
  const safeTags = [
@@ -53,7 +52,7 @@ module.exports = function (core) {
53
52
  logger,
54
53
  patcher,
55
54
  assess: {
56
- getSourceContext,
55
+ getSinkContext,
57
56
  eventFactory: { createSinkEvent },
58
57
  dataflow: {
59
58
  tracker,
@@ -73,7 +72,7 @@ module.exports = function (core) {
73
72
  name: 'global.ContrastMethods.eval',
74
73
  patchType,
75
74
  pre({ args, orig }) {
76
- if (!getSourceContext(RULE, ruleId)) return;
75
+ if (!getSinkContext(ruleId)) return;
77
76
 
78
77
  const script = args[0];
79
78
  if (!script || !isString(script)) return;
@@ -31,7 +31,6 @@ const {
31
31
  isString
32
32
  } = require('@contrast/common');
33
33
  const { patchType, filterSafeTags } = require('../../common');
34
- const { InstrumentationType: { RULE } } = require('../../../../constants');
35
34
 
36
35
  /**
37
36
  * @param {{
@@ -47,7 +46,7 @@ module.exports = function(core) {
47
46
  patcher,
48
47
  config,
49
48
  assess: {
50
- getSourceContext,
49
+ getSinkContext,
51
50
  eventFactory: { createSinkEvent },
52
51
  dataflow: {
53
52
  tracker,
@@ -78,7 +77,7 @@ module.exports = function(core) {
78
77
  name,
79
78
  patchType,
80
79
  around: (next, data) => {
81
- const sourceContext = getSourceContext(RULE, ruleId);
80
+ const sourceContext = getSinkContext(ruleId);
82
81
  if (!sourceContext) return next();
83
82
 
84
83
  const { contentType } = sourceContext.responseData;
@@ -27,7 +27,6 @@ const {
27
27
  },
28
28
  isString
29
29
  } = require('@contrast/common');
30
- const { InstrumentationType: { RULE } } = require('../../../../constants');
31
30
  const { createSubsetTags } = require('../../../tag-utils');
32
31
  const { patchType, filterSafeTags } = require('../../common');
33
32
 
@@ -46,7 +45,7 @@ module.exports = function(core) {
46
45
  config,
47
46
  assess: {
48
47
  inspect, // TODO NODE-3455: remove
49
- getSourceContext,
48
+ getSinkContext,
50
49
  eventFactory: { createSinkEvent },
51
50
  dataflow: {
52
51
  tracker,
@@ -73,7 +72,7 @@ module.exports = function(core) {
73
72
  name: 'Express.Response.location',
74
73
  patchType,
75
74
  pre: (data) => {
76
- if (!getSourceContext(RULE, ruleId)) return;
75
+ if (!getSinkContext(ruleId)) return;
77
76
 
78
77
  let [url] = data.args;
79
78
  if (url === 'back') {
@@ -27,7 +27,6 @@ const {
27
27
  },
28
28
  isString
29
29
  } = require('@contrast/common');
30
- const { InstrumentationType: { RULE } } = require('../../../../constants');
31
30
  const { createSubsetTags } = require('../../../tag-utils');
32
31
  const { filterSafeTags, patchType } = require('../../common');
33
32
 
@@ -65,7 +64,7 @@ module.exports = function(core) {
65
64
  patcher,
66
65
  assess: {
67
66
  inspect, // TODO NODE-3455: remove
68
- getSourceContext,
67
+ getSinkContext,
69
68
  eventFactory: { createSinkEvent },
70
69
  dataflow: {
71
70
  tracker,
@@ -87,12 +86,12 @@ module.exports = function(core) {
87
86
 
88
87
  unvalidatedRedirect.install = function() {
89
88
  const name = 'fastify.Reply.prototype.redirect';
90
- depHooks.resolve({ name: 'fastify', file: 'lib/reply' }, (Reply) => {
89
+ depHooks.resolve({ name: 'fastify', version: '>=3 <5', file: 'lib/reply' }, (Reply) => {
91
90
  patcher.patch(Reply.prototype, 'redirect', {
92
91
  name,
93
92
  patchType,
94
93
  post(data) {
95
- if (!getSourceContext(RULE, ruleId)) return;
94
+ if (!getSinkContext(ruleId)) return;
96
95
 
97
96
  const { url, index: valueIndex } = getURLArgument(data.args);
98
97
  if (!url || !isString(url)) return;
@@ -28,7 +28,6 @@ const {
28
28
  isString,
29
29
  primordials: { ArrayPrototypeJoin },
30
30
  } = require('@contrast/common');
31
- const { InstrumentationType: { RULE } } = require('../../../constants');
32
31
 
33
32
  module.exports = function(core) {
34
33
  const {
@@ -36,7 +35,7 @@ module.exports = function(core) {
36
35
  patcher,
37
36
  assess: {
38
37
  inspect, // TODO NODE-3455: remove
39
- getSourceContext,
38
+ getSinkContext,
40
39
  eventFactory: { createSinkEvent },
41
40
  dataflow: {
42
41
  tracker,
@@ -63,7 +62,7 @@ module.exports = function(core) {
63
62
 
64
63
  const pre = (name, method, moduleName = 'fs', fullMethodName = '') => (data) => {
65
64
  const { name: methodName, indices } = method;
66
- if (!getSourceContext(RULE, ruleId)) return;
65
+ if (!getSinkContext(ruleId)) return;
67
66
 
68
67
  const values = getValues(indices, data.args);
69
68
  if (!values.length) return;
@@ -116,7 +115,7 @@ module.exports = function(core) {
116
115
 
117
116
  core.assess.dataflow.sinks.pathTraversal = {
118
117
  install() {
119
- depHooks.resolve({ name: 'fs' }, (fs) => {
118
+ depHooks.resolve({ name: 'fs', version: '*' }, (fs) => {
120
119
  for (const method of FS_METHODS) {
121
120
  // not all methods are available on every OS or Node version.
122
121
  if (fs[method.name]) {
@@ -151,7 +150,7 @@ module.exports = function(core) {
151
150
  }
152
151
  });
153
152
 
154
- depHooks.resolve({ name: 'fs/promises' }, (fsPromises) => {
153
+ depHooks.resolve({ name: 'fs/promises', version: '*' }, (fsPromises) => {
155
154
  for (const method of FS_METHODS) {
156
155
  if (method.promises && fsPromises[method.name]) {
157
156
  const name = `fsPromises.${method.name}`;
@@ -33,8 +33,8 @@ describe('assess dataflow sinks path-traversal', function () {
33
33
  ({ core, simulateRequestScope, trackString } = initAssessFixture());
34
34
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
35
35
 
36
- core.depHooks.resolve.withArgs({ name: 'fs' }).yields(fs);
37
- core.depHooks.resolve.withArgs({ name: 'fs/promises' }).yields(fsPromises);
36
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'fs' })).yields(fs);
37
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'fs/promises' })).yields(fsPromises);
38
38
 
39
39
  require('./fs')(core).install();
40
40
  });