@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
@@ -21,47 +21,41 @@ const BaseSensor = require('../../hooks/frameworks/base');
21
21
  const patcher = require('../../hooks/patcher');
22
22
  const { PATCH_TYPES } = require('../../constants');
23
23
  const { emitSinkEvent } = require('../../hooks/frameworks/common');
24
+ const agentEmitter = require('../../agent-emitter');
25
+ const SinkEvent = require('../models/sink-event');
24
26
 
25
27
  const { SINK_TYPES } = constants;
26
28
  const ID = 'mongodb';
27
29
 
28
- /**
29
- * json.stringify(data) in try-catch
30
- * @param {any} data
31
- * @returns {string}
32
- */
33
- const safeStringify = (data) => {
34
- try {
35
- return JSON.stringify(data);
36
- } catch (e) {
37
- // ignore errors
38
- }
39
- };
40
-
41
- /**
42
- * @param {any} query `cmd.query`
43
- * @returns {string}
44
- */
45
- const getQueryAsString = (args, version) => {
30
+ function getCursorQueryData(args, version) {
46
31
  const query = semver.gte(version, '3.3.0')
47
32
  ? _.get(args, '0.cmd.query')
48
33
  : _.get(args, '1.query');
49
34
 
50
- if (_.isString(query)) return query.toString();
51
- if (!_.isObject(query)) return;
35
+ if (!query) {
36
+ return;
37
+ }
38
+
39
+ if (_.isString(query)) {
40
+ return query.toString()
41
+ }
52
42
 
53
43
  if (query['$where']) {
54
44
  return query['$where'].toString();
55
45
  }
56
46
 
57
- const keys = Object.keys(query);
58
- if (keys.length === 1 && _.isString(query[keys[0]])) {
59
- // eval: { $where : 'process.exit()' }
60
- return query[keys[0]];
47
+ return query;
48
+ }
49
+
50
+ function getOpQueryData(op) {
51
+ if (!op.q) {
52
+ return;
61
53
  }
62
- // otherwise try and look at the stringified query
63
- return safeStringify(query);
64
- };
54
+ if (op.q.$where) {
55
+ return op.q.$where;
56
+ }
57
+ return op.q;
58
+ }
65
59
 
66
60
  class MongoDBSensor extends BaseSensor {
67
61
  constructor(agent) {
@@ -76,8 +70,11 @@ class MongoDBSensor extends BaseSensor {
76
70
  name: 'mongodb.CoreServer.prototype',
77
71
  patchType: PATCH_TYPES.PROTECT_SINK,
78
72
  pre: (wrapCtx) => {
79
- const data = getQueryAsString(wrapCtx.args, version);
80
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
73
+ emitSinkEvent(
74
+ getCursorQueryData(wrapCtx.args, version),
75
+ SINK_TYPES.NOSQL_QUERY,
76
+ ID
77
+ );
81
78
  }
82
79
  });
83
80
 
@@ -86,21 +83,12 @@ class MongoDBSensor extends BaseSensor {
86
83
  alwaysRun: true,
87
84
  name: 'mongodb.CoreServer.prototype',
88
85
  patchType: PATCH_TYPES.PROTECT_SINK,
89
- pre: (wrapCtx) => {
90
- const data = getQueryAsString(wrapCtx.args, version);
91
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
92
- }
93
- });
94
-
95
- // insert(ns, opts, options, cb)
96
- patcher.patch(mongodb.CoreServer.prototype, 'insert', {
97
- alwaysRun: true,
98
- name: 'mongodb.CoreServer.prototype',
99
- patchType: PATCH_TYPES.PROTECT_SINK,
100
- pre: (wrapCtx) => {
101
- const arg = _.get(wrapCtx, 'args.1');
102
- const data = safeStringify(arg);
103
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
86
+ pre: (data) => {
87
+ emitSinkEvent(
88
+ getCursorQueryData(data.args, version),
89
+ SINK_TYPES.NOSQL_QUERY,
90
+ ID
91
+ );
104
92
  }
105
93
  });
106
94
 
@@ -109,10 +97,17 @@ class MongoDBSensor extends BaseSensor {
109
97
  alwaysRun: true,
110
98
  name: 'mongodb.CoreServer.prototype',
111
99
  patchType: PATCH_TYPES.PROTECT_SINK,
112
- pre: (wrapCtx) => {
113
- const arg = _.get(wrapCtx, 'args.1');
114
- const data = safeStringify(arg);
115
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
100
+ pre: (data) => {
101
+ const ops = Array.isArray(data.args[1])
102
+ ? data.args[1]
103
+ : [data.args[1]];
104
+
105
+ for (const op of ops) {
106
+ const eData = getOpQueryData(op);
107
+ if (eData) {
108
+ emitSinkEvent(eData, SINK_TYPES.NOSQL_QUERY, ID);
109
+ }
110
+ }
116
111
  }
117
112
  });
118
113
 
@@ -121,10 +116,17 @@ class MongoDBSensor extends BaseSensor {
121
116
  alwaysRun: true,
122
117
  name: 'mongodb.CoreServer.prototype',
123
118
  patchType: PATCH_TYPES.PROTECT_SINK,
124
- pre: (wrapCtx) => {
125
- const arg = _.get(wrapCtx, 'args.1');
126
- const data = safeStringify(arg);
127
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
119
+ pre: (data) => {
120
+ const ops = Array.isArray(data.args[1])
121
+ ? data.args[1]
122
+ : [data.args[1]];
123
+
124
+ for (const op of ops) {
125
+ const eData = getOpQueryData(op);
126
+ if (eData) {
127
+ emitSinkEvent(eData, SINK_TYPES.NOSQL_QUERY, ID);
128
+ }
129
+ }
128
130
  }
129
131
  });
130
132
 
@@ -133,9 +135,8 @@ class MongoDBSensor extends BaseSensor {
133
135
  alwaysRun: true,
134
136
  name: 'mongodb.Db.prototype',
135
137
  patchType: PATCH_TYPES.PROTECT_SINK,
136
- pre: (wrapCtx) => {
137
- const data = _.get(wrapCtx, 'args.0');
138
- emitSinkEvent(data, SINK_TYPES.NOSQL_QUERY, ID);
138
+ pre: (data) => {
139
+ emitSinkEvent(data.args[0], SINK_TYPES.NOSQL_QUERY, ID);
139
140
  }
140
141
  });
141
142
  });
