@contrast/agent 4.12.0 → 4.13.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 (41) 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/esm.mjs +1 -32
  6. package/lib/assess/models/base-event.js +1 -1
  7. package/lib/assess/sinks/dynamo.js +65 -30
  8. package/lib/assess/static/read-findings-from-cache.js +40 -0
  9. package/lib/assess/technologies/index.js +12 -13
  10. package/lib/cli-rewriter/index.js +65 -6
  11. package/lib/contrast.js +1 -2
  12. package/lib/core/config/options.js +6 -0
  13. package/lib/core/config/util.js +15 -33
  14. package/lib/core/exclusions/input.js +6 -1
  15. package/lib/core/express/index.js +2 -4
  16. package/lib/hooks/http.js +81 -81
  17. package/lib/hooks/require.js +1 -0
  18. package/lib/instrumentation.js +17 -0
  19. package/lib/protect/errors/handler-async-errors.js +66 -0
  20. package/lib/protect/input-analysis.js +7 -13
  21. package/lib/protect/listeners.js +27 -23
  22. package/lib/protect/rules/base-scanner/index.js +2 -2
  23. package/lib/protect/rules/bot-blocker/bot-blocker-rule.js +4 -2
  24. package/lib/protect/rules/cmd-injection/cmdinjection-rule.js +57 -2
  25. package/lib/protect/rules/cmd-injection-semantic-chained-commands/cmd-injection-semantic-chained-commands-rule.js +31 -2
  26. package/lib/protect/rules/cmd-injection-semantic-dangerous-paths/cmd-injection-semantic-dangerous-paths-rule.js +32 -2
  27. package/lib/protect/rules/index.js +42 -21
  28. package/lib/protect/rules/ip-denylist/ip-denylist-rule.js +2 -2
  29. package/lib/protect/rules/nosqli/nosql-injection-rule.js +103 -38
  30. package/lib/protect/rules/path-traversal/path-traversal-rule.js +3 -0
  31. package/lib/protect/rules/rule-factory.js +6 -6
  32. package/lib/protect/rules/signatures/signature.js +3 -0
  33. package/lib/protect/rules/sqli/sql-injection-rule.js +98 -5
  34. package/lib/protect/rules/sqli/sql-scanner/labels.json +0 -3
  35. package/lib/protect/rules/xss/reflected-xss-rule.js +3 -3
  36. package/lib/protect/sample-aggregator.js +65 -57
  37. package/lib/protect/service.js +709 -104
  38. package/lib/reporter/models/app-activity/sample.js +6 -0
  39. package/lib/reporter/ts-reporter.js +1 -1
  40. package/lib/util/get-file-type.js +47 -0
  41. package/package.json +5 -3
@@ -39,6 +39,12 @@ class Sample {
39
39
  this.input = input;
40
40
  this.request = appContext.request;
41
41
 
42
+ // extra info for processing at sink time.
43
+ // NOT TO BE INCLUDED IN ACTUAL DTM AT REPORTING TIME.
44
+ // This is particularly useful when using the agent lib for processing
45
+ // mongo expansion and injection.
46
+ this._inputInfoForSink = {};
47
+
42
48
  this.assessment = assessment;
43
49
 
44
50
  if (assessment) {
@@ -386,7 +386,7 @@ module.exports = class TSReporter {
386
386
  }
387
387
 
388
388
  if (!context) {
389
- logger.warn(`StorageContext unavailable - unable to send 'Activity'`);
389
+ logger.warn('StorageContext unavailable - sendActivityMessage() failed');
390
390
  return;
391
391
  }
392
392
 
@@ -0,0 +1,47 @@
1
+ /**
2
+ Copyright: 2022 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 path = require('path');
18
+ const parent = require('parent-package-json');
19
+
20
+ // eslint-disable-next-line complexity
21
+ function getType(filename) {
22
+ const url = filename.startsWith('file://') ? filename : `file://${filename}`;
23
+
24
+ const { protocol, pathname } = new URL(url);
25
+
26
+ let parentType = 'commonjs';
27
+ try {
28
+ parentType = parent(pathname).parse().type;
29
+ } catch (err) {
30
+ // Node assumes `commonjs ` if there's no `type` set in package.json
31
+ }
32
+
33
+ if (protocol === 'node:') {
34
+ return 'builtin';
35
+ }
36
+ if (protocol === 'file:') {
37
+ const ext = path.extname(pathname);
38
+ if (ext === '.mjs' || (ext === '.js' && parentType === 'module')) {
39
+ return 'module';
40
+ } else if (ext === '.cjs' || (ext === '.js' && parentType !== 'module')) {
41
+ return 'commonjs';
42
+ }
43
+ }
44
+ return 'unknown';
45
+ }
46
+
47
+ module.exports = getType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "Node.js security instrumentation by Contrast Security",
5
5
  "keywords": [
6
6
  "security",
@@ -76,12 +76,13 @@
76
76
  "@babel/template": "^7.10.4",
77
77
  "@babel/traverse": "^7.12.1",
78
78
  "@babel/types": "^7.12.1",
79
+ "@contrast/agent-lib": "^2.2.3",
79
80
  "@contrast/distringuish-prebuilt": "^2.2.0",
80
81
  "@contrast/flat": "^4.1.1",
81
82
  "@contrast/fn-inspect": "^2.4.4",
82
83
  "@contrast/heapdump": "^1.1.0",
83
84
  "@contrast/protobuf-api": "^3.2.3",
84
- "@contrast/require-hook": "^2.0.10",
85
+ "@contrast/require-hook": "^3.0.0",
85
86
  "@contrast/synchronous-source-maps": "^1.1.0",
86
87
  "amqp-connection-manager": "^3.2.2",
87
88
  "amqplib": "^0.8.0",
@@ -161,6 +162,7 @@
161
162
  "marsdb": "file:test/mock/marsdb",
162
163
  "mocha": "^9.2.0",
163
164
  "mochawesome": "^7.0.1",
165
+ "mock-fs": "^5.1.2",
164
166
  "mongodb": "file:test/mock/mongodb",
165
167
  "mongodb-npm": "npm:mongodb@^3.6.5",
166
168
  "mongoose": "^6.1.1",
@@ -179,7 +181,7 @@
179
181
  "rethinkdb": "file:test/mock/rethinkdb",
180
182
  "sequelize": "^6.11.0",
181
183
  "shellcheck": "^1.0.0",
182
- "sinon": "^7.2.2",
184
+ "sinon": "^9.2.4",
183
185
  "sinon-chai": "^3.3.0",
184
186
  "sqlite3": "file:test/mock/sqlite3",
185
187
  "swig": "file:test/mock/swig",