@contrast/assess 1.40.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 (167) 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/index.test.js +1 -1
  53. package/lib/dataflow/propagation/install/path/join-and-resolve.js +3 -4
  54. package/lib/dataflow/propagation/install/path/normalize.js +4 -5
  55. package/lib/dataflow/propagation/install/path/parse.js +3 -4
  56. package/lib/dataflow/propagation/install/path/relative.js +4 -5
  57. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +3 -4
  58. package/lib/dataflow/propagation/install/pug/index.js +3 -4
  59. package/lib/dataflow/propagation/install/pug-runtime-escape.js +3 -4
  60. package/lib/dataflow/propagation/install/querystring/escape.js +3 -4
  61. package/lib/dataflow/propagation/install/querystring/escape.test.js +1 -1
  62. package/lib/dataflow/propagation/install/querystring/parse.js +3 -4
  63. package/lib/dataflow/propagation/install/querystring/parse.test.js +1 -1
  64. package/lib/dataflow/propagation/install/querystring/stringify.js +3 -4
  65. package/lib/dataflow/propagation/install/querystring/stringify.test.js +1 -1
  66. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +2 -3
  67. package/lib/dataflow/propagation/install/send.js +3 -3
  68. package/lib/dataflow/propagation/install/sequelize/query-generator.js +3 -3
  69. package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +2 -1
  70. package/lib/dataflow/propagation/install/sequelize/sql-string.js +5 -5
  71. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -3
  72. package/lib/dataflow/propagation/install/string/concat.js +2 -3
  73. package/lib/dataflow/propagation/install/string/format-methods.js +2 -3
  74. package/lib/dataflow/propagation/install/string/html-methods.js +3 -4
  75. package/lib/dataflow/propagation/install/string/match-all.js +2 -3
  76. package/lib/dataflow/propagation/install/string/match.js +2 -3
  77. package/lib/dataflow/propagation/install/string/replace.js +2 -3
  78. package/lib/dataflow/propagation/install/string/slice.js +2 -3
  79. package/lib/dataflow/propagation/install/string/split.js +2 -3
  80. package/lib/dataflow/propagation/install/string/substring.js +2 -3
  81. package/lib/dataflow/propagation/install/string/trim.js +2 -3
  82. package/lib/dataflow/propagation/install/unescape.js +2 -3
  83. package/lib/dataflow/propagation/install/url/domain-parsers.js +3 -4
  84. package/lib/dataflow/propagation/install/url/parse.js +3 -4
  85. package/lib/dataflow/propagation/install/url/parse.test.js +2 -2
  86. package/lib/dataflow/propagation/install/url/searchParams.js +3 -4
  87. package/lib/dataflow/propagation/install/url/url.js +3 -4
  88. package/lib/dataflow/propagation/install/util-format.js +3 -4
  89. package/lib/dataflow/propagation/install/validator/hooks.js +9 -9
  90. package/lib/dataflow/sinks/install/child-process.js +5 -6
  91. package/lib/dataflow/sinks/install/eval.js +2 -3
  92. package/lib/dataflow/sinks/install/express/reflected-xss.js +3 -4
  93. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +3 -4
  94. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +3 -4
  95. package/lib/dataflow/sinks/install/fs.js +4 -5
  96. package/lib/dataflow/sinks/install/fs.test.js +2 -2
  97. package/lib/dataflow/sinks/install/function.js +2 -3
  98. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.js +3 -4
  99. package/lib/dataflow/sinks/install/http/request.js +3 -4
  100. package/lib/dataflow/sinks/install/http/request.test.js +2 -2
  101. package/lib/dataflow/sinks/install/http/server-response.js +5 -6
  102. package/lib/dataflow/sinks/install/http/server-response.test.js +3 -3
  103. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +3 -4
  104. package/lib/dataflow/sinks/install/libxmljs.js +4 -5
  105. package/lib/dataflow/sinks/install/libxmljs.test.js +2 -2
  106. package/lib/dataflow/sinks/install/marsdb.js +3 -4
  107. package/lib/dataflow/sinks/install/marsdb.test.js +3 -3
  108. package/lib/dataflow/sinks/install/mongodb.js +3 -4
  109. package/lib/dataflow/sinks/install/mongodb.test.js +2 -6
  110. package/lib/dataflow/sinks/install/mssql.js +4 -5
  111. package/lib/dataflow/sinks/install/mssql.test.js +2 -2
  112. package/lib/dataflow/sinks/install/mysql.js +4 -5
  113. package/lib/dataflow/sinks/install/mysql.test.js +2 -11
  114. package/lib/dataflow/sinks/install/node-serialize.js +3 -4
  115. package/lib/dataflow/sinks/install/node-serialize.test.js +1 -3
  116. package/lib/dataflow/sinks/install/postgres.js +5 -6
  117. package/lib/dataflow/sinks/install/postgres.test.js +3 -9
  118. package/lib/dataflow/sinks/install/restify.js +3 -4
  119. package/lib/dataflow/sinks/install/restify.test.js +3 -5
  120. package/lib/dataflow/sinks/install/sequelize.js +3 -4
  121. package/lib/dataflow/sinks/install/sqlite3.js +3 -4
  122. package/lib/dataflow/sinks/install/vm.js +3 -4
  123. package/lib/dataflow/sources/install/body-parser1.js +2 -4
  124. package/lib/dataflow/sources/install/body-parser1.test.js +4 -8
  125. package/lib/dataflow/sources/install/busboy.js +3 -4
  126. package/lib/dataflow/sources/install/busboy.test.js +2 -2
  127. package/lib/dataflow/sources/install/cookie-parser1.js +2 -4
  128. package/lib/dataflow/sources/install/cookie-parser1.test.js +2 -4
  129. package/lib/dataflow/sources/install/express/params.js +56 -38
  130. package/lib/dataflow/sources/install/express/params.test.js +80 -73
  131. package/lib/dataflow/sources/install/express/parsedUrl.js +45 -29
  132. package/lib/dataflow/sources/install/express/parsedUrl.test.js +71 -29
  133. package/lib/dataflow/sources/install/fastify/fastify.js +2 -3
  134. package/lib/dataflow/sources/install/fastify/fastify.test.js +3 -6
  135. package/lib/dataflow/sources/install/formidable1.js +2 -3
  136. package/lib/dataflow/sources/install/hapi/hapi.js +1 -2
  137. package/lib/dataflow/sources/install/http.js +2 -3
  138. package/lib/dataflow/sources/install/http.test.js +2 -2
  139. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +3 -5
  140. package/lib/dataflow/sources/install/koa/koa-multer.js +3 -4
  141. package/lib/dataflow/sources/install/koa/koa-multer.test.js +1 -1
  142. package/lib/dataflow/sources/install/koa/koa-routers.js +3 -4
  143. package/lib/dataflow/sources/install/koa/koa2.js +2 -4
  144. package/lib/dataflow/sources/install/multer1.js +2 -3
  145. package/lib/dataflow/sources/install/multer1.test.js +1 -3
  146. package/lib/dataflow/sources/install/qs6.js +2 -4
  147. package/lib/dataflow/sources/install/querystring.js +2 -3
  148. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +2 -3
  149. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +1 -1
  150. package/lib/dataflow/sources/install/restify/jsonBodyParser.js +2 -3
  151. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +1 -1
  152. package/lib/dataflow/sources/install/restify/router.js +2 -4
  153. package/lib/dataflow/sources/install/restify/router.test.js +4 -6
  154. package/lib/get-source-context.js +77 -37
  155. package/lib/get-source-context.test.js +106 -53
  156. package/lib/index.d.ts +3 -9
  157. package/lib/response-scanning/install/http.js +3 -3
  158. package/lib/response-scanning/install/http.test.js +2 -2
  159. package/lib/session-configuration/install/express-session.js +1 -1
  160. package/lib/session-configuration/install/express-session.test.js +1 -3
  161. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  162. package/lib/session-configuration/install/fastify-cookie.test.js +1 -3
  163. package/lib/session-configuration/install/koa.js +1 -1
  164. package/lib/session-configuration/install/koa.test.js +1 -1
  165. package/package.json +11 -11
  166. package/lib/constants.js +0 -26
  167. package/lib/dataflow/sinks/install/fs-original.js +0 -170
