@contrast/assess 1.34.0 → 1.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/lib/crypto-analysis/install/crypto.js +1 -1
  2. package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
  3. package/lib/dataflow/propagation/install/JSON/parse.js +3 -2
  4. package/lib/dataflow/propagation/install/JSON/parse.test.js +2 -2
  5. package/lib/dataflow/propagation/install/JSON/stringify.js +11 -10
  6. package/lib/dataflow/propagation/install/JSON/stringify.test.js +3 -3
  7. package/lib/dataflow/propagation/install/array-prototype-join.js +4 -3
  8. package/lib/dataflow/propagation/install/array-prototype-join.test.js +3 -3
  9. package/lib/dataflow/propagation/install/buffer.js +2 -3
  10. package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +2 -2
  11. package/lib/dataflow/propagation/install/decode-uri-component.js +5 -8
  12. package/lib/dataflow/propagation/install/decode-uri-component.test.js +1 -1
  13. package/lib/dataflow/propagation/install/ejs/escape-xml.js +6 -9
  14. package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +2 -2
  15. package/lib/dataflow/propagation/install/ejs/template.js +2 -2
  16. package/lib/dataflow/propagation/install/encode-uri.js +4 -6
  17. package/lib/dataflow/propagation/install/encode-uri.test.js +2 -2
  18. package/lib/dataflow/propagation/install/escape-html.js +5 -8
  19. package/lib/dataflow/propagation/install/escape-html.test.js +3 -3
  20. package/lib/dataflow/propagation/install/escape.js +5 -8
  21. package/lib/dataflow/propagation/install/escape.test.js +2 -2
  22. package/lib/dataflow/propagation/install/fastify-send.js +3 -5
  23. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +6 -9
  24. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +1 -1
  25. package/lib/dataflow/propagation/install/joi/boolean.js +50 -52
  26. package/lib/dataflow/propagation/install/joi/expression.js +3 -10
  27. package/lib/dataflow/propagation/install/joi/index.js +98 -101
  28. package/lib/dataflow/propagation/install/joi/keys.js +10 -5
  29. package/lib/dataflow/propagation/install/joi/number.js +50 -52
  30. package/lib/dataflow/propagation/install/joi/string-schema.js +9 -14
  31. package/lib/dataflow/propagation/install/joi/utils.js +7 -4
  32. package/lib/dataflow/propagation/install/joi/values.js +5 -7
  33. package/lib/dataflow/propagation/install/mongoose/schema-map.js +5 -4
  34. package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +4 -4
  35. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +5 -4
  36. package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +4 -5
  37. package/lib/dataflow/propagation/install/mongoose/schema-string.js +3 -4
  38. package/lib/dataflow/propagation/install/mustache-escape.js +5 -8
  39. package/lib/dataflow/propagation/install/mustache-escape.test.js +2 -2
  40. package/lib/dataflow/propagation/install/mysql-connection-escape.js +5 -8
  41. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +2 -2
  42. package/lib/dataflow/propagation/install/parse-int.js +3 -3
  43. package/lib/dataflow/propagation/install/path/basename.js +7 -12
  44. package/lib/dataflow/propagation/install/path/basename.test.js +2 -2
  45. package/lib/dataflow/propagation/install/path/common.js +2 -2
  46. package/lib/dataflow/propagation/install/path/dirname.js +5 -10
  47. package/lib/dataflow/propagation/install/path/dirname.test.js +2 -2
  48. package/lib/dataflow/propagation/install/path/extname.js +6 -11
  49. package/lib/dataflow/propagation/install/path/extname.test.js +2 -2
  50. package/lib/dataflow/propagation/install/path/format.js +7 -13
  51. package/lib/dataflow/propagation/install/path/format.test.js +2 -2
  52. package/lib/dataflow/propagation/install/path/join-and-resolve.js +7 -12
  53. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +2 -2
  54. package/lib/dataflow/propagation/install/path/normalize.js +4 -11
  55. package/lib/dataflow/propagation/install/path/normalize.test.js +2 -2
  56. package/lib/dataflow/propagation/install/path/parse.js +3 -8
  57. package/lib/dataflow/propagation/install/path/parse.test.js +2 -2
  58. package/lib/dataflow/propagation/install/path/relative.js +5 -11
  59. package/lib/dataflow/propagation/install/path/relative.test.js +2 -2
  60. package/lib/dataflow/propagation/install/path/toNamespacedPath.js +5 -11
  61. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +2 -2
  62. package/lib/dataflow/propagation/install/pug/index.js +8 -3
  63. package/lib/dataflow/propagation/install/pug-runtime-escape.js +5 -8
  64. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +1 -1
  65. package/lib/dataflow/propagation/install/querystring/escape.js +3 -3
  66. package/lib/dataflow/propagation/install/querystring/parse.js +7 -11
  67. package/lib/dataflow/propagation/install/querystring/stringify.js +3 -3
  68. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +4 -3
  69. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +5 -3
  70. package/lib/dataflow/propagation/install/send.js +5 -10
  71. package/lib/dataflow/propagation/install/sequelize/query-generator.js +3 -4
  72. package/lib/dataflow/propagation/install/sequelize/sql-string.js +8 -12
  73. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +2 -13
  74. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -5
  75. package/lib/dataflow/propagation/install/sql-template-strings.test.js +2 -2
  76. package/lib/dataflow/propagation/install/string/concat.js +2 -1
  77. package/lib/dataflow/propagation/install/string/concat.test.js +15 -2
  78. package/lib/dataflow/propagation/install/string/format-methods.js +4 -2
  79. package/lib/dataflow/propagation/install/string/format-methods.test.js +15 -2
  80. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  81. package/lib/dataflow/propagation/install/string/html-methods.test.js +15 -2
  82. package/lib/dataflow/propagation/install/string/index.js +2 -2
  83. package/lib/dataflow/propagation/install/string/match-all.js +2 -1
  84. package/lib/dataflow/propagation/install/string/match-all.test.js +13 -0
  85. package/lib/dataflow/propagation/install/string/match.js +11 -10
  86. package/lib/dataflow/propagation/install/string/match.test.js +13 -0
  87. package/lib/dataflow/propagation/install/string/replace.js +15 -9
  88. package/lib/dataflow/propagation/install/string/replace.test.js +13 -0
  89. package/lib/dataflow/propagation/install/string/slice.js +2 -1
  90. package/lib/dataflow/propagation/install/string/slice.test.js +13 -0
  91. package/lib/dataflow/propagation/install/string/split.js +2 -1
  92. package/lib/dataflow/propagation/install/string/split.test.js +13 -0
  93. package/lib/dataflow/propagation/install/string/substring.js +2 -1
  94. package/lib/dataflow/propagation/install/string/substring.test.js +13 -0
  95. package/lib/dataflow/propagation/install/string/trim.js +4 -1
  96. package/lib/dataflow/propagation/install/string/trim.test.js +13 -0
  97. package/lib/dataflow/propagation/install/unescape.js +5 -8
  98. package/lib/dataflow/propagation/install/unescape.test.js +2 -2
  99. package/lib/dataflow/propagation/install/url/domain-parsers.js +4 -5
  100. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +2 -2
  101. package/lib/dataflow/propagation/install/url/parse.js +3 -2
  102. package/lib/dataflow/propagation/install/url/parse.test.js +2 -2
  103. package/lib/dataflow/propagation/install/url/searchParams.js +5 -5
  104. package/lib/dataflow/propagation/install/url/searchParams.test.js +2 -2
  105. package/lib/dataflow/propagation/install/url/url.js +6 -3
  106. package/lib/dataflow/propagation/install/url/url.test.js +2 -2
  107. package/lib/dataflow/propagation/install/util-format.js +7 -6
  108. package/lib/dataflow/propagation/install/util-format.test.js +2 -2
  109. package/lib/dataflow/propagation/install/validator/hooks.js +7 -2
  110. package/lib/dataflow/sinks/install/child-process.js +1 -1
  111. package/lib/dataflow/sinks/install/child-process.test.js +1 -1
  112. package/lib/dataflow/sinks/install/fs.js +1 -1
  113. package/lib/dataflow/sinks/install/fs.test.js +1 -1
  114. package/lib/dataflow/sinks/install/function.js +1 -1
  115. package/lib/dataflow/sinks/install/http/request.js +2 -1
  116. package/lib/dataflow/sinks/install/http/request.test.js +1 -1
  117. package/lib/dataflow/sinks/install/http/server-response.test.js +3 -5
  118. package/lib/dataflow/sinks/install/restify.js +1 -1
  119. package/lib/dataflow/sinks/install/vm.js +4 -2
  120. package/lib/dataflow/sinks/install/vm.test.js +1 -1
  121. package/lib/dataflow/sources/handler.js +6 -3
  122. package/lib/dataflow/sources/handler.test.js +38 -0
  123. package/lib/dataflow/sources/install/body-parser1.test.js +4 -4
  124. package/lib/dataflow/sources/install/busboy.js +8 -3
  125. package/lib/dataflow/sources/install/busboy.test.js +2 -2
  126. package/lib/dataflow/sources/install/cookie-parser1.test.js +2 -2
  127. package/lib/dataflow/sources/install/express/params.js +14 -11
  128. package/lib/dataflow/sources/install/express/params.test.js +5 -7
  129. package/lib/dataflow/sources/install/express/parsedUrl.js +3 -2
  130. package/lib/dataflow/sources/install/fastify/fastify.js +7 -6
  131. package/lib/dataflow/sources/install/fastify/fastify.test.js +2 -2
  132. package/lib/dataflow/sources/install/formidable1.js +7 -6
  133. package/lib/dataflow/sources/install/formidable1.test.js +2 -2
  134. package/lib/dataflow/sources/install/hapi/hapi.js +8 -10
  135. package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -1
  136. package/lib/dataflow/sources/install/http.js +20 -16
  137. package/lib/dataflow/sources/install/http.test.js +28 -34
  138. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +7 -7
  139. package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +3 -4
  140. package/lib/dataflow/sources/install/koa/koa-multer.js +8 -4
  141. package/lib/dataflow/sources/install/koa/koa-routers.js +7 -6
  142. package/lib/dataflow/sources/install/koa/koa-routers.test.js +2 -2
  143. package/lib/dataflow/sources/install/koa/koa2.js +7 -3
  144. package/lib/dataflow/sources/install/koa/koa2.test.js +1 -1
  145. package/lib/dataflow/sources/install/multer1.js +6 -2
  146. package/lib/dataflow/sources/install/qs6.js +1 -1
  147. package/lib/dataflow/sources/install/querystring.js +1 -1
  148. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +1 -4
  149. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +6 -8
  150. package/lib/dataflow/sources/install/restify/jsonBodyParser.js +0 -1
  151. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +4 -8
  152. package/lib/dataflow/sources/install/restify/router.test.js +2 -2
  153. package/lib/dataflow/tag-utils.js +1 -1
  154. package/lib/dataflow/tracker.js +1 -1
  155. package/lib/dataflow/utils/is-safe-content-type.js +3 -2
  156. package/lib/event-factory.js +4 -4
  157. package/lib/event-factory.test.js +19 -14
  158. package/lib/get-policy.js +2 -2
  159. package/lib/index.d.ts +11 -6
  160. package/lib/index.js +18 -7
  161. package/lib/index.test.js +4 -0
  162. package/lib/make-source-context.js +37 -28
  163. package/lib/make-source-context.test.js +7 -7
  164. package/lib/response-scanning/handlers/index.js +7 -5
  165. package/lib/response-scanning/handlers/utils.js +11 -8
  166. package/lib/response-scanning/install/http.js +1 -1
  167. package/lib/sampler.js +136 -0
  168. package/lib/sampler.test.js +296 -0
  169. package/lib/session-configuration/install/express-session.js +1 -1
  170. package/lib/session-configuration/install/fastify-cookie.js +1 -1
  171. package/package.json +10 -10
