@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
@@ -28,7 +28,6 @@ const {
28
28
  },
29
29
  Rule: { UNSAFE_CODE_EXECUTION: ruleId }
30
30
  } = require('@contrast/common');
31
- const { InstrumentationType: { RULE } } = require('../../../constants');
32
31
  const { patchType, filterSafeTags } = require('../common');
33
32
 
34
33
  const safeTags = [
@@ -47,7 +46,7 @@ module.exports = function (core) {
47
46
  patcher,
48
47
  assess: {
49
48
  inspect, // TODO NODE-3455: remove
50
- getSourceContext,
49
+ getSinkContext,
51
50
  eventFactory: { createSinkEvent },
52
51
  dataflow: {
53
52
  tracker,
@@ -67,7 +66,7 @@ module.exports = function (core) {
67
66
  name: 'global.ContrastMethods.Function',
68
67
  patchType,
69
68
  pre({ args: origArgs, hooked, orig, name }) {
70
- if (!getSourceContext(RULE, ruleId)) return;
69
+ if (!getSinkContext(ruleId)) return;
71
70
 
72
71
  const fnBody = origArgs[origArgs.length - 1];
73
72
  if (!fnBody || !isString(fnBody)) return;
@@ -27,7 +27,6 @@ const {
27
27
  },
28
28
  isString
29
29
  } = require('@contrast/common');
30
- const { InstrumentationType: { RULE } } = require('../../../../constants');
31
30
  const { patchType, filterSafeTags } = require('../../common');
32
31
  const { createSubsetTags } = require('../../../tag-utils');
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,
@@ -67,13 +66,13 @@ module.exports = function(core) {
67
66
  ];
68
67
 
69
68
  unvalidatedRedirect.install = function() {
70
- depHooks.resolve({ name: '@hapi/hapi', file: 'lib/response' }, (Response) => {
69
+ depHooks.resolve({ name: '@hapi/hapi', version: '>=18 <22', file: 'lib/response' }, (Response) => {
71
70
  const name = 'hapi.Response.prototype.redirect';
72
71
  patcher.patch(Response.prototype, 'redirect', {
73
72
  name,
74
73
  patchType,
75
74
  pre: (data) => {
76
- if (!getSourceContext(RULE, ruleId)) return;
75
+ if (!getSinkContext(ruleId)) return;
77
76
 
78
77
  const [url] = data.args;
79
78
  if (!url || !isString(url)) return;
@@ -29,7 +29,6 @@ const {
29
29
  Rule: { SSRF: ruleId },
30
30
  primordials: { RegExpPrototypeExec }
31
31
  } = require('@contrast/common');
32
- const { InstrumentationType: { RULE } } = require('../../../../constants');
33
32
  const { createAppendTags } = require('../../../tag-utils');
34
33
  const { patchType } = require('../../common');
35
34
 
@@ -47,7 +46,7 @@ module.exports = function(core) {
47
46
  patcher,
48
47
  assess: {
49
48
  inspect, // TODO NODE-3455: remove
50
- getSourceContext,
49
+ getSinkContext,
51
50
  eventFactory: { createSinkEvent },
52
51
  dataflow: {
53
52
  tracker,
@@ -96,14 +95,14 @@ module.exports = function(core) {
96
95
 
97
96
  http.install = function() {
98
97
  ['http', 'https'].forEach((moduleName) => {
99
- depHooks.resolve({ name: moduleName }, (module) => {
98
+ depHooks.resolve({ name: moduleName, version: '*' }, (module) => {
100
99
  const name = `${moduleName}.request`;
101
100
  const methodName = 'request';
102
101
  patcher.patch(module, methodName, {
103
102
  name,
104
103
  patchType,
105
104
  pre(data) {
106
- if (!getSourceContext(RULE, ruleId)) return;
105
+ if (!getSinkContext(ruleId)) return;
107
106
 
108
107
  // url <string> |<URL>
109
108
  const [urlArg] = data.args;
@@ -47,8 +47,8 @@ const getReq = function (strOrObj, key, trackedString) {
47
47
  core.assess.dataflow.propagation.stringInstrumentation.substring.install();
48
48
  core.assess.dataflow.propagation.stringInstrumentation.split.install();
49
49
  core.assess.dataflow.propagation.urlInstrumentation.url.install();
50
- core.depHooks.resolve.withArgs({ name: 'url' }).yield(require('url'));
51
- core.depHooks.resolve.withArgs({ name: module }).yields(modules[module]);
50
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'url' })).yield(require('url'));
51
+ core.depHooks.resolve.withArgs(sinon.match({ name: module })).yields(modules[module]);
52
52
 
53
53
  require('./request')(core).install();
54
54
  });
@@ -31,7 +31,6 @@ const {
31
31
  },
32
32
  Rule: { REFLECTED_XSS: ruleId },
33
33
  } = require('@contrast/common');
34
- const { InstrumentationType: { RULE } } = require('../../../../constants');
35
34
 
36
35
  const { patchType, filterSafeTags } = require('../../common');
37
36
 
@@ -48,7 +47,7 @@ module.exports = function(core) {
48
47
  depHooks,
49
48
  patcher,
50
49
  assess: {
51
- getSourceContext,
50
+ getSinkContext,
52
51
  eventFactory: { createSinkEvent },
53
52
  dataflow: {
54
53
  tracker,
@@ -80,7 +79,7 @@ module.exports = function(core) {
80
79
  const preHook = (moduleName, responseName, method) => ({ args, obj: response, result, hooked, orig }) => {
81
80
  const methodName = `${responseName + (moduleName !== 'spdy' ? '.prototype' : '')}.${method}`;
82
81
  const name = `${moduleName}.${methodName}`;
83
- const sourceContext = getSourceContext(RULE, ruleId);
82
+ const sourceContext = getSinkContext(ruleId);
84
83
  if (!sourceContext) return;
85
84
 
86
85
  const payload = args[0];
@@ -140,7 +139,7 @@ module.exports = function(core) {
140
139
  };
141
140
 
142
141
  http.install = function() {
143
- depHooks.resolve({ name: 'http' }, (http) => {
142
+ depHooks.resolve({ name: 'http', version: '*' }, (http) => {
144
143
  {
145
144
  const method = 'write';
146
145
  patcher.patch(http.ServerResponse.prototype, method, {
@@ -158,7 +157,7 @@ module.exports = function(core) {
158
157
  });
159
158
  }
160
159
  });
161
- depHooks.resolve({ name: 'http2' }, (http2) => {
160
+ depHooks.resolve({ name: 'http2', version: '*' }, (http2) => {
162
161
  {
163
162
  const method = 'write';
164
163
  patcher.patch(http2.Http2ServerResponse.prototype, method, {
@@ -176,7 +175,7 @@ module.exports = function(core) {
176
175
  });
177
176
  }
178
177
  });
179
- depHooks.resolve({ name: 'spdy', file: 'lib/spdy/response.js' }, (response) => {
178
+ depHooks.resolve({ name: 'spdy', version: '<5', file: 'lib/spdy/response.js' }, (response) => {
180
179
  {
181
180
  const method = 'end';
182
181
  patcher.patch(response, method, {
@@ -36,9 +36,9 @@ describe('assess dataflow sinks http, http2, spdy', function () {
36
36
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
37
37
  reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
38
38
 
39
- core.depHooks.resolve.withArgs({ name: 'http' }).yields({ ServerResponse });
40
- core.depHooks.resolve.withArgs({ name: 'http2' }).yields({ Http2ServerResponse });
41
- core.depHooks.resolve.withArgs({ name: 'spdy', file: 'lib/spdy/response.js' }).yields(response);
39
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'http' })).yields({ ServerResponse });
40
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'http2' })).yields({ Http2ServerResponse });
41
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'spdy' })).yields(response);
42
42
 
43
43
  require('./server-response')(core).install();
44
44
  });
@@ -27,7 +27,6 @@ const {
27
27
  Rule: { UNVALIDATED_REDIRECT: ruleId },
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
 
@@ -47,7 +46,7 @@ module.exports = function(core) {
47
46
  config,
48
47
  assess: {
49
48
  inspect, // TODO NODE-3455: remove
50
- getSourceContext,
49
+ getSinkContext,
51
50
  eventFactory: { createSinkEvent },
52
51
  dataflow: {
53
52
  tracker,
@@ -69,13 +68,13 @@ module.exports = function(core) {
69
68
  const unvalidatedRedirect = core.assess.dataflow.sinks.koa.unvalidatedRedirect = {};
70
69
 
71
70
  unvalidatedRedirect.install = function() {
72
- depHooks.resolve({ name: 'koa', file: 'lib/response', version: '<2.9.0' }, (Response) => {
71
+ depHooks.resolve({ name: 'koa', version: '<2.9.0', file: 'lib/response' }, (Response) => {
73
72
  const name = 'Koa.Response.redirect';
74
73
  patcher.patch(Response, 'redirect', {
75
74
  name,
76
75
  patchType,
77
76
  pre(data) {
78
- if (!getSourceContext(RULE, ruleId)) return;
77
+ if (!getSinkContext(ruleId)) return;
79
78
 
80
79
  let isBackRoute = false;
81
80
  let [url] = data.args;
@@ -24,7 +24,6 @@ const {
24
24
  LIMITED_CHARS,
25
25
  },
26
26
  } = require('@contrast/common');
27
- const { InstrumentationType: { RULE } } = require('../../../constants');
28
27
  const { patchType } = require('../common');
29
28
 
30
29
  const safeTags = [
@@ -48,7 +47,7 @@ module.exports = function(core) {
48
47
  patcher,
49
48
  assess: {
50
49
  inspect, // TODO NODE-3455: remove
51
- getSourceContext,
50
+ getSinkContext,
52
51
  eventFactory: { createSinkEvent },
53
52
  dataflow: {
54
53
  tracker,
@@ -71,7 +70,7 @@ module.exports = function(core) {
71
70
  name: `${moduleName}.${method}`,
72
71
  patchType,
73
72
  pre(data) {
74
- if (!getSourceContext(RULE, ruleId) || !data.args[0]) return;
73
+ if (!getSinkContext(ruleId) || !data.args[0]) return;
75
74
 
76
75
  const [xmlString, opts] = data.args;
77
76
 
@@ -122,11 +121,11 @@ module.exports = function(core) {
122
121
  core.assess.dataflow.sinks.libxmljs = {
123
122
  install() {
124
123
  // libxmljs changed its API in version 1.0.0
125
- depHooks.resolve({ name: 'libxmljs', version: '>=1' }, handler('libxmljs', true));
124
+ depHooks.resolve({ name: 'libxmljs', version: '>=1 <2' }, handler('libxmljs', true));
126
125
 
127
126
  // libxmljs versions prior to 1.0.0 and libxmljs2 share the same API
128
127
  depHooks.resolve({ name: 'libxmljs', version: '<1' }, handler('libxmljs', false));
129
- depHooks.resolve({ name: 'libxmljs2' }, handler('libxmljs2', false));
128
+ depHooks.resolve({ name: 'libxmljs2', version: '<1' }, handler('libxmljs2', false));
130
129
  },
131
130
  };
132
131
 
@@ -34,11 +34,11 @@ describe('assess dataflow sinks libxmljs', function () {
34
34
  .yields(modules['libxmljs@0']);
35
35
 
36
36
  core.depHooks.resolve
37
- .withArgs({ name: 'libxmljs', version: '>=1' })
37
+ .withArgs({ name: 'libxmljs', version: '>=1 <2' })
38
38
  .yields(modules['libxmljs@1']);
39
39
 
40
40
  core.depHooks.resolve
41
- .withArgs({ name: 'libxmljs2' })
41
+ .withArgs(sinon.match({ name: 'libxmljs2' }))
42
42
  .yields(modules['libxmljs2']);
43
43
 
44
44
  require('./libxmljs')(core).install();
@@ -25,7 +25,6 @@ const {
25
25
  CUSTOM_VALIDATED_NOSQL_INJECTION,
26
26
  },
27
27
  } = require('@contrast/common');
28
- const { InstrumentationType: { RULE } } = require('../../../constants');
29
28
  const { patchType } = require('../common');
30
29
 
31
30
  const collectionMethods = ['find', 'findOne', 'update', 'remove'];
@@ -51,7 +50,7 @@ module.exports = function (core) {
51
50
  patcher,
52
51
  assess: {
53
52
  inspect, // TODO NODE-3455: remove
54
- getSourceContext,
53
+ getSinkContext,
55
54
  eventFactory: { createSinkEvent },
56
55
  dataflow: {
57
56
  tracker,
@@ -90,7 +89,7 @@ module.exports = function (core) {
90
89
  name,
91
90
  patchType,
92
91
  around(next, data) {
93
- if (!getSourceContext(RULE, ruleId)) return next();
92
+ if (!getSinkContext(ruleId)) return next();
94
93
 
95
94
  const argIdx = 0;
96
95
  const result = getVulnerabilityInfo(data.args[argIdx]);
@@ -134,7 +133,7 @@ module.exports = function (core) {
134
133
  }
135
134
 
136
135
  instr.install = function () {
137
- depHooks.resolve({ name: 'marsdb' }, (marsdb) => {
136
+ depHooks.resolve({ name: 'marsdb', version: '<1' }, (marsdb) => {
138
137
  collectionMethods.forEach((method) => patchCollection(marsdb, method));
139
138
  });
140
139
  };
@@ -30,7 +30,7 @@ describe('assess dataflow marsdb', function () {
30
30
  core.assess.eventFactory,
31
31
  'createSinkEvent'
32
32
  );
33
- core.depHooks.resolve.withArgs({ name: 'marsdb' }).yields({ Collection });
33
+ core.depHooks.resolve.yields({ Collection });
34
34
 
35
35
  instr = require('./marsdb')(core);
36
36
  instr.install();
@@ -142,7 +142,7 @@ describe('assess dataflow marsdb', function () {
142
142
  });
143
143
  });
144
144
 
145
- describe('installing marsdb', function () {
145
+ describe('assess dataflow marsdb installation', function () {
146
146
  let core, instr;
147
147
 
148
148
  it('should log trace error if the method does not exist', function () {
@@ -153,7 +153,7 @@ describe('installing marsdb', function () {
153
153
  }
154
154
 
155
155
  ({ core } = initAssessFixture());
156
- core.depHooks.resolve.withArgs({ name: 'marsdb' }).yields({ Collection });
156
+ core.depHooks.resolve.yields({ Collection });
157
157
 
158
158
  instr = require('./marsdb')(core);
159
159
  instr.install();
@@ -29,7 +29,6 @@ const {
29
29
  traverseValues,
30
30
  isString,
31
31
  } = require('@contrast/common');
32
- const { InstrumentationType: { RULE } } = require('../../../constants');
33
32
  const utils = require('../../tag-utils');
34
33
  const { patchType, filterSafeTags } = require('../common');
35
34
 
@@ -83,7 +82,7 @@ module.exports = function (core) {
83
82
  patcher,
84
83
  assess: {
85
84
  inspect, // TODO NODE-3455: remove
86
- getSourceContext,
85
+ getSinkContext,
87
86
  eventFactory: { createSinkEvent },
88
87
  dataflow: {
89
88
  tracker,
@@ -282,7 +281,7 @@ module.exports = function (core) {
282
281
  function createAroundHook(entity, name, method, getInfoMethod, vulnerableArgIdxs) {
283
282
  const argsIdxsToCheck = vulnerableArgIdxs || [0];
284
283
  return function (next, data) {
285
- if (!getSourceContext(RULE, ruleId)) return next();
284
+ if (!getSinkContext(ruleId)) return next();
286
285
 
287
286
  const { obj, args: origArgs } = data;
288
287
  const safeReports = [];
@@ -372,7 +371,7 @@ module.exports = function (core) {
372
371
  }
373
372
 
374
373
  instr.install = function () {
375
- depHooks.resolve({ name: 'mongodb' }, (mongodb, version) => {
374
+ depHooks.resolve({ name: 'mongodb', version: '<7' }, (mongodb, version) => {
376
375
  patchCollection(mongodb, version);
377
376
  patchDatabase(mongodb, version);
378
377
  });
@@ -42,9 +42,7 @@ describe('assess dataflow sinks mongodb-v4', function () {
42
42
  beforeEach(function () {
43
43
  ({ core, simulateRequestScope, trackString } = initAssessFixture());
44
44
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
45
- core.depHooks.resolve
46
- .withArgs({ name: 'mongodb' })
47
- .yields({ Collection, Db });
45
+ core.depHooks.resolve.yields({ Collection, Db });
48
46
 
49
47
  // while the Assess fixture will have already composed the module, we re-require (which
50
48
  // just reassigns the component) so we're able to inject the spied-upon functions above
@@ -536,9 +534,7 @@ describe('assess dataflow sinks mongodb-v4', function () {
536
534
  class Db {
537
535
  command() { }
538
536
  }
539
- core.depHooks.resolve
540
- .withArgs({ name: 'mongodb' })
541
- .yields({ Collection, Db }, 'v5.x.x');
537
+ core.depHooks.resolve.yields({ Collection, Db }, 'v5.x.x');
542
538
 
543
539
  const instr = require('./mongodb')(core);
544
540
  instr.install();
@@ -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 { createModuleLabel } = require('../../propagation/common');
31
30
  const { patchType, filterSafeTags } = require('../common');
32
31
 
@@ -51,7 +50,7 @@ module.exports = function(core) {
51
50
  patcher,
52
51
  config,
53
52
  assess: {
54
- getSourceContext,
53
+ getSinkContext,
55
54
  eventFactory: { createSinkEvent },
56
55
  dataflow: {
57
56
  tracker,
@@ -62,7 +61,7 @@ module.exports = function(core) {
62
61
 
63
62
  const pre = (name, method, obj, version) => (data) => {
64
63
  if (
65
- !getSourceContext(RULE, ruleId) ||
64
+ !getSinkContext(ruleId) ||
66
65
  !data.args[0] ||
67
66
  !isString(data.args[0]) ||
68
67
  isLocked(ruleId)
@@ -118,7 +117,7 @@ module.exports = function(core) {
118
117
  core.assess.dataflow.sinks.mssql = {
119
118
  install() {
120
119
  depHooks.resolve(
121
- { name: 'mssql', file: 'lib/base/prepared-statement.js' },
120
+ { name: 'mssql', version: '<12', file: 'lib/base/prepared-statement.js' },
122
121
  (PreparedStatement, version) => {
123
122
  patcher.patch(PreparedStatement.prototype, 'prepare', {
124
123
  name: 'PreparedStatement.prototype.prepare',
@@ -134,7 +133,7 @@ module.exports = function(core) {
134
133
  );
135
134
 
136
135
  depHooks.resolve(
137
- { name: 'mssql', file: 'lib/base/request.js' },
136
+ { name: 'mssql', version: '<12', file: 'lib/base/request.js' },
138
137
  (Request, version) => {
139
138
  patcher.patch(Request.prototype, 'batch', {
140
139
  name: 'Request.prototype.batch',
@@ -26,11 +26,11 @@ describe('assess dataflow sinks mssql', function () {
26
26
  reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
27
27
 
28
28
  core.depHooks.resolve
29
- .withArgs({ name: 'mssql', file: 'lib/base/prepared-statement.js' })
29
+ .withArgs(sinon.match({ name: 'mssql', file: 'lib/base/prepared-statement.js' }))
30
30
  .yields(PreparedStatement);
31
31
 
32
32
  core.depHooks.resolve
33
- .withArgs({ name: 'mssql', file: 'lib/base/request.js' })
33
+ .withArgs(sinon.match({ name: 'mssql', file: 'lib/base/request.js' }))
34
34
  .yields(Request);
35
35
 
36
36
  require('./mssql')(core).install();
@@ -29,7 +29,6 @@ const {
29
29
  },
30
30
  isString,
31
31
  } = require('@contrast/common');
32
- const { InstrumentationType: { RULE } } = require('../../../constants');
33
32
 
34
33
  const safeTags = [
35
34
  `excluded:${ruleId}`,
@@ -54,7 +53,7 @@ module.exports = function(core) {
54
53
  patcher,
55
54
  assess: {
56
55
  inspect, // TODO NODE-3455: remove
57
- getSourceContext,
56
+ getSinkContext,
58
57
  eventFactory: { createSinkEvent },
59
58
  dataflow: {
60
59
  tracker,
@@ -75,7 +74,7 @@ module.exports = function(core) {
75
74
 
76
75
  const pre = (module, file, obj, method) => (data) => {
77
76
  if (
78
- !getSourceContext(RULE, ruleId) ||
77
+ !getSinkContext(ruleId) ||
79
78
  !data.args[0] ||
80
79
  isLocked(ruleId)
81
80
  ) return;
@@ -123,7 +122,7 @@ module.exports = function(core) {
123
122
  core.assess.dataflow.sinks.mysql = {
124
123
  install() {
125
124
  depHooks.resolve(
126
- { name: 'mysql', file: 'lib/Connection' },
125
+ { name: 'mysql', version: '<3', file: 'lib/Connection' },
127
126
  (Connection) => {
128
127
  patcher.patch(Connection.prototype, 'query', {
129
128
  name: 'Connection.prototype.query',
@@ -133,7 +132,7 @@ module.exports = function(core) {
133
132
  },
134
133
  );
135
134
  depHooks.resolve(
136
- { name: 'mysql2', file: 'lib/connection' },
135
+ { name: 'mysql2', version: '<4', file: 'lib/connection' },
137
136
  (connection) => {
138
137
  ['query', 'execute'].forEach((method) => {
139
138
  patcher.patch(connection.prototype, `${method}`, {
@@ -19,17 +19,8 @@ describe('assess dataflow sinks mysql', function () {
19
19
  tracker = core.assess.dataflow.tracker;
20
20
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
21
21
 
22
- core.depHooks.resolve
23
- .withArgs({ name: 'mysql', file: 'lib/Connection' })
24
- .yields(Connection);
25
-
26
- core.depHooks.resolve
27
- .withArgs({ name: 'mysql2', file: 'lib/connection' })
28
- .yields(connection);
29
-
30
- core.depHooks.resolve
31
- .withArgs({ name: 'mysql2', file: 'lib/connection' })
32
- .yields(connection);
22
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'mysql' })).yields(Connection);
23
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'mysql2' })).yields(connection);
33
24
 
34
25
  require('./mysql')(core).install();
35
26
  });
@@ -22,7 +22,6 @@ const {
22
22
  UNTRUSTED
23
23
  }
24
24
  } = require('@contrast/common');
25
- const { InstrumentationType: { RULE } } = require('../../../constants');
26
25
  const { patchType } = require('../common');
27
26
 
28
27
  const safeTags = [`excluded:${ruleId}`];
@@ -39,7 +38,7 @@ module.exports = function(core) {
39
38
  depHooks,
40
39
  patcher,
41
40
  assess: {
42
- getSourceContext,
41
+ getSinkContext,
43
42
  eventFactory: { createSinkEvent },
44
43
  dataflow: {
45
44
  tracker,
@@ -50,12 +49,12 @@ module.exports = function(core) {
50
49
 
51
50
  core.assess.dataflow.sinks.nodeSerialize = {
52
51
  install() {
53
- depHooks.resolve({ name: 'node-serialize' }, (nodeSerialize) => {
52
+ depHooks.resolve({ name: 'node-serialize', version: '<1' }, (nodeSerialize) => {
54
53
  patcher.patch(nodeSerialize, 'unserialize', {
55
54
  name: 'node-serialize.unserialize',
56
55
  patchType,
57
56
  pre(data) {
58
- if (!getSourceContext(RULE, ruleId) || !data.args[0]) return;
57
+ if (!getSinkContext(ruleId) || !data.args[0]) return;
59
58
 
60
59
  const [input] = data.args;
61
60
  if (!isString(input)) return;
@@ -13,9 +13,7 @@ describe('assess dataflow sinks node-serialize', function () {
13
13
  ({ core, simulateRequestScope, trackString } = initAssessFixture());
14
14
  reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
15
15
 
16
- core.depHooks.resolve
17
- .withArgs({ name: 'node-serialize' })
18
- .yields(serialize);
16
+ core.depHooks.resolve.yields(serialize);
19
17
 
20
18
  require('./node-serialize')(core).install();
21
19
 
@@ -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;