@@ -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) {
@@ -29,10 +28,41 @@ module.exports = function init(core) {
29
28
  patcher,
30
29
  } = core;
31
30
 
31
+ function preHook(name, args) {
32
+ return function(data) {
33
+ const [req] = args || data.args;
34
+
35
+ const sourceContext = getSourceContext();
36
+ if (!sourceContext) return;
37
+
38
+ const sourceInfo = {
39
+ context: 'req._parsedUrl',
40
+ data: req._parsedUrl,
41
+ name,
42
+ sourceContext,
43
+ stacktraceOpts: {
44
+ constructorOpt: data.hooked
45
+ }
46
+ };
47
+
48
+ sources.handle({
49
+ ...sourceInfo,
50
+ inputType: InputType.URI,
51
+ keys: ['href', 'path', 'pathname'],
52
+ });
53
+
54
+ sources.handle({
55
+ ...sourceInfo,
56
+ inputType: InputType.QUERYSTRING,
57
+ keys: ['query', 'search'],
58
+ });
59
+ };
60
+ }
61
+
32
62
  core.assess.dataflow.sources.expressInstrumentation.parsedUrl = {
33
63
  install() {
34
64
  depHooks.resolve(
35
- { name: 'express', version: '>=4.0.0 <5.0.0', file: 'lib/middleware/init.js' },
65
+ { name: 'express', version: '>=4 <5', file: 'lib/middleware/init.js' },
36
66
  /** @param {import('express/lib/middleware/init')} mw */
37
67
  (mw) => {
38
68
  const name = 'express.middleware.init';
@@ -44,36 +74,10 @@ module.exports = function init(core) {
44
74
  name: 'express.middleware.init.expressInit',
45
75
  patchType,
46
76
  pre(data) {
47
- const { args: [req] } = data;
48
77
  patcher.patch(data.args, '2', {
49
78
  name: 'express.middleware.init.expressInit.next',
50
79
  patchType,
51
- pre(data) {
52
- const sourceContext = getSourceContext(SOURCE);
53
- if (!sourceContext) return;
54
-
55
- const sourceInfo = {
56
- context: 'req._parsedUrl',
57
- data: req._parsedUrl,
58
- name,
59
- sourceContext,
60
- stacktraceOpts: {
61
- constructorOpt: data.hooked
62
- }
63
- };
64
-
65
- sources.handle({
66
- ...sourceInfo,
67
- inputType: InputType.URI,
68
- keys: ['href', 'path', 'pathname'],
69
- });
70
-
71
- sources.handle({
72
- ...sourceInfo,
73
- inputType: InputType.QUERYSTRING,
74
- keys: ['query', 'search'],
75
- });
76
- }
80
+ pre: preHook(name, data.args)
77
81
  });
78
82
  }
79
83
  });
@@ -81,6 +85,18 @@ module.exports = function init(core) {
81
85
  });
82
86
  }
83
87
  );
88
+
89
+ // Used by Express 5
90
+ depHooks.resolve(
91
+ { name: 'router', version: '>=2 <3', file: 'lib/layer.js' },
92
+ (Layer) => {
93
+ patcher.patch(Layer.prototype, 'handleRequest', {
94
+ name: 'Layer.prototype.handleRequest',
95
+ patchType,
96
+ pre: preHook('Layer.prototype.handleRequest')
97
+ });
98
+ }
99
+ );
84
100
  }