@@ -18,7 +18,7 @@
18
18
  const {
19
19
  Rule,
20
20
  isString,
21
- StringPrototypeToLowerCase,
21
+ primordials: { StringPrototypeToLowerCase },
22
22
  } = require('@contrast/common');
23
23
  const semver = require('semver');
24
24
  const { InstrumentationType: { RULE } } = require('../../constants');
@@ -14,7 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { StringPrototypeTrim } = require('@contrast/common');
17
+ const { primordials: { StringPrototypeTrim } } = require('@contrast/common');
18
18
 
19
19
  function isNumber(value) {
20
20
  return !isNaN(value);
@@ -16,6 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const { isString } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
19
20
  const { createSubsetTags } = require('../../../tag-utils');
20
21
  const { patchType } = require('../../common');
21
22
  const { getKeyValueIndices } = require('./parse-fn');
@@ -47,9 +48,9 @@ const applyValuesToObject = (object, stack) => {
47
48
  module.exports = function (core) {
48
49
  const {
49
50
  logger,
50
- scopes: { sources, instrumentation },
51
51
  patcher,
52
52
  assess: {
53
+ getSourceContext,
53
54
  eventFactory: { createPropagationEvent },
54
55
  dataflow: { tracker },
55
56
  },
@@ -100,7 +101,7 @@ module.exports = function (core) {
100
101
  name: 'JSON.parse',
101
102
  patchType,
102
103
  pre(data) {
103
- if (!data.args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
104
+ if (!data.args[0] || !getSourceContext(PROPAGATOR)) return;
104
105
  const [input, reviver] = data.args;
105
106
 
106
107
  const strInfo = tracker.getData(input);
@@ -123,7 +123,7 @@ describe('assess dataflow propagation JSON parse', function () {
123
123
  });
124
124
  });
125
125
 
126
- it('will not propagate if there is no assess context', function () {
126
+ it('will not propagate if there is no assess policy in request context', function () {
127
127
  simulateRequestScope(function () {
128
128
  const trackedString = trackString('foo');
129
129
  const string = JSON.stringify({ prop: trackedString });
@@ -131,7 +131,7 @@ describe('assess dataflow propagation JSON parse', function () {
131
131
 
132
132
  expect(result.prop).to.be.equal('foo');
133
133
  expect(tracker.getData(result.prop)).to.be.null;
134
- }, {});
134
+ }, { assess: { policy: null } });
135
135
  });
136
136
 
137
137
  it('should ignore empty string', function () {
@@ -17,13 +17,16 @@
17
17
 
18
18
  const {
19
19
  isString,
20
- ArrayPrototypeSlice,
21
- StringPrototypeReplace,
22
- StringPrototypeMatch,
23
- StringPrototypeMatchAll,
24
- StringPrototypeSlice,
20
+ primordials: {
21
+ ArrayPrototypeSlice,
22
+ StringPrototypeReplace,
23
+ StringPrototypeMatch,
24
+ StringPrototypeMatchAll,
25
+ StringPrototypeSlice,
26
+ }
25
27
  } = require('@contrast/common');
26
28
  const crypto = require('crypto');
29
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
27
30
  const { createMergedTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
28
31
  const { patchType } = require('../../common');
29
32
 
@@ -78,9 +81,9 @@ function patchReplacer(replacer) {
78
81
 
79
82
  module.exports = function(core) {
80
83
  const {
81
- scopes: { sources, instrumentation },
82
84
  patcher,
83
85
  assess: {
86
+ getSourceContext,
84
87
  eventFactory: { createPropagationEvent },
85
88
  dataflow: { tracker }
86
89
  }
@@ -92,8 +95,6 @@ module.exports = function(core) {
92
95
  if (!isString(space) || StringPrototypeMatch.call(space, /^\s+$/) || !space) {
93
96
  return null;
94
97
  }
95
-
96
-
97
98
  const props = tracker.getData(StringPrototypeSlice.call(space, 0, 10));
98
99
  if (!props || !Object.keys(props.tags).length) {
99
100
  return null;
@@ -165,7 +166,7 @@ module.exports = function(core) {
165
166
  name: 'JSON.stringify',
166
167
  patchType,
167
168
  pre(data) {
168
- if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
169
+ if (!getSourceContext(PROPAGATOR)) return;
169
170
 
170
171
  const [input, , space] = data.args;
171
172
  let [, replacer] = data.args;
@@ -222,7 +223,7 @@ module.exports = function(core) {
222
223
  data.args = [input, contrastReplacer, space];
223
224
  },
224
225
  post(data) {
225
- if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
226
+ if (!getSourceContext(PROPAGATOR)) return;
226
227
  let tags = {};
227
228
  const vulnerableSources = [];
228
229
  if (!data.metadata?.propagate) {
@@ -3,7 +3,7 @@
3
3
  const { expect } = require('chai');
4
4
  const { initAssessFixture } = require('@contrast/test/fixtures');
5
5
  const {
6
- UtilInspect,
6
+ primordials: { UtilInspect },
7
7
  DataflowTag: { UNTRUSTED },
8
8
  } = require('@contrast/common');
9
9
  const origStringify = JSON.stringify;
@@ -80,12 +80,12 @@ describe('assess dataflow propagation JSON stringify', function () {
80
80
  });
81
81
  });
82
82
 
83
- it('results in an untracked string when there is no Assess scope', function () {
83
+ it('results in an untracked string when there is no Assess policy in request scope', function () {
84
84
  simulateRequestScope(() => {
85
85
  const ret = JSON.stringify(objWithTrackedStr);
86
86
  expect(ret).to.equal(origStringify(objWithTrackedStr));
87
87
  expect(tracker.getData(ret)).to.be.null;
88
- }, {});
88
+ }, { assess: { policy: null } });
89
89
  });
90
90
 
91
91
  it('results in an untracked string when instrumentation is locked', function () {
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { isString, ArrayPrototypeJoin, UtilInspect } = require('@contrast/common');
18
+ const { isString, primordials: { ArrayPrototypeJoin } } = require('@contrast/common');
19
19
  const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
20
  const { createAppendTags } = require('../../tag-utils');
21
21
  const { patchType } = require('../common');
@@ -24,6 +24,7 @@ module.exports = function(core) {
24
24
  const {
25
25
  patcher,
26
26
  assess: {
27
+ inspect,
27
28
  getSourceContext,
28
29
  eventFactory: { createPropagationEvent },
29
30
  dataflow: { tracker }
@@ -70,7 +71,7 @@ module.exports = function(core) {
70
71
  patchType,
71
72
  post(data) {
72
73
  const { args: origArgs, obj, result, hooked, orig } = data;
73
- if (!result || !(getSourceContext(PROPAGATOR))) return;
74
+ if (!result || !getSourceContext(PROPAGATOR)) return;
74
75
 
75
76
  const resultInfo = tracker.getData(result);
76
77
  const delimiter = origArgs[0] === undefined ? ',' : origArgs[0];
@@ -93,7 +94,7 @@ module.exports = function(core) {
93
94
  name,
94
95
  moduleName: 'Array',
95
96
  methodName: 'prototype.join',
96
- context: `${object.value}.join('${UtilInspect(args[0].value) || ''})`,
97
+ context: `${object.value}.join('${inspect(args[0].value) || ''})`,
97
98
  object,
98
99
  result: {
99
100
  value: resultInfo ? resultInfo.value : result,
@@ -62,7 +62,7 @@ describe('assess dataflow propagation array join', function () {
62
62
  });
63
63
  });
64
64
 
65
- it('propagates correclty nested arrays', function () {
65
+ it('propagates correctly nested arrays', function () {
66
66
  simulateRequestScope(function () {
67
67
  const str = trackString('tracked', { tags: { untrusted: [0, 6] } });
68
68
  const arr = [
@@ -86,12 +86,12 @@ describe('assess dataflow propagation array join', function () {
86
86
  });
87
87
  });
88
88
 
89
- it('will not propagate if there is no assess context', function () {
89
+ it('will not propagate if there is no assess policy in source context', function () {
90
90
  simulateRequestScope(function () {
91
91
  const value = trackString('foo');
92
92
  const result = ['not-tracked', value].join();
93
93
  expect(tracker.getData(result)).to.be.null;
94
- }, {});
94
+ }, { assess: { policy: null } });
95
95
  });
96
96
 
97
97
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,7 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { isString, ArrayPrototypeJoin, StringPrototypeSubstring } = require('@contrast/common');
17
+ const { isString, primordials: { ArrayPrototypeJoin, StringPrototypeSubstring, BufferPrototypeToString } } = require('@contrast/common');
18
18
  const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
19
19
  const { getAdjustedUntrackedValue } = require('../../tag-utils');
20
20
  const { patchType } = require('../common');
@@ -32,7 +32,6 @@ module.exports = function(core) {
32
32
  return core.assess.dataflow.propagation.bufferInstrumentation = {
33
33
  install() {
34
34
  const name = 'global.Buffer.prototype.toString';
35
- const bufferToString = patcher.unwrap(Buffer.prototype.toString);
36
35
 
37
36
  patcher.patch(global.Buffer.prototype, 'toString', {
38
37
  patchType,
@@ -99,7 +98,7 @@ module.exports = function(core) {
99
98
  if (trkInfo) {
100
99
  const args = data.args.map((arg, i) => {
101
100
  if (i == 0) {
102
- const value = argType == 'string' ? arg : bufferToString.call(arg);
101
+ const value = argType == 'string' ? arg : BufferPrototypeToString.call(arg);
103
102
  // todo (NODE-3455): make sure tag ranges are included in substring
104
103
  return { tracked: true, value: StringPrototypeSubstring.call(value, 0, 50) };
105
104
  } else {
@@ -135,11 +135,11 @@ describe('assess dataflow propagation contrast-methods tag', function () {
135
135
  });
136
136
  });
137
137
 
138
- it('does not propagate if not in proper scope', function () {
138
+ it('does not propagate if no assess policy in request store', function () {
139
139
  simulateRequestScope(() => {
140
140
  const result = global.ContrastMethods.tag(['', ''], trackString('bar'));
141
141
  const data = tracker.getData(result);
142
142
  expect(data).to.be.null;
143
- }, null);
143
+ }, { assess: { policy: null } });
144
144
  });
145
145
  });
@@ -15,19 +15,16 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { URL_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { URL_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createFullLengthCopyTags } = require('../../tag-utils');
24
21
  const { patchType, createObjectLabel } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  assess: {
27
+ getSourceContext,
31
28
  eventFactory: { createPropagationEvent },
32
29
  dataflow: { tracker }
33
30
  }
@@ -42,7 +39,7 @@ module.exports = function(core) {
42
39
  patchType,
43
40
  post(data) {
44
41
  const { args, result, hooked, orig } = data;
45
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
46
43
 
47
44
  const argInfo = tracker.getData(args[0]);
48
45
 
@@ -63,7 +63,7 @@ describe('assess dataflow propagation decodeURIComponent', function () {
63
63
  const value = trackString('%3Ftest%3Dstr');
64
64
  const result = decodeURIComponent(value);
65
65
  expect(tracker.getData(result)).to.be.null;
66
- }, {});
66
+ }, { assess: { policy: null } });
67
67
  });
68
68
 
69
69
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { WEAK_URL_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../../tag-utils');
18
+ const { DataflowTag: { WEAK_URL_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
20
+ const { createFullLengthCopyTags } = require('../../../tag-utils');
24
21
  const { patchType } = require('../../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  depHooks,
31
27
  assess: {
28
+ getSourceContext,
32
29
  eventFactory: { createPropagationEvent },
33
30
  dataflow: { tracker }
34
31
  }
@@ -36,14 +33,14 @@ module.exports = function(core) {
36
33
 
37
34
  return core.assess.dataflow.propagation.ejsInstrumentation.escapeXML = {
38
35
  install() {
39
- depHooks.resolve({ name: 'ejs', file: 'lib/utils.js', version: '>=2.6.2' }, (ejsUtils, version) => {
36
+ depHooks.resolve({ name: 'ejs', file: 'lib/utils.js', version: '>=2.6.2' }, (ejsUtils) => {
40
37
  const name = 'ejs.utils.escapeXML';
41
38
  patcher.patch(ejsUtils, 'escapeXML', {
42
39
  name,
43
40
  patchType,
44
41
  post(data) {
45
42
  const { args, result, hooked, orig } = data;
46
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
43
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
47
44
 
48
45
  const argInfo = tracker.getData(args[0]);
49
46
 
@@ -49,12 +49,12 @@ describe('assess dataflow propagation ejs.utils.escapeXML', function () {
49
49
  });
50
50
  });
51
51
 
52
- it('will not propagate if there is no assess context', function () {
52
+ it('will not propagate if there is no assess policy in request context', function () {
53
53
  simulateRequestScope(function () {
54
54
  const value = trackString('foo');
55
55
  const result = mockEjsUtils.escapeXML(value);
56
56
  expect(tracker.getData(result)).to.be.null;
57
- }, {});
57
+ }, { assess: { policy: null } });
58
58
  });
59
59
 
60
60
  it('will not propagate if there instrumentation is locked', function () {
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
 
18
18
  const { EOL } = require('os');
19
- const { ArrayPrototypeJoin } = require('@contrast/common');
19
+ const { primordials: { ArrayPrototypeJoin, StringPrototypeSubstring } } = require('@contrast/common');
20
20
  const { patchType } = require('../../common');
21
21
  const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
22
22
 
@@ -65,7 +65,7 @@ module.exports = function (core) {
65
65
 
66
66
  try {
67
67
  const { code } = rewriter.rewriteSync(`${WRAPPER_PREFIX}${data.obj.source}${WRAPPER_SUFFIX}`, REWRITE_OPTS);
68
- data.obj.source = code.substring(code.indexOf('{') + 1, code.lastIndexOf('}'));
68
+ data.obj.source = StringPrototypeSubstring.call(code, code.indexOf('{') + 1, code.lastIndexOf('}'));
69
69
  } catch (err) {
70
70
  logger.error(
71
71
  { err, funcKey: data.funcKey, source: data.obj.source },
@@ -18,16 +18,15 @@
18
18
  const {
19
19
  DataflowTag: { URL_ENCODED, WEAK_URL_ENCODED }
20
20
  } = require('@contrast/common');
21
- const {
22
- createEscapeTagRanges
23
- } = require('../../tag-utils');
21
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
22
+ const { createEscapeTagRanges } = require('../../tag-utils');
24
23
  const { patchType, createObjectLabel } = require('../common');
25
24
 
26
25
  module.exports = function(core) {
27
26
  const {
28
- scopes: { sources, instrumentation },
29
27
  patcher,
30
28
  assess: {
29
+ getSourceContext,
31
30
  eventFactory: { createPropagationEvent },
32
31
  dataflow: { tracker }
33
32
  }
@@ -35,7 +34,6 @@ module.exports = function(core) {
35
34
 
36
35
  return core.assess.dataflow.propagation.encodeURI = {
37
36
  install() {
38
-
39
37
  [
40
38
  {
41
39
  methodName: 'encodeURIComponent',
@@ -52,7 +50,7 @@ module.exports = function(core) {
52
50
  patchType,
53
51
  post(data) {
54
52
  const { args, result, hooked, orig } = data;
55
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
53
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
56
54
 
57
55
  const argInfo = tracker.getData(args[0]);
58
56
 
@@ -27,12 +27,12 @@ describe('assess dataflow propagation encodeURI, encodeURIComponent', function (
27
27
  sinon.resetHistory();
28
28
  });
29
29
 
30
- it('will not propagate if there is no assess context', function () {
30
+ it('will not propagate if there is no assess policy in request context', function () {
31
31
  simulateRequestScope(function () {
32
32
  const value = trackString('?test=str');
33
33
  const result = encodeURIComponent(value);
34
34
  expect(tracker.getData(result)).to.be.null;
35
- }, {});
35
+ }, { assess: { policy: null } });
36
36
  });
37
37
 
38
38
  it('will not propagate if there instrumentation is locked', function () {
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { HTML_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createEscapeTagRanges
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { HTML_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createEscapeTagRanges } = require('../../tag-utils');
24
21
  const { patchType } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  depHooks,
31
27
  assess: {
28
+ getSourceContext,
32
29
  eventFactory: { createPropagationEvent },
33
30
  dataflow: { tracker }
34
31
  }
@@ -44,7 +41,7 @@ module.exports = function(core) {
44
41
  patchType,
45
42
  post(data) {
46
43
  const { args, result, hooked, orig } = data;
47
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
44
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
48
45
 
49
46
  const argInfo = tracker.getData(args[0]);
50
47
 
@@ -28,12 +28,12 @@ describe('assess dataflow propagation escape-html', function () {
28
28
  sinon.resetHistory();
29
29
  });
30
30
 
31
- it('will not propagate if there is no assess context', function () {
31
+ it('will not propagate if there is no assess policy in request context', function () {
32
32
  simulateRequestScope(function () {
33
33
  const value = trackString('<script>alert("hello");</script>');
34
34
  const result = patchedEscapeHtml(value);
35
35
  expect(tracker.getData(result)).to.be.null;
36
- }, {});
36
+ }, { assess: { policy: null } });
37
37
  });
38
38
 
39
39
  it('will not propagate if there instrumentation is locked', function () {
@@ -51,7 +51,7 @@ describe('assess dataflow propagation escape-html', function () {
51
51
  const value = '<script>alert("hello");</script>';
52
52
  const result = patchedEscapeHtml(value);
53
53
  expect(tracker.getData(result)).to.be.null;
54
- }, {});
54
+ });
55
55
  });
56
56
 
57
57
 
@@ -15,19 +15,16 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { WEAK_URL_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { WEAK_URL_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createFullLengthCopyTags } = require('../../tag-utils');
24
21
  const { patchType, createObjectLabel } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  assess: {
27
+ getSourceContext,
31
28
  eventFactory: { createPropagationEvent },
32
29
  dataflow: { tracker }
33
30
  }
@@ -42,7 +39,7 @@ module.exports = function(core) {
42
39
  patchType,
43
40
  post(data) {
44
41
  const { args, result, hooked, orig } = data;
45
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
42
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
46
43
 
47
44
  const argInfo = tracker.getData(args[0]);
48
45
 
@@ -53,12 +53,12 @@ describe('assess dataflow propagation escape', function () {
53
53
  });
54
54
  });
55
55
 
56
- it('will not propagate if there is no assess context', function () {
56
+ it('will not propagate if there is no assess policy in request context', function () {
57
57
  simulateRequestScope(function () {
58
58
  const value = trackString('?test=str');
59
59
  const result = escape(value);
60
60
  expect(tracker.getData(result)).to.be.null;
61
- }, {});
61
+ }, { assess: { policy: null } });
62
62
  });
63
63
 
64
64
  it('will not propagate if there instrumentation is locked', function () {
@@ -14,14 +14,14 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
+ const { primordials: { StringPrototypeSlice } } = require('@contrast/common');
17
18
  const { patchType } = require('../common');
18
- const { StringPrototypeSlice } = require('@contrast/common');
19
19
 
20
20
  module.exports = function (core) {
21
21
  const {
22
22
  depHooks,
23
23
  patcher,
24
- scopes: { sources, instrumentation },
24
+ assess: { getSourceContext }
25
25
  } = core;
26
26
 
27
27
  return core.assess.dataflow.propagation.fastifySend = {
@@ -33,9 +33,7 @@ module.exports = function (core) {
33
33
  pre(data) {
34
34
  const { args } = data;
35
35
 
36
- if (!sources.getStore()?.assess || instrumentation.isLocked()) {
37
- return;
38
- }
36
+ if (!getSourceContext()) return;
39
37
 
40
38
  const untrackedPath = StringPrototypeSlice.call(` ${args[0]}`, 1);
41
39
  args[0] = untrackedPath;
@@ -15,20 +15,17 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const {
19
- DataflowTag: { HTML_ENCODED }
20
- } = require('@contrast/common');
21
- const {
22
- createFullLengthCopyTags
23
- } = require('../../tag-utils');
18
+ const { DataflowTag: { HTML_ENCODED } } = require('@contrast/common');
19
+ const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
20
+ const { createFullLengthCopyTags } = require('../../tag-utils');
24
21
  const { patchType } = require('../common');
25
22
 
26
23
  module.exports = function(core) {
27
24
  const {
28
- scopes: { sources, instrumentation },
29
25
  patcher,
30
26
  depHooks,
31
27
  assess: {
28
+ getSourceContext,
32
29
  eventFactory: { createPropagationEvent },
33
30
  dataflow: { tracker }
34
31
  }
@@ -36,7 +33,7 @@ module.exports = function(core) {
36
33
 
37
34
  return core.assess.dataflow.propagation.handlebarsEscapeExpression = {
38
35
  install() {
39
- depHooks.resolve({ name: 'handlebars', version: '>=4.0.0' }, (handlebars, version) => {
36
+ depHooks.resolve({ name: 'handlebars', version: '>=4.0.0' }, (handlebars) => {
40
37
  const name = 'handlebars.Utils.escapeExpression';
41
38
 
42
39
  patcher.patch(handlebars.Utils, 'escapeExpression', {
@@ -44,7 +41,7 @@ module.exports = function(core) {
44
41
  patchType,
45
42
  post(data) {
46
43
  const { args, result, hooked, orig } = data;
47
- if (!result || !args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
44
+ if (!result || !args[0] || !getSourceContext(PROPAGATOR)) return;
48
45
 
49
46
  const argInfo = tracker.getData(args[0]);
50
47
 
@@ -56,7 +56,7 @@ describe('assess dataflow propagation handlebars.Utils.escapeExpression', functi
56
56
  const value = trackString('foo');
57
57
  const result = mockHandlebars.Utils.escapeExpression(value);
58
58
  expect(tracker.getData(result)).to.be.null;
59
- }, {});
59
+ }, { assess: { policy: null } });
60
60
  });
61
61
 
62
62
  it('will not propagate if there instrumentation is locked', function () {