@@ -27,7 +27,7 @@ module.exports = {
27
27
  Finding: require('./finding'),
28
28
  HttpMethodTamperingDetails: require('./http-method-tampering-details'),
29
29
  HttpRequest: require('./http-request'),
30
- IpBlacklistDetails: require('./ip-denylist-details'),
30
+ IpDenylistDetails: require('./ip-denylist-details'),
31
31
  LibraryUsageUpdate: require('./library-usage-update'),
32
32
  Poll: require('./poll'),
33
33
  NoSqlInjectionDetails: require('./no-sql-injection-details'),
@@ -16,7 +16,7 @@ Copyright: 2021 Contrast Security, Inc
16
16
  const { dtm } = require('@contrast/protobuf-api');
17
17
 
18
18
  module.exports = function IpDenylistDetails(details = {}) {
19
- return new dtm.IpBlacklistDetails({
19
+ return new dtm.IpDenylistDetails({
20
20
  0: details.ip,
21
21
  1: details.uuid
22
22
  });
@@ -65,7 +65,7 @@ const DETAILS_MAP = {
65
65
  Constructor: require('./untrusted-deserialization-details')
66
66
  },
67
67
  [IP_DENYLIST]: {
68
- index: 22,
68
+ index: 44,
69
69
  Constructor: require('./ip-denylist-details')
70
70
  },
71
71
  [PATH_TRAVERSAL]: {
@@ -33,22 +33,24 @@ function DefendFeatures(defend = {}) {
33
33
  const {
34
34
  auth,
35
35
  botBlockers = [],
36
- ipBlacklists = [],
37
- ipWhitelists = [],
38
36
  logEnhancers = [],
39
- ruleDefinitionList = []
37
+ ruleDefinitionList = [],
38
+ ipDenylists = [],
39
+ ipAllowlists = []
40
40
  } = defend;
41
41
  return wrapToObject(
42
42
  new settings.DefendFeatures([
43
43
  defend.enabled, // 1 enabled
44
44
  defend['bot-blocker'], // 2 bot_blocker
45
45
  botBlockers.map((blocker) => BotBlocker(blocker).array), // 3 bot_blockers
46
- ipBlacklists.map((bl) => IpFilter(bl).array), // 4 ip_blacklists
47
- ipWhitelists.map((wl) => IpFilter(wl).array), // 5 ip_whitelist
46
+ undefined, // 4 -
47
+ undefined, // 5 -
48
48
  logEnhancers.map((le) => LogEnhancer(le).array), // 6 log_enhancers (unsupported as of q2-2019)
49
49
  ruleDefinitionList.map((def) => RuleDefinition(def).array), // 7 rule_definitions
50
50
  Syslog(defend.syslog).array, // 8 syslog
51
- Auth(auth).array // 9 auth
51
+ Auth(auth).array, // 9 auth
52
+ ipDenylists.map((dl) => IpFilter(dl).array), // 10 ip_denylists
53
+ ipAllowlists.map((al) => IpFilter(al).array) // 11 ip_allowlists
52
54
  ]),
53
55
  ({ syslog, ruleDefinitionsList }) => {
54
56
  ruleDefinitionsList.forEach(({ keywordsList, patternsList }) => {
@@ -25,7 +25,6 @@ const {
25
25
 
26
26
  function Exclusion({
27
27
  assessmentRules,
28
- blacklist,
29
28
  inputName,
30
29
  inputType,
31
30
  matchStrategy,
@@ -33,7 +32,8 @@ function Exclusion({
33
32
  name,
34
33
  rules,
35
34
  type,
36
- urls
35
+ urls,
36
+ denylist
37
37
  }) {
38
38
  return wrapToObject(
39
39
  new settings.Exclusion([
@@ -44,11 +44,12 @@ function Exclusion({
44
44
  rules, // 5 protection_rules
45
45
  assessmentRules, // 6 assessment_rules
46
46
  urls, // 7 urls
47
- blacklist, // 8 blacklist
47
+ undefined, // 8 -
48
48
  ExclusionInputType(inputType), // 9 input_type
49
49
  inputName, // 10 input_name
50
50
  modes.includes('assess'), // 11 assess
51
- modes.includes('defend') // 12 protect
51
+ modes.includes('defend'), // 12 protect
52
+ denylist // 13 denylist
52
53
  ]),
53
54
  (exclusion) => {
54
55
  exclusion.inputType = EXCLUSION_INPUT_TYPES[exclusion.inputType];
package/lib/tracker.js CHANGED
@@ -45,12 +45,6 @@ const defaultContrastProperties = {
45
45
  }
46
46
  };
47
47
 
48
- // NOTE: this function just exists for us to get a better view
49
- // of the module's performance while profiling
50
- function getExtStringProps(ext) {
51
- return distringuish.getProperties(ext);
52
- }
53
-
54
48
  // i'm not sure why this is a class. there are no methods, and externalized
55
49
  // strings don't have an instance of the class; they have an object with the
56
50
  // same property names.
@@ -74,37 +68,6 @@ class Tracker {
74
68
  this.metadata = new WeakMap();
75
69
  }
76
70
 
77
- /**
78
- * Map lookup for metadata of a value
79
- *
80
- * @param {*} value Tracked value
81
- * @return {ContrastProperties|undefined}
82
- */
83
- getData(value) {
84
- if (typeof value === 'string') {
85
- const props = getExtStringProps(value);
86
- if (props == null) {
87
- return defaultContrastProperties;
88
- }
89
-
90
- return props;
91
- }
92
- return this.metadata.get(value) || defaultContrastProperties;
93
- }
94
-
95
- /**
96
- * Resets a string's tracking metadata to the default contrast properties.
97
- * This will effectively untrack the associated string, but it will still be
98
- * the externalized value.
99
- * @param {object} trackingData A tracked string's metadata
100
- */
101
- untrack(str) {
102
- const trackingData = this.getData(str);
103
- if (trackingData.tracked) {
104
- Object.assign(trackingData, defaultContrastProperties);
105
- }
106
- }
107
-
108
71
  trackString(str) {
109
72
  if (str.length === 0) {
110
73
  return str;
@@ -113,7 +76,7 @@ class Tracker {
113
76
  // XXX: this is the closest we have to a dedup.
114
77
  // it may be kind of expensive. we need to consider whether or not
115
78
  // this is worthwhile
116
- if (this.getData(str).tracked) {
79
+ if (this.getData(str)) {
117
80
  return str;
118
81
  }
119
82
 
@@ -143,38 +106,15 @@ class Tracker {
143
106
  return value;
144
107
  }
145
108
 
146
- // trackArray(value, parent, sourceType, parentKey) {}
147
-
148
- /**
149
- * Associate properties with a string.
150
- *
151
- * @param {*} value value to track
152
- * @returns {*} the value - tracked if some type of string, otherwise untracked
153
- */
154
- track(value) {
155
- if (typeof value === 'string') {
156
- return this.trackString(value);
157
- }
158
-
159
- if (value instanceof String) {
160
- return this.trackStringObject(value);
161
- }
162
-
163
- return value;
164
- }
165
109
 
166
110
  /**
167
111
  * Associate properties with a string. Returns null if str is not a string,
168
112
  * is a zero-length string, or any internal error takes place.
169
113
  *
170
- * This behavior is different than track in that it requires the caller to check
171
- * the return value. track always returned properties even if the value was not a
172
- * string or there were no properties associated with the string value.
173
- *
174
114
  * @param {*} str a value to track.
175
115
  * @returns {Object|null} {str, props} or null on error.
176
116
  */
177
- track2(str) {
117
+ track(str) {
178
118
  if (typeof str === 'string') {
179
119
  // is the string already tracked?
180
120
  let props = distringuish.getProperties(str);
@@ -217,7 +157,7 @@ class Tracker {
217
157
  * @param {*} str any value
218
158
  * @return {ContrastProperties|null}
219
159
  */
220
- getData2(str) {
160
+ getData(str) {
221
161
  if (typeof str === 'string') {
222
162
  return distringuish.getProperties(str);
223
163
  }
@@ -227,12 +167,20 @@ class Tracker {
227
167
  return null;
228
168
  }
229
169
 
230
- untrack2(str) {
170
+ /**
171
+ * Resets a string's tracking metadata to the default contrast properties.
172
+ * This will effectively untrack the associated string, but it will still be
173
+ * the externalized value.
174
+ * @param {object} trackingData A tracked string's metadata
175
+ */
176
+ untrack(str) {
231
177
  if (typeof str === 'string') {
232
- if (!distringuish.getProperties(str)) {
178
+ let props = distringuish.getProperties(str);
179
+ if (!props) {
233
180
  return null;
234
181
  }
235
182
  // return an untracked version of the string
183
+ Object.assign(props, {event: null, tagRanges: [], tracked: false})
236
184
  return distringuish.internalize(str);
237
185
  }
238
186
  if (str instanceof String) {
@@ -0,0 +1,27 @@
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
+ function some(array, predicate) {
16
+ let index = -1;
17
+ const length = array == null ? 0 : array.length;
18
+
19
+ while (++index < length) {
20
+ if (predicate(array[index], index, array)) {
21
+ return true;
22
+ }
23
+ }
24
+ return false;
25
+ }
26
+
27
+ module.exports = some;
@@ -133,7 +133,7 @@ class SourceMapUtility {
133
133
  const { line, source } = consumer.originalPositionFor({
134
134
  line: lineNumber,
135
135
  column
136
- });
136
+ }) || { line: undefined, source: undefined };
137
137
 
138
138
  if (line) lineNumber = line;
139
139
  if (source) file = this.replaceSource(file, source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent",
3
- "version": "4.5.1",
3
+ "version": "4.7.1",
4
4
  "description": "Node.js security instrumentation by Contrast Security",
5
5
  "keywords": [
6
6
  "security",
@@ -38,7 +38,8 @@
38
38
  "extract-licenses": "node scripts/extract-licenses",
39
39
  "fix": "eslint . --fix",
40
40
  "prepare": "husky install || exit 0",
41
- "preversion": "npm run test:gh-ci"
41
+ "preversion": "npm run test:gh-ci",
42
+ "initsecrets": "scripts/detect-secrets.sh"
42
43
  },
43
44
  "lint-staged": {
44
45
  "*.js": "eslint --fix",
@@ -74,11 +75,10 @@
74
75
  "@contrast/fn-inspect": "^2.4.2",
75
76
  "@contrast/heapdump": "^1.1.0",
76
77
  "@contrast/protobuf-api": "^3.2.0",
77
- "@contrast/require-hook": "^2.0.5",
78
+ "@contrast/require-hook": "^2.0.6",
78
79
  "@contrast/synchronous-source-maps": "^1.1.0",
79
80
  "amqp-connection-manager": "^3.2.2",
80
81
  "amqplib": "^0.8.0",
81
- "base64url": "^3.0.1",
82
82
  "big-integer": "^1.6.36",
83
83
  "bluebird": "^3.5.3",
84
84
  "builtin-modules": "^3.2.0",
@@ -94,25 +94,22 @@
94
94
  "jspack": "0.0.4",
95
95
  "lodash": "^4.17.21",
96
96
  "make-dir": "^3.1.0",
97
- "moment": "^2.21.0",
98
97
  "multi-stage-sourcemap": "^0.3.1",
99
98
  "on-finished": "^2.3.0",
100
99
  "parseurl": "^1.3.3",
101
100
  "prom-client": "^12.0.0",
102
101
  "recursive-readdir": "^2.2.2",
103
- "request": "^2.88.0",
104
102
  "semver": "^7.3.2",
105
- "source-map": "^0.7.3",
106
103
  "winston": "^3.1.0",
107
104
  "winston-daily-rotate-file": "^3.5.1",
108
- "winston-syslog": "2.1.0",
109
105
  "yaml": "^1.10.0"
110
106
  },
111
107
  "devDependencies": {
108
+ "@aws-sdk/client-dynamodb": "^3.39.0",
112
109
  "@bmacnaughton/string-generator": "^1.0.0",
113
110
  "@contrast/eslint-config": "^2.0.1",
114
111
  "@contrast/fake-module": "file:test/mock/contrast-fake",
115
- "@contrast/screener-service": "^1.12.4",
112
+ "@contrast/screener-service": "^1.12.5",
116
113
  "@hapi/boom": "file:test/mock/boom",
117
114
  "@hapi/hapi": "file:test/mock/hapi",
118
115
  "@ls-lint/ls-lint": "^1.8.1",
@@ -129,9 +126,10 @@
129
126
  "config": "^3.3.3",
130
127
  "csv-writer": "^1.2.0",
131
128
  "deasync": "^0.1.20",
129
+ "dustjs-linkedin": "^3.0.0",
132
130
  "ejs": "^3.1.6",
133
131
  "escape-html": "^1.0.3",
134
- "eslint": "^5.16.0",
132
+ "eslint": "^8.2.0",
135
133
  "eslint-config-prettier": "^6.11.0",
136
134
  "eslint-plugin-mocha": "^7.0.1",
137
135
  "eslint-plugin-node": "^11.1.0",
@@ -147,27 +145,28 @@
147
145
  "jsdoc": "^3.6.7",
148
146
  "libxmljs": "file:test/mock/libxmljs",
149
147
  "libxmljs2": "file:test/mock/libxmljs2",
150
- "lint-staged": "^11.0.0",
148
+ "lint-staged": "^12.0.2",
151
149
  "madge": "^4.0.1",
152
150
  "marsdb": "file:test/mock/marsdb",
153
- "mocha": "^8.2.0",
154
- "mochawesome": "^6.2.2",
151
+ "mocha": "^9.1.3",
152
+ "mochawesome": "^7.0.1",
155
153
  "mongodb": "file:test/mock/mongodb",
156
154
  "mongodb-npm": "npm:mongodb@^3.6.5",
155
+ "mongoose": "^6.1.1",
157
156
  "mustache": "^3.0.1",
158
157
  "mysql": "file:test/mock/mysql",
159
158
  "nock": "^12.0.3",
160
159
  "node-fetch": "^2.6.1",
161
160
  "node-serialize": "file:test/mock/node-serialize",
162
161
  "npm-license-crawler": "^0.2.1",
163
- "nyc": "^15.0.0",
162
+ "nyc": "^15.1.0",
164
163
  "pg": "file:test/mock/pg",
165
164
  "pino": "^6.7.0",
166
165
  "prettier": "^1.19.1",
167
166
  "proxyquire": "^2.1.0",
168
167
  "qs": "^6.9.4",
169
168
  "rethinkdb": "file:test/mock/rethinkdb",
170
- "sequelize": "^6.3.3",
169
+ "sequelize": "^6.11.0",
171
170
  "shellcheck": "^1.0.0",
172
171
  "sinon": "^7.2.2",
173
172
  "sinon-chai": "^3.3.0",
@@ -176,7 +175,7 @@
176
175
  "triple-beam": "^1.3.0",
177
176
  "typeorm": "file:test/mock/typeorm",
178
177
  "uuid": "^8.3.1",
179
- "validator": "^13.5.2",
178
+ "validator": "^13.7.0",
180
179
  "xpath": "file:test/mock/xpath"
181
180
  },
182
181
  "main": "bootstrap.js",
@@ -1,42 +0,0 @@
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 emitter = require('../../agent-emitter');
18
- const { HTTP_EVENTS } = require('../../constants');
19
- const HttpFramework = require('./http');
20
-
21
- const id = 'https';
22
-
23
- class HttpsFramework extends HttpFramework {
24
- constructor(agent) {
25
- super(agent, id);
26
- }
27
-
28
- /**
29
- * Override for <code>HttpSource.prototype.handleServerCreate</code>.
30
- * We override in order to emit the event with the proper callback argument -
31
- * HTTPS servers take an `options` object as the first argument. We want the
32
- * second callback argument.
33
- * @param {*[]} args The arguments passed to the Server constructor
34
- * @param {Server} server
35
- */
36
- handleServerCreate(args, server) {
37
- const callback = args[1];
38
- emitter.emit(HTTP_EVENTS.SERVER_CREATE, callback, server);
39
- }
40
- }
41
-
42
- module.exports = HttpsFramework;