85
101
  };
86
102
 
@@ -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());
@@ -16,35 +16,81 @@ describe('assess dataflow sources express parsedUrl', function () {
16
16
 
17
17
  req = {};
18
18
  res = {};
19
- middleware = {
20
- init() {
21
- return function (req, res, next) {
22
- req._parsedUrl = {
23
- href: '/some/path?asdf=jkl',
24
- path: '/some/path?asdf=jkl',
25
- pathname: '/some/path',
26
- query: 'asdf=jkl',
27
- search: '?asdf=jkl;',
19
+ });
20
+
21
+ describe('express4', function() {
22
+ let middleware;
23
+
24
+ beforeEach(function() {
25
+ middleware = {
26
+ init() {
27
+ return function (req, res, next) {
28
+ req._parsedUrl = {
29
+ href: '/some/path?asdf=jkl',
30
+ path: '/some/path?asdf=jkl',
31
+ pathname: '/some/path',
32
+ query: 'asdf=jkl',
33
+ search: '?asdf=jkl;',
34
+ };
35
+ next();
28
36
  };
29
- next();
30
- };
31
- }
32
- };
33
-
34
- core.depHooks
35
- .resolve
36
- .withArgs({ name: 'express', version: '>=4.0.0 <5.0.0', file: 'lib/middleware/init.js' })
37
- .yields(middleware);
37
+ }
38
+ };
39
+
40
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'express' })).yields(middleware);
41
+ });
42
+
43
+ it('hooks init next in order to track req._parsedUrl values', function () {
44
+ instrumentation.install();
45
+ expect(patcher.isContrastHooked(middleware.init)).to.be.true;
46
+
47
+ const middlewareFn = middleware.init('text');
48
+
49
+ simulateRequestScope(() => {
50
+ const cb = sinon.spy(function () {
51
+ [
52
+ 'href',
53
+ 'path',
54
+ 'pathname',
55
+ 'query',
56
+ 'search',
57
+ ].forEach((prop) => {
58
+ const strInfo = tracker.getData(req._parsedUrl[prop]);
59
+ expect(strInfo).to.be.ok;
60
+ });
61
+ });
62
+
63
+ middlewareFn(req, res, cb);
64
+
65
+ expect(cb).to.have.been.called;
66
+ });
67
+ });
38
68
  });
