@contrast/agent 4.5.1 → 4.7.1

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 (209) hide show
  1. package/bin/VERSION +1 -1
  2. package/bin/linux/contrast-service +0 -0
  3. package/bin/mac/contrast-service +0 -0
  4. package/bin/windows/contrast-service.exe +0 -0
  5. package/lib/assess/membrane/deserialization-membrane.js +4 -5
  6. package/lib/assess/membrane/source-membrane.js +16 -33
  7. package/lib/assess/models/call-context.js +1 -1
  8. package/lib/assess/policy/propagators.json +19 -21
  9. package/lib/assess/policy/rules.json +7 -2
  10. package/lib/assess/policy/signatures.json +42 -0
  11. package/lib/assess/policy/util.js +2 -1
  12. package/lib/assess/propagators/JSON/parse.js +1 -1
  13. package/lib/assess/propagators/JSON/stringify.js +3 -3
  14. package/lib/assess/propagators/array-prototype-join.js +7 -8
  15. package/lib/assess/propagators/common.js +7 -5
  16. package/lib/assess/propagators/dustjs/escape-html.js +22 -0
  17. package/lib/assess/propagators/dustjs/escape-js.js +22 -0
  18. package/lib/assess/propagators/encode-uri/encode-uri-component.js +22 -0
  19. package/lib/assess/propagators/encode-uri/encode-uri.js +22 -0
  20. package/lib/assess/propagators/handlebars-escape-expresssion.js +1 -1
  21. package/lib/assess/propagators/index.js +0 -2
  22. package/lib/assess/propagators/joi/boolean.js +1 -1
  23. package/lib/assess/propagators/joi/expression.js +1 -1
  24. package/lib/assess/propagators/joi/number.js +1 -1
  25. package/lib/assess/propagators/joi/string-base.js +1 -1
  26. package/lib/assess/propagators/joi/string-schema.js +12 -13
  27. package/lib/assess/propagators/joi/values.js +37 -22
  28. package/lib/assess/propagators/manager.js +12 -10
  29. package/lib/assess/propagators/mongoose/helpers.js +20 -0
  30. package/lib/assess/propagators/mongoose/index.js +18 -0
  31. package/lib/assess/propagators/mongoose/map.js +74 -0
  32. package/lib/assess/propagators/mongoose/string.js +104 -0
  33. package/lib/assess/propagators/mustache/escape.js +22 -0
  34. package/lib/assess/propagators/number.js +54 -0
  35. package/lib/assess/propagators/object.js +6 -7
  36. package/lib/assess/propagators/path/basename.js +14 -13
  37. package/lib/assess/propagators/path/common.js +156 -47
  38. package/lib/assess/propagators/path/dirname.js +14 -13
  39. package/lib/assess/propagators/path/extname.js +14 -13
  40. package/lib/assess/propagators/path/join.js +5 -1
  41. package/lib/assess/propagators/path/normalize.js +1 -2
  42. package/lib/assess/propagators/path/parse.js +1 -1
  43. package/lib/assess/propagators/path/relative.js +7 -5
  44. package/lib/assess/propagators/path/resolve.js +11 -2
  45. package/lib/assess/propagators/querystring/escape.js +20 -18
  46. package/lib/assess/propagators/querystring/parse.js +7 -5
  47. package/lib/assess/propagators/querystring/stringify.js +25 -24
  48. package/lib/assess/propagators/querystring/unescape.js +20 -18
  49. package/lib/assess/propagators/sequelize/sql-string-escape.js +1 -1
  50. package/lib/assess/propagators/sequelize/sql-string-format-named-parameters.js +1 -1
  51. package/lib/assess/propagators/sequelize/sql-string-format.js +3 -3
  52. package/lib/assess/propagators/sequelize/utils.js +2 -2
  53. package/lib/assess/propagators/string-prototype-replace.js +30 -28
  54. package/lib/assess/propagators/string-prototype-split.js +36 -36
  55. package/lib/assess/propagators/string-prototype-trim.js +15 -17
  56. package/lib/assess/propagators/string.js +12 -16
  57. package/lib/assess/propagators/template-escape.js +87 -0
  58. package/lib/assess/propagators/templates.js +10 -11
  59. package/lib/assess/propagators/url/url-prototype-parse.js +5 -6
  60. package/lib/assess/propagators/url/url-url.js +51 -43
  61. package/lib/assess/propagators/util/format.js +1 -1
  62. package/lib/assess/propagators/v8/init-hooks.js +3 -3
  63. package/lib/assess/propagators/validator/init-hooks.js +22 -22
  64. package/lib/assess/sinks/common.js +10 -5
  65. package/lib/assess/sinks/dustjs-linkedin-xss.js +131 -0
  66. package/lib/assess/sinks/libxmljs-xxe.js +1 -1
  67. package/lib/assess/sinks/mongodb.js +2 -1
  68. package/lib/assess/sinks/ssrf-url.js +1 -1
  69. package/lib/constants.js +4 -1
  70. package/lib/core/arch-components/dynamodb.js +1 -2
  71. package/lib/core/arch-components/dynamodbv3.js +44 -0
  72. package/lib/core/arch-components/index.js +1 -0
  73. package/lib/core/arch-components/rethinkdb.js +53 -0
  74. package/lib/core/config/options.js +3 -2
  75. package/lib/core/rewrite/injections.js +8 -0
  76. package/lib/core/stacktrace.js +2 -1
  77. package/lib/feature-set.js +1 -1
  78. package/lib/hooks/frameworks/base.js +8 -2
  79. package/lib/hooks/frameworks/http.js +23 -16
  80. package/lib/hooks/frameworks/http2.js +73 -0
  81. package/lib/hooks/frameworks/index.js +8 -3
  82. package/lib/hooks/http.js +112 -128
  83. package/lib/hooks/object-to-primitive.js +6 -7
  84. package/lib/hooks/patcher.js +75 -44
  85. package/lib/hooks/require.js +16 -22
  86. package/lib/instrumentation.js +0 -3
  87. package/lib/protect/rules/nosqli/nosql-injection-rule.js +228 -0
  88. package/lib/protect/rules/rule-factory.js +2 -2
  89. package/lib/protect/service.js +23 -11
  90. package/lib/protect/sinks/mongodb.js +56 -55
  91. package/lib/reporter/translations/to-protobuf/dtm/index.js +1 -1
  92. package/lib/reporter/translations/to-protobuf/dtm/ip-denylist-details.js +1 -1
  93. package/lib/reporter/translations/to-protobuf/dtm/rasp-rule-sample.js +1 -1
  94. package/lib/reporter/translations/to-protobuf/settings/defend-features.js +8 -6
  95. package/lib/reporter/translations/to-protobuf/settings/exclusions.js +5 -4
  96. package/lib/tracker.js +13 -65
  97. package/lib/util/some.js +27 -0
  98. package/lib/util/source-map.js +1 -1
  99. package/package.json +15 -16
  100. package/lib/hooks/frameworks/https.js +0 -42
  101. package/lib/protect/rules/nosqli/no-sql-injection-rule.js +0 -109
  102. package/node_modules/bindings/LICENSE.md +0 -22
  103. package/node_modules/bindings/README.md +0 -98
  104. package/node_modules/bindings/bindings.js +0 -221
  105. package/node_modules/bindings/package.json +0 -32
  106. package/node_modules/file-uri-to-path/.npmignore +0 -1
  107. package/node_modules/file-uri-to-path/.travis.yml +0 -30
  108. package/node_modules/file-uri-to-path/History.md +0 -21
  109. package/node_modules/file-uri-to-path/LICENSE +0 -20
  110. package/node_modules/file-uri-to-path/README.md +0 -74
  111. package/node_modules/file-uri-to-path/index.d.ts +0 -2
  112. package/node_modules/file-uri-to-path/index.js +0 -66
  113. package/node_modules/file-uri-to-path/package.json +0 -36
  114. package/node_modules/file-uri-to-path/test/test.js +0 -24
  115. package/node_modules/file-uri-to-path/test/tests.json +0 -13
  116. package/node_modules/glossy/LICENSE +0 -19
  117. package/node_modules/glossy/README.md +0 -129
  118. package/node_modules/glossy/index.js +0 -12
  119. package/node_modules/glossy/lib/glossy/parse.js +0 -520
  120. package/node_modules/glossy/lib/glossy/produce.js +0 -459
  121. package/node_modules/glossy/package.json +0 -47
  122. package/node_modules/glossy/test/decide.js +0 -7
  123. package/node_modules/glossy/test/decode_pri.js +0 -24
  124. package/node_modules/glossy/test/parse_3164.js +0 -104
  125. package/node_modules/glossy/test/parse_5424.js +0 -106
  126. package/node_modules/glossy/test/parse_5848.js +0 -40
  127. package/node_modules/glossy/test/parse_8601.js +0 -14
  128. package/node_modules/glossy/test/parse_rfc3339.js +0 -9
  129. package/node_modules/glossy/test/produce.js +0 -162
  130. package/node_modules/glossy/test/runner.js +0 -40
  131. package/node_modules/glossy/test/structure_data.js +0 -24
  132. package/node_modules/nan/CHANGELOG.md +0 -537
  133. package/node_modules/nan/LICENSE.md +0 -13
  134. package/node_modules/nan/README.md +0 -455
  135. package/node_modules/nan/doc/asyncworker.md +0 -146
  136. package/node_modules/nan/doc/buffers.md +0 -54
  137. package/node_modules/nan/doc/callback.md +0 -76
  138. package/node_modules/nan/doc/converters.md +0 -41
  139. package/node_modules/nan/doc/errors.md +0 -226
  140. package/node_modules/nan/doc/json.md +0 -62
  141. package/node_modules/nan/doc/maybe_types.md +0 -583
  142. package/node_modules/nan/doc/methods.md +0 -664
  143. package/node_modules/nan/doc/new.md +0 -147
  144. package/node_modules/nan/doc/node_misc.md +0 -123
  145. package/node_modules/nan/doc/object_wrappers.md +0 -263
  146. package/node_modules/nan/doc/persistent.md +0 -296
  147. package/node_modules/nan/doc/scopes.md +0 -73
  148. package/node_modules/nan/doc/script.md +0 -38
  149. package/node_modules/nan/doc/string_bytes.md +0 -62
  150. package/node_modules/nan/doc/v8_internals.md +0 -199
  151. package/node_modules/nan/doc/v8_misc.md +0 -85
  152. package/node_modules/nan/include_dirs.js +0 -1
  153. package/node_modules/nan/nan.h +0 -2898
  154. package/node_modules/nan/nan_callbacks.h +0 -88
  155. package/node_modules/nan/nan_callbacks_12_inl.h +0 -514
  156. package/node_modules/nan/nan_callbacks_pre_12_inl.h +0 -520
  157. package/node_modules/nan/nan_converters.h +0 -72
  158. package/node_modules/nan/nan_converters_43_inl.h +0 -68
  159. package/node_modules/nan/nan_converters_pre_43_inl.h +0 -42
  160. package/node_modules/nan/nan_define_own_property_helper.h +0 -29
  161. package/node_modules/nan/nan_implementation_12_inl.h +0 -430
  162. package/node_modules/nan/nan_implementation_pre_12_inl.h +0 -263
  163. package/node_modules/nan/nan_json.h +0 -166
  164. package/node_modules/nan/nan_maybe_43_inl.h +0 -356
  165. package/node_modules/nan/nan_maybe_pre_43_inl.h +0 -268
  166. package/node_modules/nan/nan_new.h +0 -340
  167. package/node_modules/nan/nan_object_wrap.h +0 -156
  168. package/node_modules/nan/nan_persistent_12_inl.h +0 -132
  169. package/node_modules/nan/nan_persistent_pre_12_inl.h +0 -242
  170. package/node_modules/nan/nan_private.h +0 -73
  171. package/node_modules/nan/nan_string_bytes.h +0 -305
  172. package/node_modules/nan/nan_typedarray_contents.h +0 -96
  173. package/node_modules/nan/nan_weak.h +0 -437
  174. package/node_modules/nan/package.json +0 -41
  175. package/node_modules/nan/tools/1to2.js +0 -412
  176. package/node_modules/nan/tools/README.md +0 -14
  177. package/node_modules/nan/tools/package.json +0 -19
  178. package/node_modules/unix-dgram/LICENSE +0 -13
  179. package/node_modules/unix-dgram/README.md +0 -107
  180. package/node_modules/unix-dgram/binding.gyp +0 -20
  181. package/node_modules/unix-dgram/build/Makefile +0 -324
  182. package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram/src/unix_dgram.o.d +0 -58
  183. package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram.node.d +0 -1
  184. package/node_modules/unix-dgram/build/Release/.deps/Release/unix_dgram.node.d +0 -1
  185. package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram/src/unix_dgram.o +0 -0
  186. package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram.node +0 -0
  187. package/node_modules/unix-dgram/build/Release/unix_dgram.node +0 -0
  188. package/node_modules/unix-dgram/build/binding.Makefile +0 -6
  189. package/node_modules/unix-dgram/build/config.gypi +0 -213
  190. package/node_modules/unix-dgram/build/unix_dgram.target.mk +0 -159
  191. package/node_modules/unix-dgram/lib/unix_dgram.js +0 -168
  192. package/node_modules/unix-dgram/package.json +0 -36
  193. package/node_modules/unix-dgram/src/unix_dgram.cc +0 -404
  194. package/node_modules/unix-dgram/src/win_dummy.cc +0 -7
  195. package/node_modules/unix-dgram/test/test-connect-callback.js +0 -68
  196. package/node_modules/unix-dgram/test/test-connect.js +0 -53
  197. package/node_modules/unix-dgram/test/test-dgram-unix.js +0 -58
  198. package/node_modules/unix-dgram/test/test-send-error.js +0 -26
  199. package/node_modules/winston-syslog/.eslintrc +0 -7
  200. package/node_modules/winston-syslog/.travis.yml +0 -14
  201. package/node_modules/winston-syslog/CHANGELOG.md +0 -9
  202. package/node_modules/winston-syslog/LICENSE +0 -20
  203. package/node_modules/winston-syslog/README.md +0 -135
  204. package/node_modules/winston-syslog/lib/utils.js +0 -26
  205. package/node_modules/winston-syslog/lib/winston-syslog.js +0 -385
  206. package/node_modules/winston-syslog/package.json +0 -56
  207. package/node_modules/winston-syslog/test/format-test.js +0 -122
  208. package/node_modules/winston-syslog/test/syslog-test.js +0 -95
  209. package/node_modules/winston-syslog/test/unix-connect-test.js +0 -133
