@contrast/assess 1.41.0 → 1.43.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 +10 -11
  110. package/lib/dataflow/sinks/install/mssql.test.js +10 -12
  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
@@ -26,7 +26,6 @@ const {
26
26
  Rule: { SQL_INJECTION: ruleId },
27
27
  isString,
28
28
  } = require('@contrast/common');
29
- const { InstrumentationType: { RULE } } = require('../../../constants');
30
29
  const { filterSafeTags, patchType } = require('../common');
31
30
 
32
31
  /**
@@ -43,7 +42,7 @@ module.exports = function(core) {
43
42
  patcher,
44
43
  assess: {
45
44
  inspect, // TODO NODE-3455: remove
46
- getSourceContext,
45
+ getSinkContext,
47
46
  eventFactory: { createSinkEvent },
48
47
  dataflow: {
49
48
  tracker,
@@ -63,7 +62,7 @@ module.exports = function(core) {
63
62
  const postgres = core.assess.dataflow.sinks.postgres = {};
64
63
 
65
64
  const preHook = (methodSignature) => (data) => {
66
- if (!getSourceContext(RULE, ruleId) || isLocked(ruleId)) return;
65
+ if (!getSinkContext(ruleId) || isLocked(ruleId)) return;
67
66
 
68
67
  const [arg0] = data.args;
69
68
  const query = arg0?.text || arg0;
@@ -126,7 +125,7 @@ module.exports = function(core) {
126
125
  postgres.install = function() {
127
126
  const pgClientQueryPatchName = 'pg.Client.prototype.query';
128
127
  depHooks.resolve(
129
- { name: 'pg', file: 'lib/client.js' },
128
+ { name: 'pg', version: '<9', file: 'lib/client.js' },
130
129
  (client) => {
131
130
  patcher.patch(client.prototype, 'query', {
132
131
  name: pgClientQueryPatchName,
@@ -138,7 +137,7 @@ module.exports = function(core) {
138
137
 
139
138
  const pgNativeClientQueryPatchName = 'pg.native.Client.prototype.query';
140
139
  depHooks.resolve(
141
- { name: 'pg', file: 'lib/native/client.js' },
140
+ { name: 'pg', version: '<9', file: 'lib/native/client.js' },
142
141
  (client) => {
143
142
  patcher.patch(client.prototype, 'query', {
144
143
  name: pgNativeClientQueryPatchName,
@@ -148,7 +147,7 @@ module.exports = function(core) {
148
147
  },
149
148
  );
150
149
 
151
- depHooks.resolve({ name: 'pg-pool' }, (pool) => {
150
+ depHooks.resolve({ name: 'pg-pool', version: '<4' }, (pool) => {
152
151
  const name = 'pg-pool.Pool.prototype.query';
153
152
  patcher.patch(pool.prototype, 'query', {
154
153
  name,
@@ -28,15 +28,9 @@ describe('assess dataflow sinks postgres', function () {
28
28
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
29
29
  reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
30
30
 
31
- core.depHooks.resolve
32
- .withArgs({ name: 'pg', file: 'lib/client.js' })
33
- .yields(Client);
34
-
35
- core.depHooks.resolve
36
- .withArgs({ name: 'pg', file: 'lib/native/client.js' })
37
- .yields(NativeClient);
38
-
39
- core.depHooks.resolve.withArgs({ name: 'pg-pool' }).yields(Pool);
31
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'pg', file: 'lib/client.js' })).yields(Client);
32
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'pg', file: 'lib/native/client.js' })).yields(NativeClient);
33
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'pg-pool' })).yields(Pool);
40
34
 
41
35
  require('./postgres')(core).install();
42
36
  });
@@ -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
  const { createAppendTags } = require('../../tag-utils');
33
32
  const { patchType } = require('../common');
34
33
 
@@ -45,7 +44,7 @@ module.exports = function(core) {
45
44
  depHooks,
46
45
  patcher,
47
46
  assess: {
48
- getSourceContext,
47
+ getSinkContext,
49
48
  eventFactory: { createSinkEvent },
50
49
  dataflow: {
51
50
  tracker,
@@ -114,7 +113,7 @@ module.exports = function(core) {
114
113
  install() {
115
114
  // restify adds functionality to the built-in response via this patch function.
116
115
  // once it returns the request, it'll have been decorated with redirect() method.
117
- depHooks.resolve({ name: 'restify', file: 'lib/response.js' }, (responsePatch) => patcher.patch(responsePatch, {
116
+ depHooks.resolve({ name: 'restify', version: '<12', file: 'lib/response.js' }, (responsePatch) => patcher.patch(responsePatch, {
118
117
  name: 'restify.response.patch',
119
118
  patchType,
120
119
  post(data) {
@@ -122,7 +121,7 @@ module.exports = function(core) {
122
121
  patchType,
123
122
  name: 'restify.Response.redirect',
124
123
  pre(data) {
125
- if (!getSourceContext(RULE, ruleId)) return;
124
+ if (!getSinkContext(ruleId)) return;
126
125
 
127
126
  let vulnArgIdx;
128
127
  let vulnArgIsString = true;
@@ -33,11 +33,9 @@ describe('assess dataflow restify sinks', function () {
33
33
  return new Response();
34
34
  };
35
35
 
36
- core.depHooks.resolve
37
- .withArgs({ name: 'restify', file: 'lib/response.js' })
38
- .callsFake((desc, cb) => {
39
- patchMock = cb(patch);
40
- });
36
+ core.depHooks.resolve.callsFake((desc, cb) => {
37
+ patchMock = cb(patch);
38
+ });
41
39
 
42
40
  require('./restify')(core).install();
43
41
  });
@@ -25,7 +25,6 @@ const {
25
25
  CUSTOM_ENCODED,
26
26
  },
27
27
  } = require('@contrast/common');
28
- const { InstrumentationType: { RULE } } = require('../../../constants');
29
28
  const { patchType, filterSafeTags } = require('../common');
30
29
 
31
30
  /**
@@ -42,7 +41,7 @@ module.exports = function (core) {
42
41
  config,
43
42
  assess: {
44
43
  inspect, // TODO NODE-3455: remove
45
- getSourceContext,
44
+ getSinkContext,
46
45
  eventFactory: { createSinkEvent },
47
46
  dataflow: {
48
47
  tracker,
@@ -63,12 +62,12 @@ module.exports = function (core) {
63
62
  const sequelize = (core.assess.dataflow.sinks.sequelize = {});
64
63
 
65
64
  sequelize.install = function () {
66
- depHooks.resolve({ name: 'sequelize' }, (sequelize) => {
65
+ depHooks.resolve({ name: 'sequelize', version: '<7' }, (sequelize) => {
67
66
  patcher.patch(sequelize.prototype, 'query', {
68
67
  name: 'sequelize.prototype.query',
69
68
  patchType,
70
69
  around(next, data) {
71
- if (!getSourceContext(RULE, ruleId) || !data.args[0]) return next();
70
+ if (!getSinkContext(ruleId) || !data.args[0]) return next();
72
71
 
73
72
  const { args, hooked, orig } = data;
74
73
  const query = typeof args[0] === 'string' ? args[0] : args[0].query;
@@ -27,7 +27,6 @@ const {
27
27
  Rule: { SQL_INJECTION: ruleId },
28
28
  isString
29
29
  } = require('@contrast/common');
30
- const { InstrumentationType: { RULE } } = require('../../../constants');
31
30
 
32
31
  const safeTags = [
33
32
  `excluded:${ruleId}`,
@@ -49,7 +48,7 @@ module.exports = function(core) {
49
48
  depHooks,
50
49
  patcher,
51
50
  assess: {
52
- getSourceContext,
51
+ getSinkContext,
53
52
  eventFactory: { createSinkEvent },
54
53
  dataflow: {
55
54
  tracker,
@@ -60,7 +59,7 @@ module.exports = function(core) {
60
59
 
61
60
  const pre = (name, method) => (data) => {
62
61
  if (
63
- !getSourceContext(RULE, ruleId) ||
62
+ !getSinkContext(ruleId) ||
64
63
  !data.args[0] ||
65
64
  !isString(data.args[0]) ||
66
65
  isLocked(ruleId)
@@ -105,7 +104,7 @@ module.exports = function(core) {
105
104
 
106
105
  core.assess.dataflow.sinks.sqlite3 = {
107
106
  install() {
108
- depHooks.resolve({ name: 'sqlite3' }, sqlite3 => {
107
+ depHooks.resolve({ name: 'sqlite3', version: '<6' }, sqlite3 => {
109
108
  ['all', 'run', 'get', 'each', 'exec', 'prepare'].forEach((method) => {
110
109
  const name = `sqlite3.Database.prototype.${method}`;
111
110
  patcher.patch(sqlite3.Database.prototype, method, {
@@ -33,7 +33,6 @@ const {
33
33
  },
34
34
  traverseValues,
35
35
  } = require('@contrast/common');
36
- const { InstrumentationType: { RULE } } = require('../../../constants');
37
36
  const { createAdjustedQueryTags } = require('../../tag-utils');
38
37
 
39
38
  const safeTags = [
@@ -58,7 +57,7 @@ module.exports = function (core) {
58
57
  patcher,
59
58
  assess: {
60
59
  inspect, // TODO NODE-3455: remove
61
- getSourceContext,
60
+ getSinkContext,
62
61
  eventFactory: { createSinkEvent },
63
62
  dataflow: {
64
63
  tracker,
@@ -144,7 +143,7 @@ module.exports = function (core) {
144
143
  }
145
144
 
146
145
  function around(next, { args: origArgs, hooked, orig, name }) {
147
- if (!getSourceContext(RULE, ruleId) || isLocked(ruleId)) return next();
146
+ if (!getSinkContext(ruleId) || isLocked(ruleId)) return next();
148
147
 
149
148
  const methodPath = StringPrototypeSplit.call(name, '.');
150
149
  const method = methodPath[methodPath.length - 1];
@@ -250,7 +249,7 @@ module.exports = function (core) {
250
249
 
251
250
  core.assess.dataflow.sinks.vm = {
252
251
  install() {
253
- depHooks.resolve({ name: 'vm' }, (vm) => {
252
+ depHooks.resolve({ name: 'vm', version: '*' }, (vm) => {
254
253
  [
255
254
  'Script',
256
255
  'createScript',
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  const METHODS = ['json', 'raw', 'text', 'urlencoded'];
@@ -39,7 +38,7 @@ module.exports = function init(core) {
39
38
  const preHook = (data) => {
40
39
  const [req, , next] = data.args;
41
40
  data.args[2] = scopes.wrap(function contrastNext(...args) {
42
- const sourceContext = getSourceContext(SOURCE);
41
+ const sourceContext = getSourceContext();
43
42
 
44
43
  if (!sourceContext) {
45
44
  return next(...args);
@@ -98,7 +97,7 @@ module.exports = function init(core) {
98
97
  core.assess.dataflow.sources.bodyParser1Instrumentation = {
99
98
  install() {
100
99
  depHooks.resolve(
101
- { name: 'body-parser', version: '>=1.0.0' },
100
+ { name: 'body-parser', version: '>=1 <2' },
102
101
  /** @param {import('body-parser').BodyParser} bodyParser */