39
69
 
40
- it('hooks init next in order to track req._parsedUrl values', function () {
41
- instrumentation.install();
42
- expect(patcher.isContrastHooked(middleware.init)).to.be.true;
70
+ describe('express5', function() {
71
+ let LayerMock;
72
+
73
+ beforeEach(function() {
74
+ req = {
75
+ _parsedUrl: {
76
+ href: '/some/path?asdf=jkl',
77
+ path: '/some/path?asdf=jkl',
78
+ pathname: '/some/path',
79
+ query: 'asdf=jkl',
80
+ search: '?asdf=jkl;',
81
+ }
82
+ };
43
83
 
44
- const middlewareFn = middleware.init('text');
84
+ LayerMock = sinon.stub();
85
+ LayerMock.prototype.handleRequest = sinon.stub();
45
86
 
46
- simulateRequestScope(() => {
47
- const cb = sinon.spy(function () {
87
+ core.depHooks.resolve.withArgs(sinon.match({ name: 'router' })).yields(LayerMock);
88
+ });
89
+
90
+ it('hooks handleRequest in order to track req._parsedUrl values', function () {
91
+ instrumentation.install();
92
+ simulateRequestScope(() => {
93
+ LayerMock.prototype.handleRequest(req);
48
94
  [
49
95
  'href',
50
96
  'path',
@@ -56,10 +102,6 @@ describe('assess dataflow sources express parsedUrl', function () {
56
102
  expect(strInfo).to.be.ok;
57
103
  });
58
104
  });
59
-
60
- middlewareFn(req, res, cb);
61
-
62
- expect(cb).to.have.been.called;
63
105
  });
64
106
  });
65
107
  });
@@ -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;
@@ -16,8 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../../constants');
20
-
21
19
  const { patchType } = require('../../common');
22
20
 
23
21
  const inputType = InputType.QUERYSTRING;
@@ -42,10 +40,10 @@ module.exports = (core) => {
42
40
  * registers a depHook for koa module instrumentation
43
41
  */
44
42
  function install() {
45
- depHooks.resolve({ name: 'koa', version: '>=2.3.0' }, (Koa) => {
43
+ depHooks.resolve({ name: 'koa', version: '>=2.3.0 <3' }, (Koa) => {
46
44
  const createMiddleware = ({ name, funcKey }) => {
47
45
  const contrastStartMiddleware = function contrastStartMiddleware(ctx, next) {
48
- const sourceContext = getSourceContext(SOURCE);
46
+ const sourceContext = getSourceContext();
49
47
 
50
48
  if (!sourceContext) {
51
49
  return next();
@@ -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,7 +31,7 @@ module.exports = (core) => {
32
31
  } = core;
33
32
 
34
33
  function handler(req, constructorOpt) {
35
- const sourceContext = getSourceContext(SOURCE);
34
+ const sourceContext = getSourceContext();
36
35
  if (!sourceContext) return;
37
36
 
38
37
  function handle(context, data, key) {
@@ -71,7 +70,7 @@ module.exports = (core) => {
71
70
  const multer1Instrumentation = (core.assess.dataflow.sources.multer1Instrumentation = {
72
71
  install() {
73
72
  depHooks.resolve(
74
- { name: 'multer', file: 'lib/make-middleware.js' },
73
+ { name: 'multer', version: '<2', file: 'lib/make-middleware.js' },
75
74
  (_export) => patcher.patch(_export, {
76
75
  name: 'multer._makeMiddleware',
77
76
  patchType,
@@ -29,9 +29,7 @@ describe('assess dataflow sources multer', function () {
29
29
 
30
30
  multer(core).install();
31
31
 
32
- const [patchedFunction] = core.depHooks.resolve
33
- .withArgs({ name: 'multer', file: 'lib/make-middleware.js' })
34
- .yield(multerMakeMiddlewareMock);
32
+ const [patchedFunction] = core.depHooks.resolve.yield(multerMakeMiddlewareMock);
35
33
  multerMakeMiddlewareMock = patchedFunction;
36
34
  });
37
35
 
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType: { QUERYSTRING: inputType } } = require('@contrast/common');
19
- const { InstrumentationType: { SOURCE } } = require('../../../constants');
20
19
  const { patchType } = require('../common');
21
20
 
22
21
  module.exports = (core) => {
@@ -33,15 +32,14 @@ module.exports = (core) => {
33
32
  // Patch `qs`
34
33
  function install() {
35
34
  const name = 'qs.parse';
36
- depHooks.resolve({ name: 'qs' },
35
+ depHooks.resolve({ name: 'qs', version: '<7' },
37
36
  (qs) => patcher.patch(qs, 'parse', {
38
37
  name,
39
38
  patchType,
40
39
  post({ args, hooked, orig, result, funcKey }) {
41
- const sourceContext = getSourceContext(SOURCE);
40
+ const sourceContext = getSourceContext();
42
41
 
43
42
  if (!sourceContext) {
44
- logger.error({ inputType, funcKey }, 'unable to handle source. Missing `sourceContext`');
45
43
  return;
46
44
  }
47
45
 
@@ -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,12 +29,12 @@ module.exports = (core) => {
30
29
  core.assess.dataflow.sources.querystringInstrumentation = {
31
30
  install() {
32
31
  const name = 'querystring.parse';
33
- depHooks.resolve({ name: 'querystring' },
32
+ depHooks.resolve({ name: 'querystring', version: '*' },
34
33
  (querystring) => patcher.patch(querystring, 'parse', {
35
34
  name,
36
35
  patchType,
37
36
  post({ args, hooked, orig, result, funcKey }) {
38
- const sourceContext = getSourceContext(SOURCE);
37
+ const sourceContext = getSourceContext();
39
38
  const inputType = InputType.QUERYSTRING;
40
39
 
41
40
  if (!sourceContext) return;
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType: { BODY } } = 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 core.assess.dataflow.sources.restifyInstrumentation.fieldedTextBodyParser = {
34
33
  install() {
35
34
  depHooks.resolve(
36
- { name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8' },
35
+ { name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8 <12' },
37
36
  (fieldedTextBodyParser) => patcher.patch(fieldedTextBodyParser, {
38
37
  name: 'restify.plugins.fieldedTextBodyParser',
39
38
  patchType,
@@ -44,7 +43,7 @@ module.exports = function init(core) {
44
43
  pre(data) {
45
44
  const { args: [req, , next], name, funcKey } = data;
46
45
  data.args[2] = function contrastNext(...args) {
47
- const sourceContext = getSourceContext(SOURCE);
46
+ const sourceContext = getSourceContext();
48
47
 
49
48
  if (!sourceContext) return next(...args);
50
49
 
@@ -20,7 +20,7 @@ describe('assess dataflow sources restify fieldedTextBodyParser', function () {
20
20
  next = sinon.stub();
21
21
 
22
22
  core.depHooks.resolve
23
- .withArgs({ name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8' })
23
+ .withArgs({ name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8 <12' })
24
24
  .callsFake((_, cb) => {
25
25
  fieldedTextBodyParserStub = cb(fieldedTextBodyParserStub);
26
26
  });
@@ -16,7 +16,6 @@
16
16
  'use strict';
17
17
 
18
18
  const { InputType: { JSON_VALUE } } = 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 core.assess.dataflow.sources.restifyInstrumentation.jsonBodyParser = {
34
33
  install() {
35
34
  depHooks.resolve(
36
- { name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8' },
35
+ { name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8 <12' },
37
36
  (jsonBodyParser) => patcher.patch(jsonBodyParser, {
38
37
  name: 'restify.plugins.jsonBodyParser',
39
38
  patchType,
@@ -48,7 +47,7 @@ module.exports = function init(core) {
48
47
  const { args: [req, , next], name, funcKey } = data;
49
48
 
50
49
  data.args[2] = function contrastNext(...args) {
51
- const sourceContext = getSourceContext(SOURCE);
50
+ const sourceContext = getSourceContext();
52
51
 
53
52
  if (!sourceContext) {
54
53
  return next(...args);
@@ -23,7 +23,7 @@ describe('assess dataflow sources restify jsonBodyParser', function () {
23
23
  next = sinon.stub();
24
24
 
25
25
  core.depHooks.resolve
26
- .withArgs({ name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8' })
26
+ .withArgs({ name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8 <12' })
27
27
  .callsFake((_, cb) => {
28
28
  jsonBodyParserStub = cb(jsonBodyParserStub);
29
29
  });