@@ -79,29 +79,28 @@ function reTrackCoercedValue(coerce, rule) {
79
79
  }
80
80
 
81
81
  const argContrastProperties = tracker.getData(args[0]);
82
- if (!argContrastProperties.tracked) {
82
+ if (!argContrastProperties) {
83
83
  return;
84
84
  }
85
85
 
86
- const str = tracker.track(result.value);
87
- const strContrastProperties = tracker.getData(str);
86
+ const tracked = tracker.track(result.value);
88
87
 
89
- if (strContrastProperties.tracked) {
90
- strContrastProperties.tagRanges = tagRangeUtil.add(
91
- strContrastProperties.tagRanges,
92
- new TagRange(0, str.length - 1, 'untrusted')
88
+ if (tracked) {
89
+ tracked.props.tagRanges = tagRangeUtil.add(
90
+ tracked.props.tagRanges,
91
+ new TagRange(0, tracked.str.length - 1, 'untrusted')
93
92
  );
94
93
 
95
- strContrastProperties.event = createPropagationEvent({
94
+ tracked.props.event = createPropagationEvent({
96
95
  data,
97
96
  trackedArgsData: argContrastProperties,
98
- tagRanges: strContrastProperties.tagRanges,
97
+ tagRanges: tracked.props.tagRanges,
99
98
  target: 'R',
100
99
  joiMethod: rule
101
100
  });
102
- }
103
101
 
104
- data.result = { value: str };
102
+ data.result = { value: tracked.str };
103
+ }
105
104
  }
106
105
  });
107
106
  }