103
102
  (bodyParser) => {
104
103
  bodyParser = patcher.patch(bodyParser, {
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  const inputType = InputType.MULTIPART_VALUE;
@@ -38,7 +37,7 @@ module.exports = (core) => {
38
37
  function createPreHook(finalEventName) {
39
38
  return function (data) {
40
39
  const { orig, hooked, funcKey } = data;
41
- const sourceContext = getSourceContext(SOURCE);
40
+ const sourceContext = getSourceContext();
42
41
 
43
42
  if (!sourceContext) {
44
43
  return;
@@ -84,7 +83,7 @@ module.exports = (core) => {
84
83
 
85
84
  // Patch `busboy`
86
85
  function install() {
87
- depHooks.resolve({ name, version: '<1.0.0' }, (busboy) => {
86
+ depHooks.resolve({ name, version: '<1' }, (busboy) => {
88
87
  patcher.patch(busboy.prototype, 'emit', {
89
88
  name: 'busboy.prototype.emit',
90
89
  patchType,
@@ -93,7 +92,7 @@ module.exports = (core) => {
93
92
  });
94
93
 
95
94
 
96
- depHooks.resolve({ name, version: '>=1.0.0' }, (busboy) =>
95
+ depHooks.resolve({ name, version: '1' }, (busboy) =>
97
96
  patcher.patch(busboy, {
98
97
  name,
99
98
  patchType,
@@ -27,8 +27,8 @@ describe('assess dataflow sources busboy', function () {
27
27
  sinon.spy(sources, 'handle');
28
28
 
29
29
  busboyInstr(core).install();
30
- core.depHooks.resolve.withArgs({ name: 'busboy', version: '<1.0.0' }).yield(mockBusboy0);
31
- core.depHooks.resolve.withArgs({ name: 'busboy', version: '>=1.0.0' }).yield(mockBusboy1);
30
+ core.depHooks.resolve.withArgs({ name: 'busboy', version: '<1' }).yield(mockBusboy0);
31
+ core.depHooks.resolve.withArgs({ name: 'busboy', version: '1' }).yield(mockBusboy1);
32
32
  const patchedBusboy1 = core.patcher.patch.getCall(1).returnValue;
33
33
 
34
34
  emitMethodVersions = {
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  module.exports = function init(core) {
@@ -25,7 +24,7 @@ module.exports = function init(core) {
25
24
  assess.dataflow.sources.cookieParser1Instrumentation = {
26
25
  install() {
27
26
  depHooks.resolve(
28
- { name: 'cookie-parser', version: '>=1.0.0' },
27
+ { name: 'cookie-parser', version: '>=1 <2' },
29
28
  /** @param {import('cookie-parser')} cookieParser */
30
29
  (cookieParser) =>
31
30
  patcher.patch(cookieParser, {
@@ -40,7 +39,7 @@ module.exports = function init(core) {
40
39
  const { funcKey } = data;
41
40
  const [req, , next] = data.args;
42
41
  data.args[2] = function contrastNext(...args) {
43
- const sourceContext = assess.getSourceContext(SOURCE);
42
+ const sourceContext = assess.getSourceContext();
44
43
 
45
44
  if (!sourceContext) {
46
45
  return next(...args);
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = function init(core) {
@@ -41,7 +40,7 @@ module.exports = function init(core) {
41
40
  layer.keys.length === 0
42
41
  ) return;
43
42
 
44
- const sourceContext = getSourceContext(SOURCE);
43
+ const sourceContext = getSourceContext();
45
44
  if (!sourceContext) return;
46
45
 
47
46
  if (sourceContext.parsedParams) {
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = function init(core) {
@@ -33,7 +32,7 @@ module.exports = function init(core) {
33
32
  return function(data) {
34
33
  const [req] = args || data.args;
35
34
 
36
- const sourceContext = getSourceContext(SOURCE);
35
+ const sourceContext = getSourceContext();
37
36
  if (!sourceContext) return;
38
37
 
39
38
  const sourceInfo = {
@@ -5,7 +5,7 @@ const { expect } = require('chai');
5
5
  const { initAssessFixture } = require('@contrast/test/fixtures');
6
6
 
7
7
  describe('assess dataflow sources express parsedUrl', function () {
8
- let core, instrumentation, patcher, simulateRequestScope, middleware, req, res, tracker;
8
+ let core, instrumentation, patcher, simulateRequestScope, req, res, tracker;
9
9
 
10
10
  beforeEach(function () {
11
11
  ({ core, simulateRequestScope } = initAssessFixture());
@@ -13,12 +13,15 @@ describe('assess dataflow sources express parsedUrl', function () {
13
13
  instrumentation = core.assess.dataflow.sources.expressInstrumentation.parsedUrl;
14
14
  tracker = core.assess.dataflow.tracker;
15
15
  patcher = core.patcher;
16
+
17
+ req = {};
18
+ res = {};
16
19
  });
17
20
 
18
21
  describe('express4', function() {
22
+ let middleware;
23
+
19
24
  beforeEach(function() {
20
- req = {};
21
- res = {};
22
25
  middleware = {
23
26
  init() {
24
27
  return function (req, res, next) {
@@ -34,10 +37,7 @@ describe('assess dataflow sources express parsedUrl', function () {
34
37
  }
35
38
  };
36
39
 
37
- core.depHooks
38
- .resolve
39
- .withArgs({ name: 'express', version: '>=4 <5', file: 'lib/middleware/init.js' })
40
- .yields(middleware);
40
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'express' })).yields(middleware);
41
41
  });
42
42
 
43
43
  it('hooks init next in order to track req._parsedUrl values', function () {
@@ -69,6 +69,7 @@ describe('assess dataflow sources express parsedUrl', function () {
69
69
 
70
70
  describe('express5', function() {
71
71
  let LayerMock;
72
+
72
73
  beforeEach(function() {
73
74
  req = {
74
75
  _parsedUrl: {
@@ -83,7 +84,7 @@ describe('assess dataflow sources express parsedUrl', function () {
83
84
  LayerMock = sinon.stub();
84
85
  LayerMock.prototype.handleRequest = sinon.stub();
85
86
 
86
- core.depHooks.resolve.withArgs({ name: 'router', version: '>=2 <3', file: 'lib/layer.js' }).yields(LayerMock);
87
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'router' })).yields(LayerMock);
87
88
  });
88
89
 
89
90
  it('hooks handleRequest in order to track req._parsedUrl values', function () {
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = function (core) {
@@ -32,7 +31,7 @@ module.exports = function (core) {
32
31
 
33
32
  const source = sources.fastifyInstrumentation.fastify = {
34
33
  install() {
35
- depHooks.resolve({ name: 'fastify', version: '>=3.2.0' }, (fastify) => patcher.patch(fastify, {
34
+ depHooks.resolve({ name: 'fastify', version: '>=3.2.0 <5' }, (fastify) => patcher.patch(fastify, {
36
35
  name: 'fastify.constructor',
37
36
  patchType,
38
37
  post({ result: server, funcKey }) {
@@ -42,7 +41,7 @@ module.exports = function (core) {
42
41
  : typeof request.body == 'object'
43
42
  ? InputType.PARAMETER_VALUE
44
43
  : InputType.BODY;
45
- const sourceContext = getSourceContext(SOURCE);
44
+ const sourceContext = getSourceContext();
46
45
 
47
46
  if (!sourceContext) return;
48
47
 
@@ -26,12 +26,9 @@ describe('assess dataflow sources fastify', function () {
26
26
  addHook: sinon.stub().yields(reqMock, replyMock, doneMock),
27
27
  };
28
28
  fastifyServerMock = () => serverMock;
29
- core.depHooks
30
- .resolve
31
- .withArgs({ name: 'fastify', version: '>=3.2.0' })
32
- .callsFake((desc, cb) => {
33
- fastifyServerMock = cb(fastifyServerMock);
34
- });
29
+ core.depHooks.resolve.callsFake((desc, cb) => {
30
+ fastifyServerMock = cb(fastifyServerMock);
31
+ });
35
32
 
36
33
  fastifyInstr(core).install();
37
34
  core.logger.trace.resetHistory();
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  const inputType = InputType.MULTIPART_VALUE;
@@ -36,13 +35,13 @@ module.exports = (core) => {
36
35
 
37
36
  // Patch `formidable`
38
37
  function install() {
39
- depHooks.resolve({ name: 'formidable' }, (formidable) => {
38
+ depHooks.resolve({ name: 'formidable', version: '<4' }, (formidable) => {
40
39
  formidable.IncomingForm.prototype.parse = patcher.patch(formidable.IncomingForm.prototype.parse, {
41
40
  name,
42
41
  patchType,
43
42
  pre(data) {
44
43
  const { funcKey } = data;
45
- const sourceContext = getSourceContext(SOURCE);
44
+ const sourceContext = getSourceContext();
46
45
 
47
46
  if (!sourceContext) return;
48
47
 
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = function (core) {
@@ -40,7 +39,7 @@ module.exports = function (core) {
40
39
  post({ result: server, funcKey, hooked, orig }) {
41
40
 
42
41
  server.ext('onRequest', (req, h) => {
43
- const sourceContext = getSourceContext(SOURCE);
42
+ const sourceContext = getSourceContext();
44
43
  if (!sourceContext) return;
45
44
 
46
45
  [
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { primordials: { StringPrototypeToLowerCase }, InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  /**
@@ -47,7 +46,7 @@ module.exports = function (core) {
47
46
 
48
47
  try {
49
48
  const [, req, res] = data.args;
50
- const sourceContext = getSourceContext(SOURCE);
49
+ const sourceContext = getSourceContext();
51
50
 
52
51
  if (!sourceContext?.policy) {
53
52
  return next();
@@ -88,7 +87,7 @@ module.exports = function (core) {
88
87
  if (
89
88
  value &&
90
89
  StringPrototypeToLowerCase.call(name) === 'content-type' &&
91
- getSourceContext(SOURCE)
90
+ getSourceContext()
92
91
  ) {
93
92
  sourceContext.responseData.contentType = value;
94
93
  }
@@ -16,7 +16,7 @@ describe('assess dataflow sources http', function () {
16
16
  response = mocks.serverResponse();
17
17
 
18
18
  class Server extends EventEmitter { }
19
- core.depHooks.resolve.withArgs({ name: 'http' }).yields({ Server });
19
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'http' })).yields({ Server });
20
20
  core.logger.child = () => core.logger;
21
21
 
22
22
  require('./http')(core).install();
@@ -25,7 +25,7 @@ describe('assess dataflow sources http', function () {
25
25
 
26
26
  it('instantiates assess store with appropriate metadata and handles base sources', function (next) {
27
27
  simulateRequestScope(() => {
28
- core.scopes.sources.getStore().assess.req
28
+ core.scopes.sources.getStore().assess.req;
29
29
  server.on('request', test);
30
30
  server.emit('request', request, response);
31
31
  });
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = (core) => {
@@ -30,10 +29,9 @@ module.exports = (core) => {
30
29
  },
31
30
  } = core;
32
31
 
33
- // Patch `koa-body` v4.x.x and `koa-bodyparser` v5.x.x packages
34
32
  function install() {
35
- ['koa-body', 'koa-bodyparser'].forEach((name) => {
36
- depHooks.resolve({ name }, (koaBody) => patcher.patch(koaBody, {
33
+ [['koa-body', '<7'], ['koa-bodyparser', '<5']].forEach(([name, version]) => {
34
+ depHooks.resolve({ name, version }, (koaBody) => patcher.patch(koaBody, {
37
35
  name,
38
36
  patchType,
39
37
  post(data) {
@@ -43,7 +41,7 @@ module.exports = (core) => {
43
41
  pre(data) {
44
42
  const { funcKey } = data;
45
43
  const [ctx, origNext] = data.args;
46
- const sourceContext = getSourceContext(SOURCE);
44
+ const sourceContext = getSourceContext();
47
45
 
48
46
  if (!sourceContext) return;
49
47
 
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = (core) => {
@@ -31,7 +30,7 @@ module.exports = (core) => {
31
30
  } = core;
32
31
 
33
32
  function handler(req, constructorOpt) {
34
- const sourceContext = getSourceContext(SOURCE);
33
+ const sourceContext = getSourceContext();
35
34
  if (!sourceContext) return;
36
35
 
37
36
  function handle(context, data, key) {
@@ -68,9 +67,9 @@ module.exports = (core) => {
68
67
  }
69
68
 
70
69
  function install() {
71
- ['koa-multer', '@koa/multer'].forEach((name) => {
70
+ [['koa-multer', '<2'], ['@koa/multer', '<4']].forEach(([name, version]) => {
72
71
  depHooks.resolve(
73
- { name }, (_export) => {
72
+ { name, version }, (_export) => {
74
73
  const origMulter = _export;
75
74
  return patcher.patch(_export, {
76
75
  name,
@@ -47,7 +47,7 @@ describe('assess dataflow sources Koa multer', function () {
47
47
  koaMulter(core).install();
48
48
 
49
49
  [patchedKoaMulter] = core.depHooks.resolve
50
- .withArgs({ name })
50
+ .withArgs(sinon.match({ name }))
51
51
  .yield(koaMulterMock);
52
52
 
53
53
  });
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
19
  const { patchType } = require('../../common');
21
20
 
22
21
  module.exports = (core) => {
@@ -32,15 +31,15 @@ module.exports = (core) => {
32
31
 
33
32
  // Patch `koa-router` and `@koa/router` to handle parsed params
34
33
  function install() {
35
- ['koa-router', '@koa/router'].forEach(router => {
34
+ [['koa-router', '<14'], ['@koa/router', '<14']].forEach(([router, version]) => {
36
35
  depHooks.resolve(
37
- { name: router, file: 'lib/layer.js' },
36
+ { name: router, version, file: 'lib/layer.js' },
38
37
  (layer) => {
39
38
  layer.prototype = patcher.patch(layer.prototype, 'params', {
40
39
  name: `[${router}].layer.prototype`,
41
40
  patchType,
42
41
  post({ orig, hooked, result, name, funcKey }) {
43
- const sourceContext = getSourceContext(SOURCE);
42
+ const sourceContext = getSourceContext();
44
43
  const inputType = InputType.URL_PARAMETER;
45
44
 
46
45
  if (!sourceContext) return;