@@ -120,13 +119,13 @@ function wrapRuleAsValidator(rules, rule, tagName) {
120
119
  }
121
120
 
122
121
  const argContrastProperties = tracker.getData(args[0]);
123
- if (!argContrastProperties.tracked) {
122
+ if (!argContrastProperties) {
124
123
  return;
125
124
  }
126
125
 
127
126
  const strContrastProperties = tracker.getData(result);
128
127
 
129
- if (strContrastProperties.tracked) {
128
+ if (strContrastProperties) {
130
129
  strContrastProperties.tagRanges = tagRangeUtil.add(
131
130
  strContrastProperties.tagRanges,
132
131
  new TagRange(0, result.length - 1, tagName)
@@ -41,7 +41,7 @@ function instrumentJoiValues(values) {
41
41
  name: 'joi.values',
42
42
  patchType: ASSESS_PROPAGATOR,
43
43
  post(data) {
44
- const {
44
+ let {
45
45
  args: [value],
46
46
  result
47
47
  } = data;
@@ -51,25 +51,40 @@ function instrumentJoiValues(values) {
51
51
  return;
52
52
  }
53
53
 
54
- const resultIsString = _.isString(result.value);
55
- const argIsString = _.isString(value);
56
-
57
54
  if (result.ref) {
58
- // result === false means ref resolution failed
59
- if (resultIsString && argIsString) {
60
- const resolvedTrackData = tracker.getData(result.value);
61
- const refTrackData = tracker.getData(value);
62
- const handler = getRefHandler(resolvedTrackData, refTrackData);
63
- handler && handler(data, resolvedTrackData, refTrackData);
64
- }
65
- } else if (resultIsString) {
55
+ handler(result.value, value, data);
56
+ } else if (_.isString(result.value)) {
66
57
  // use case is .valid() - safe
67
- tracker.untrack(result.value);
58
+ result.value = tracker.untrack(result.value) || result.value;
68
59
  }
69
60
  }
70
61
  });
71
62
  }
72
63
 
64
+ const stringHandler = (resultValue, argValue, data) => {
65
+ const resultIsString = _.isString(resultValue);
66
+ const argIsString = _.isString(argValue);
67
+
68
+ if (resultIsString && argIsString) {
69
+ const resolvedTrackData = tracker.getData(resultValue);
70
+ const refTrackData = tracker.getData(argValue);
71
+ const handler = getRefHandler(resolvedTrackData, refTrackData);
72
+ handler && handler(data, resolvedTrackData, refTrackData);
73
+ }
74
+ };
75
+
76
+ const handler = (resultValue, argValue, data) => {
77
+ if (_.isString(resultValue)) {
78
+ return stringHandler(resultValue, argValue, data);
79
+ }
80
+
81
+ if (_.isObject(resultValue)) {
82
+ for (const [key, value] of Object.entries(resultValue)) {
83
+ handler(value, argValue[key], data);
84
+ }
85
+ }
86
+ };
87
+
73
88
  /**
74
89
  * Depending on which values are tracked, ref and/or target, returns the
75
90
  * appropriate function to handle the scenario.
@@ -79,14 +94,14 @@ function instrumentJoiValues(values) {
79
94
  */
80
95
  function getRefHandler(resolvedTrackData, refTrackData) {
81
96
  // 4 Cases
82
- if (!resolvedTrackData.tracked) {
83
- if (!refTrackData.tracked) {
97
+ if (!resolvedTrackData) {
98
+ if (!refTrackData) {
84
99
  return null;
85
100
  } else {
86
101
  return handleRefOnlyTracked;
87
102
  }
88
103
  } else {
89
- if (refTrackData.tracked) {
104
+ if (refTrackData) {
90
105
  return handleBothTracked;
91
106
  } else {
92
107
  return handleTargetOnlyTracked;
@@ -116,7 +131,7 @@ function handleTargetOnlyTracked(data, resolvedTrackData, refTrackData) {
116
131
  * @param {object} refTrackData tracking data for reference value
117
132
  */
118
133
  function handleBothTracked(data, resolvedTrackData, refTrackData) {
119
- const {
134
+ let {
120
135
  args: [value, , prefs],
121
136
  result
122
137
  } = data;
@@ -127,8 +142,8 @@ function handleBothTracked(data, resolvedTrackData, refTrackData) {
127
142
  }
128
143
 
129
144
  if (result.ref.map) {
130
- tracker.untrack(data.result.value);
131
- tracker.untrack(value);
145
+ data.result.value = tracker.untrack(data.result.value) || data.result.value;
146
+ value = tracker.untrack(value) || value;
132
147
  } else {
133
148
  copyValidationHistory(resolvedTrackData, refTrackData);
134
149
  if (prefs.convert) {
@@ -145,7 +160,7 @@ function handleBothTracked(data, resolvedTrackData, refTrackData) {
145
160
  * @param {object} refTrackData tracking data for reference value
146
161
  */
147
162
  function handleRefOnlyTracked(data, resolvedTrackData, refTrackData) {
148
- const {
163
+ let {
149
164
  args: [value, , prefs],
150
165
  result
151
166
  } = data;
@@ -164,8 +179,8 @@ function handleRefOnlyTracked(data, resolvedTrackData, refTrackData) {
164
179
  } else {
165
180
  // if map is used we can trust - like .valid()
166
181
  if (result.ref.map) {
167
- if (!tracker.getData(result.value).tracked) {
168
- tracker.untrack(value);
182
+ if (!tracker.getData(result.value)) {
183
+ value = tracker.untrack(value) || value;
169
184
  }
170
185
  } else {
171
186
  logger.debug(
@@ -112,13 +112,14 @@ module.exports = function Propagator(agent, propagationDescriptor) {
112
112
 
113
113
  // move the tags to the result of propagator
114
114
  if (event.tagRanges.length > 0 && validTarget === data.result) {
115
- data.result = tracker.track(data.result);
116
- const resultContrastProperties = tracker.getData(data.result);
117
- resultContrastProperties.tracked = true;
118
- resultContrastProperties.tagRanges = event.tagRanges;
115
+ const tracked = tracker.track(data.result);
116
+ if (tracked) {
117
+ tracked.props.tagRanges = event.tagRanges;
118
+ tracked.props.event = event;
119
+ data.result = tracked.str;
120
+ }
119
121
 
120
122
  event.parents.push(...sourceEvents);
121
- resultContrastProperties.event = event;
122
123
  }
123
124
  logger.trace('%s2%s %s --> %s', source, target, sources, [validTarget]);
124
125
  };
@@ -206,7 +207,7 @@ function createAppendTagRanges(data) {
206
207
  if (isString(data.obj)) {
207
208
  offset = data.obj.length;
208
209
  const sourceProps = tracker.getData(data.obj);
209
- if (sourceProps.tracked) {
210
+ if (sourceProps) {
210
211
  tagRangeUtil.addAllInPlace(newTags, sourceProps.tagRanges);
211
212
  }
212
213
  }
@@ -214,7 +215,7 @@ function createAppendTagRanges(data) {
214
215
  for (const arg of data.args) {
215
216
  if (arg) {
216
217
  const props = tracker.getData(arg);
217
- if (props.tracked) {
218
+ if (props) {
218
219
  tagRangeUtil.addAllWithOffsetInPlace(newTags, props.tagRanges, offset);
219
220
  }
220
221
 
@@ -339,7 +340,7 @@ function getSourcesMetadata(sources) {
339
340
  function isSourceTracked(sourceName, source) {
340
341
  if (source) {
341
342
  const contrastProperties = tracker.getData(source);
342
- return contrastProperties.tracked;
343
+ return !!contrastProperties;
343
344
  }
344
345
 
345
346
  return false;
@@ -384,7 +385,7 @@ function getTrackedSources(sources, skipNested) {
384
385
  function isTargetTracked(target, hasTags) {
385
386
  if (hasTags) {
386
387
  const contrastProperties = tracker.getData(target);
387
- return contrastProperties.tracked;
388
+ return !!contrastProperties;
388
389
  }
389
390
 
390
391
  return false;
@@ -457,7 +458,8 @@ function getValidSources(sources) {
457
458
  const sourceContrastProperties = tracker.getData(source);
458
459
  if (
459
460
  isString(source) &&
460
- !(sourceContrastProperties && sourceContrastProperties.tracked)
461
+ (!sourceContrastProperties ||
462
+ (sourceContrastProperties && !sourceContrastProperties.tracked))
461
463
  ) {
462
464
  return false;
463
465
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ const hasUserDefinedValidator = (data) =>
16
+ data.obj.validators.some((validator) => validator.type === 'user defined');
17
+
18
+ module.exports = {
19
+ hasUserDefinedValidator
20
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ module.exports.handle = () => {
16
+ require('./map');
17
+ require('./string');
18
+ };
@@ -0,0 +1,74 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const tracker = require('../../../tracker');
18
+ const patcher = require('../../../hooks/patcher');
19
+ const requireHook = require('../../../hooks/require');
20
+ const tagRangeUtil = require('../../models/tag-range/util');
21
+ const {
22
+ PATCH_TYPES: { ASSESS_PROPAGATOR }
23
+ } = require('../../../constants');
24
+ const TagRange = require('../../models/tag-range');
25
+ const { CallContext, PropagationEvent, Signature } = require('../../models');
26
+ const { hasUserDefinedValidator } = require('./helpers');
27
+
28
+ const doValidateSyncPatcher = (SchemaMap) => {
29
+ patcher.patch(SchemaMap.prototype, 'doValidateSync', {
30
+ alwaysRun: true,
31
+ name: 'mongoose.map.doValidateSync',
32
+ patchType: ASSESS_PROPAGATOR,
33
+ post(data) {
34
+ if (data.result || data.obj.options.of.name !== 'String') return;
35
+
36
+ if (!hasUserDefinedValidator(data)) return;
37
+
38
+ for (const value of data.args[0].values()) {
39
+ const trackingData = tracker.track(value);
40
+
41
+ if (!trackingData) return;
42
+
43
+ const { props } = trackingData;
44
+ const stringLength = value.length - 1;
45
+
46
+ props.tagRanges = tagRangeUtil.add(
47
+ props.tagRanges,
48
+ new TagRange(0, stringLength, 'custom-validated-nosql-injection')
49
+ );
50
+
51
+ props.tagRanges = tagRangeUtil.add(
52
+ props.tagRanges,
53
+ new TagRange(0, stringLength, 'string-type-checked')
54
+ );
55
+
56
+ props.event = new PropagationEvent({
57
+ context: new CallContext(data),
58
+ signature: new Signature('mongoose.map.doValidateSync'),
59
+ tagRanges: props.tagRanges,
60
+ source: 'P',
61
+ target: 'A',
62
+ parents: [props.event]
63
+ });
64
+ }
65
+ }
66
+ });
67
+ };
68
+
69
+ requireHook.resolve(
70
+ { name: 'mongoose', file: 'lib/schema/map.js', version: '>=5.0.0' },
71
+ (SchemaMap) => {
72
+ doValidateSyncPatcher(SchemaMap);
73
+ }
74
+ );
@@ -0,0 +1,104 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const tracker = require('../../../tracker');
18
+ const patcher = require('../../../hooks/patcher');
19
+ const requireHook = require('../../../hooks/require');
20
+ const tagRangeUtil = require('../../models/tag-range/util');
21
+ const {
22
+ PATCH_TYPES: { ASSESS_PROPAGATOR }
23
+ } = require('../../../constants');
24
+ const TagRange = require('../../models/tag-range');
25
+ const { CallContext, PropagationEvent, Signature } = require('../../models');
26
+ const { hasUserDefinedValidator } = require('./helpers');
27
+
28
+ const enumPatcher = (SchemaString) => {
29
+ patcher.patch(SchemaString.prototype, 'enum', {
30
+ alwaysRun: true,
31
+ name: 'mongoose.string.enum',
32
+ patchType: ASSESS_PROPAGATOR,
33
+ post(data) {
34
+ if (!data.result) return;
35
+
36
+ const enumValidator = data.result.validators.find(
37
+ (validator) => validator.type === 'enum'
38
+ );
39
+
40
+ if (!enumValidator) return;
41
+
42
+ patcher.patch(enumValidator, 'validator', {
43
+ alwaysRun: true,
44
+ name: 'mongoose.string.enumValidator',
45
+ patchType: ASSESS_PROPAGATOR,
46
+ post(data) {
47
+ if (!data.result) return;
48
+
49
+ tracker.untrack(data.args[0]);
50
+ }
51
+ });
52
+ }
53
+ });
54
+ };
55
+
56
+ const doValidateSyncPatcher = (SchemaString) => {
57
+ patcher.patch(SchemaString.prototype, 'doValidateSync', {
58
+ alwaysRun: true,
59
+ name: 'mongoose.string.doValidateSync',
60
+ patchType: ASSESS_PROPAGATOR,
61
+ post(data) {
62
+ if (data.result) return;
63
+
64
+ if (!hasUserDefinedValidator(data)) return;
65
+
66
+ const trackingData = tracker.track(data.args[0]);
67
+ if (!trackingData) return;
68
+
69
+ const { props } = trackingData;
70
+ const incomingStringLength = data.args[0].length - 1;
71
+
72
+ props.tagRanges = tagRangeUtil.add(
73
+ props.tagRanges,
74
+ new TagRange(
75
+ 0,
76
+ incomingStringLength,
77
+ 'custom-validated-nosql-injection'
78
+ )
79
+ );
80
+
81
+ props.tagRanges = tagRangeUtil.add(
82
+ props.tagRanges,
83
+ new TagRange(0, incomingStringLength, 'string-type-checked')
84
+ );
85
+
86
+ props.event = new PropagationEvent({
87
+ context: new CallContext(data),
88
+ signature: new Signature('mongoose.string.doValidateSync'),
89
+ tagRanges: props.tagRanges,
90
+ source: 'P',
91
+ target: 'A',
92
+ parents: [props.event]
93
+ });
94
+ }
95
+ });
96
+ };
97
+
98
+ requireHook.resolve(
99
+ { name: 'mongoose', file: 'lib/schema/string.js', version: '>=5.0.0' },
100
+ (SchemaString) => {
101
+ enumPatcher(SchemaString);
102
+ doValidateSyncPatcher(SchemaString);
103
+ }
104
+ );
@@ -0,0 +1,22 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+ const { propagate } = require('../template-escape');
17
+
18
+ function handler(data) {
19
+ propagate(data, 'html-encoded', 'mustache.escape');
20
+ }
21
+
22
+ module.exports.handle = handler;
@@ -0,0 +1,54 @@
1
+ /**
2
+ Copyright: 2021 Contrast Security, Inc
3
+ Contact: support@contrastsecurity.com
4
+ License: Commercial
5
+
6
+ NOTICE: This Software and the patented inventions embodied within may only be
7
+ used as part of Contrast Security’s commercial offerings. Even though it is
8
+ made available through public repositories, use of this Software is subject to
9
+ the applicable End User Licensing Agreement found at
10
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ between Contrast Security and the End User. The Software may not be reverse
12
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ way not consistent with the End User License Agreement.
14
+ */
15
+ 'use strict';
16
+
17
+ const tracker = require('../../tracker.js');
18
+ const patcher = require('../../hooks/patcher.js');
19
+ const { PATCH_TYPES } = require('../../constants');
20
+ const tagRangeUtil = require('../models/tag-range/util');
21
+ const TagRange = require('../models/tag-range');
22
+ const ContrastNumber = require('../../core/rewrite/injections').get('Number');
23
+ const { CallContext, PropagationEvent, Signature } = require('../models');
24
+
25
+ function handle() {
26
+ ContrastNumber.enable();
27
+
28
+ patcher.patch(ContrastNumber.value, {
29
+ name: 'Number',
30
+ patchType: PATCH_TYPES.ASSESS_PROPAGATOR,
31
+ post(data) {
32
+ const trackingData = tracker.getData(data.args[0]);
33
+
34
+ if (!Number.isNaN(data.result) && trackingData) {
35
+ const { event } = trackingData;
36
+ trackingData.tagRanges = tagRangeUtil.add(
37
+ trackingData.tagRanges,
38
+ new TagRange(0, data.args[0].length - 1, 'limited-chars')
39
+ );
40
+
41
+ trackingData.event = new PropagationEvent({
42
+ context: new CallContext(data),
43
+ signature: new Signature('Number'),
44
+ tagRanges: trackingData.tagRanges,
45
+ source: 'P',
46
+ target: 'P',
47
+ parents: [event]
48
+ });
49
+ }
50
+ }
51
+ });
52
+ }
53
+
54
+ module.exports = { handle };
@@ -41,18 +41,17 @@ function handle() {
41
41
  }
42
42
 
43
43
  const argContrastProperties = tracker.getData(arg);
44
- if (!argContrastProperties.tracked) {
44
+ if (!argContrastProperties) {
45
45
  return;
46
46
  }
47
47
 
48
- const str = tracker.track(data.result);
49
- const strContrastProperties = tracker.getData(str);
50
- if (strContrastProperties.tracked) {
51
- strContrastProperties.event = argContrastProperties.event;
52
- strContrastProperties.tagRanges = strContrastProperties.tagRanges.concat(
48
+ const tracked = tracker.track(data.result);
49
+ if (tracked) {
50
+ tracked.props.event = argContrastProperties.event;
51
+ tracked.props.tagRanges = tracked.props.tagRanges.concat(
53
52
  argContrastProperties.tagRanges
54
53
  );
55
- data.result = str;
54
+ data.result = tracked.str;
56
55
  }
57
56
  }
58
57
  });
@@ -45,7 +45,7 @@ module.exports.handle = function handle() {
45
45
  if (!path || !data.result) return;
46
46
 
47
47
  const trackingData = tracker.getData(path);
48
- if (!trackingData.tracked) return;
48
+ if (!trackingData) return;
49
49
 
50
50
  if (extension) {
51
51
  const extIndex = _path.lastIndexOf(extension);
@@ -68,19 +68,20 @@ module.exports.handle = function handle() {
68
68
  // no tags propagated to the result
69
69
  if (!tagRanges.length) return;
70
70
 
71
- const result = tracker.track(data.result);
72
- const resultData = tracker.getData(result);
73
71
  const parentEvent = trackingData.event;
74
- resultData.tagRanges = tagRanges;
75
- resultData.event = new PropagationEvent({
76
- context: new CallContext(data),
77
- parents: [parentEvent],
78
- signature,
79
- source: 'P',
80
- tagRanges,
81
- target: 'R'
82
- });
83
- data.result = result;
72
+ const tracked = tracker.track(data.result);
73
+ if (tracked) {
74
+ tracked.props.tagRanges = tagRanges;
75
+ tracked.props.event = new PropagationEvent({
76
+ context: new CallContext(data),
77
+ parents: [parentEvent],
78
+ signature,
79
+ source: 'P',
80
+ tagRanges,
81
+ target: 'R'
82
+ });
83
+ data.result = tracked.str;
84
+ }
84
85
  }
85
86
  });
86
87
  }