dd-trace 3.15.0 → 3.17.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 (180) hide show
  1. package/LICENSE-3rdparty.csv +2 -2
  2. package/README.md +53 -0
  3. package/ci/init.js +9 -1
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/index.d.ts +6 -2
  7. package/package.json +24 -19
  8. package/packages/datadog-esbuild/index.js +104 -0
  9. package/packages/datadog-instrumentations/src/cucumber.js +80 -3
  10. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +100 -27
  11. package/packages/datadog-instrumentations/src/helpers/hook.js +13 -3
  12. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  13. package/packages/datadog-instrumentations/src/helpers/instrument.js +6 -0
  14. package/packages/datadog-instrumentations/src/helpers/register.js +2 -2
  15. package/packages/datadog-instrumentations/src/jest.js +35 -3
  16. package/packages/datadog-instrumentations/src/mariadb.js +130 -11
  17. package/packages/datadog-instrumentations/src/mocha.js +30 -6
  18. package/packages/datadog-instrumentations/src/mongodb-core.js +8 -2
  19. package/packages/datadog-instrumentations/src/mongoose.js +1 -1
  20. package/packages/datadog-instrumentations/src/next.js +32 -4
  21. package/packages/datadog-instrumentations/src/pg.js +16 -11
  22. package/packages/datadog-instrumentations/src/playwright.js +2 -2
  23. package/packages/datadog-plugin-amqp10/src/consumer.js +1 -1
  24. package/packages/datadog-plugin-amqp10/src/index.js +1 -1
  25. package/packages/datadog-plugin-amqp10/src/producer.js +3 -2
  26. package/packages/datadog-plugin-amqplib/src/client.js +3 -2
  27. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -1
  28. package/packages/datadog-plugin-amqplib/src/index.js +1 -1
  29. package/packages/datadog-plugin-amqplib/src/producer.js +3 -2
  30. package/packages/datadog-plugin-aws-sdk/src/base.js +7 -2
  31. package/packages/datadog-plugin-aws-sdk/src/index.js +1 -1
  32. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +2 -0
  33. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +2 -0
  34. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -0
  35. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +2 -0
  36. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +2 -0
  37. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +2 -0
  38. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +2 -0
  39. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -0
  40. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +2 -0
  41. package/packages/datadog-plugin-bunyan/src/index.js +1 -1
  42. package/packages/datadog-plugin-cassandra-driver/src/index.js +3 -2
  43. package/packages/datadog-plugin-connect/src/index.js +1 -1
  44. package/packages/datadog-plugin-couchbase/src/index.js +1 -1
  45. package/packages/datadog-plugin-cucumber/src/index.js +33 -6
  46. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  47. package/packages/datadog-plugin-cypress/src/plugin.js +40 -33
  48. package/packages/datadog-plugin-dns/src/index.js +1 -1
  49. package/packages/datadog-plugin-dns/src/lookup.js +1 -1
  50. package/packages/datadog-plugin-dns/src/lookup_service.js +1 -1
  51. package/packages/datadog-plugin-dns/src/resolve.js +1 -1
  52. package/packages/datadog-plugin-dns/src/reverse.js +1 -1
  53. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  54. package/packages/datadog-plugin-express/src/index.js +1 -1
  55. package/packages/datadog-plugin-fastify/src/index.js +1 -1
  56. package/packages/datadog-plugin-find-my-way/src/index.js +1 -1
  57. package/packages/datadog-plugin-fs/src/index.js +1 -1
  58. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +5 -5
  59. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  60. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -1
  61. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +7 -6
  62. package/packages/datadog-plugin-graphql/src/execute.js +1 -1
  63. package/packages/datadog-plugin-graphql/src/index.js +1 -1
  64. package/packages/datadog-plugin-graphql/src/parse.js +1 -1
  65. package/packages/datadog-plugin-graphql/src/resolve.js +1 -1
  66. package/packages/datadog-plugin-graphql/src/validate.js +1 -1
  67. package/packages/datadog-plugin-grpc/src/client.js +1 -1
  68. package/packages/datadog-plugin-grpc/src/index.js +1 -1
  69. package/packages/datadog-plugin-grpc/src/server.js +1 -1
  70. package/packages/datadog-plugin-hapi/src/index.js +1 -1
  71. package/packages/datadog-plugin-http/src/client.js +2 -2
  72. package/packages/datadog-plugin-http/src/index.js +1 -1
  73. package/packages/datadog-plugin-http/src/server.js +2 -2
  74. package/packages/datadog-plugin-http2/src/client.js +4 -3
  75. package/packages/datadog-plugin-http2/src/index.js +1 -1
  76. package/packages/datadog-plugin-http2/src/server.js +2 -2
  77. package/packages/datadog-plugin-ioredis/src/index.js +1 -1
  78. package/packages/datadog-plugin-jest/src/index.js +53 -19
  79. package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -1
  80. package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
  81. package/packages/datadog-plugin-kafkajs/src/producer.js +1 -1
  82. package/packages/datadog-plugin-koa/src/index.js +1 -1
  83. package/packages/datadog-plugin-mariadb/src/index.js +18 -1
  84. package/packages/datadog-plugin-memcached/src/index.js +3 -2
  85. package/packages/datadog-plugin-microgateway-core/src/index.js +1 -1
  86. package/packages/datadog-plugin-mocha/src/index.js +13 -9
  87. package/packages/datadog-plugin-moleculer/src/client.js +1 -1
  88. package/packages/datadog-plugin-moleculer/src/index.js +1 -1
  89. package/packages/datadog-plugin-moleculer/src/server.js +1 -1
  90. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  91. package/packages/datadog-plugin-mysql/src/index.js +3 -2
  92. package/packages/datadog-plugin-mysql2/src/index.js +1 -1
  93. package/packages/datadog-plugin-net/src/index.js +9 -75
  94. package/packages/datadog-plugin-net/src/ipc.js +1 -1
  95. package/packages/datadog-plugin-net/src/tcp.js +3 -2
  96. package/packages/datadog-plugin-next/src/index.js +3 -3
  97. package/packages/datadog-plugin-opensearch/src/index.js +1 -1
  98. package/packages/datadog-plugin-oracledb/src/index.js +3 -2
  99. package/packages/datadog-plugin-paperplane/src/index.js +1 -1
  100. package/packages/datadog-plugin-paperplane/src/logger.js +1 -1
  101. package/packages/datadog-plugin-paperplane/src/server.js +1 -1
  102. package/packages/datadog-plugin-pg/src/index.js +3 -2
  103. package/packages/datadog-plugin-pino/src/index.js +1 -1
  104. package/packages/datadog-plugin-playwright/src/index.js +5 -4
  105. package/packages/datadog-plugin-redis/src/index.js +3 -2
  106. package/packages/datadog-plugin-restify/src/index.js +1 -1
  107. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  108. package/packages/datadog-plugin-rhea/src/index.js +1 -1
  109. package/packages/datadog-plugin-rhea/src/producer.js +3 -2
  110. package/packages/datadog-plugin-router/src/index.js +8 -8
  111. package/packages/datadog-plugin-sharedb/src/index.js +1 -1
  112. package/packages/datadog-plugin-tedious/src/index.js +3 -2
  113. package/packages/datadog-plugin-web/src/index.js +1 -1
  114. package/packages/datadog-plugin-winston/src/index.js +1 -1
  115. package/packages/dd-trace/src/appsec/{templates/blocked.html → blocked_templates.js} +19 -1
  116. package/packages/dd-trace/src/appsec/blocking.js +9 -24
  117. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -1
  118. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -0
  119. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +12 -0
  120. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +1 -1
  121. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +11 -5
  122. package/packages/dd-trace/src/appsec/iast/iast-log.js +111 -0
  123. package/packages/dd-trace/src/appsec/iast/index.js +8 -4
  124. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -6
  125. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +11 -2
  126. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +11 -0
  127. package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +2 -0
  128. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -0
  129. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +5 -3
  130. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +5 -3
  131. package/packages/dd-trace/src/appsec/iast/telemetry/log_collector.js +96 -0
  132. package/packages/dd-trace/src/appsec/iast/telemetry/logs.js +87 -0
  133. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +27 -2
  134. package/packages/dd-trace/src/appsec/index.js +4 -18
  135. package/packages/dd-trace/src/appsec/recommended.json +43 -14
  136. package/packages/dd-trace/src/appsec/remote_config/index.js +1 -1
  137. package/packages/dd-trace/src/appsec/sdk/index.js +2 -2
  138. package/packages/dd-trace/src/ci-visibility/encode/json-encoder.js +27 -0
  139. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +2 -9
  140. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +7 -7
  141. package/packages/dd-trace/src/ci-visibility/exporters/jest-worker/index.js +33 -0
  142. package/packages/dd-trace/src/ci-visibility/exporters/jest-worker/writer.js +37 -0
  143. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +8 -2
  144. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +8 -2
  145. package/packages/dd-trace/src/config.js +44 -22
  146. package/packages/dd-trace/src/constants.js +2 -1
  147. package/packages/dd-trace/src/datastreams/encoding.js +80 -0
  148. package/packages/dd-trace/src/dcitm.js +51 -0
  149. package/packages/dd-trace/src/exporter.js +7 -9
  150. package/packages/dd-trace/src/exporters/common/agents.js +42 -0
  151. package/packages/dd-trace/src/exporters/common/docker.js +4 -1
  152. package/packages/dd-trace/src/exporters/common/request.js +1 -4
  153. package/packages/dd-trace/src/lambda/handler.js +14 -6
  154. package/packages/dd-trace/src/opentracing/propagation/log.js +23 -7
  155. package/packages/dd-trace/src/opentracing/propagation/text_map.js +28 -2
  156. package/packages/dd-trace/src/opentracing/span.js +19 -3
  157. package/packages/dd-trace/src/opentracing/span_context.js +3 -1
  158. package/packages/dd-trace/src/opentracing/tracer.js +3 -1
  159. package/packages/dd-trace/src/plugin_manager.js +7 -7
  160. package/packages/dd-trace/src/plugins/ci_plugin.js +16 -16
  161. package/packages/dd-trace/src/plugins/index.js +1 -0
  162. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  163. package/packages/dd-trace/src/plugins/outgoing.js +2 -1
  164. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  165. package/packages/dd-trace/src/plugins/util/ci.js +12 -0
  166. package/packages/dd-trace/src/plugins/util/ip_extractor.js +23 -27
  167. package/packages/dd-trace/src/plugins/util/test.js +26 -7
  168. package/packages/dd-trace/src/profiling/config.js +87 -20
  169. package/packages/dd-trace/src/profiling/constants.js +16 -0
  170. package/packages/dd-trace/src/profiling/exporter_cli.js +62 -0
  171. package/packages/dd-trace/src/profiling/exporters/agent.js +2 -1
  172. package/packages/dd-trace/src/profiling/profiler.js +21 -8
  173. package/packages/dd-trace/src/profiling/profilers/space.js +21 -1
  174. package/packages/dd-trace/src/span_sampler.js +3 -2
  175. package/packages/dd-trace/src/telemetry/index.js +16 -2
  176. package/packages/dd-trace/src/util.js +10 -1
  177. package/scripts/install_plugin_modules.js +5 -1
  178. package/packages/dd-trace/src/appsec/templates/blocked.json +0 -8
  179. package/scripts/junit_report.js +0 -25
  180. package/scripts/tdd.js +0 -34
@@ -3,7 +3,7 @@
3
3
  const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
4
 
5
5
  class NetIPCPlugin extends ClientPlugin {
6
- static get name () { return 'net' }
6
+ static get id () { return 'net' }
7
7
  static get operation () { return 'ipc' }
8
8
 
9
9
  start ({ options }) {
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const ClientPlugin = require('../../dd-trace/src/plugins/client')
4
5
 
5
6
  class NetTCPPlugin extends ClientPlugin {
6
- static get name () { return 'net' }
7
+ static get id () { return 'net' }
7
8
  static get operation () { return 'tcp' }
8
9
 
9
10
  constructor (...args) {
@@ -37,7 +38,7 @@ class NetTCPPlugin extends ClientPlugin {
37
38
  metrics: {
38
39
  'tcp.remote.port': port,
39
40
  'tcp.local.port': 0,
40
- 'out.port': port
41
+ [CLIENT_PORT_KEY]: port
41
42
  }
42
43
  })
43
44
  }
@@ -6,7 +6,7 @@ const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
6
6
  const { COMPONENT } = require('../../dd-trace/src/constants')
7
7
 
8
8
  class NextPlugin extends Plugin {
9
- static get name () {
9
+ static get id () {
10
10
  return 'next'
11
11
  }
12
12
 
@@ -21,7 +21,7 @@ class NextPlugin extends Plugin {
21
21
  const span = this.tracer.startSpan('next.request', {
22
22
  childOf,
23
23
  tags: {
24
- [COMPONENT]: this.constructor.name,
24
+ [COMPONENT]: this.constructor.id,
25
25
  'service.name': this.config.service || this.tracer._service,
26
26
  'resource.name': req.method,
27
27
  'span.type': 'web',
@@ -69,7 +69,7 @@ class NextPlugin extends Plugin {
69
69
  const req = this._requests.get(span)
70
70
 
71
71
  span.addTags({
72
- [COMPONENT]: this.constructor.name,
72
+ [COMPONENT]: this.constructor.id,
73
73
  'resource.name': `${req.method} ${page}`.trim(),
74
74
  'next.page': page
75
75
  })
@@ -3,7 +3,7 @@
3
3
  const ElasticsearchPlugin = require('../../datadog-plugin-elasticsearch/src')
4
4
 
5
5
  class OpenSearchPlugin extends ElasticsearchPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'opensearch'
8
8
  }
9
9
  }
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
5
  const log = require('../../dd-trace/src/log')
5
6
 
6
7
  class OracledbPlugin extends DatabasePlugin {
7
- static get name () { return 'oracledb' }
8
+ static get id () { return 'oracledb' }
8
9
  static get system () { return 'oracle' }
9
10
 
10
11
  start ({ query, connAttrs }) {
@@ -20,7 +21,7 @@ class OracledbPlugin extends DatabasePlugin {
20
21
  'db.user': this.config.user,
21
22
  'db.instance': url.pathname && url.pathname.substring(1),
22
23
  'db.hostname': url.hostname,
23
- 'db.port': url.port
24
+ [CLIENT_PORT_KEY]: url.port
24
25
  }
25
26
  })
26
27
  }
@@ -5,7 +5,7 @@ const PaperplaneLoggerPlugin = require('./logger')
5
5
  const PaperplaneServerPlugin = require('./server')
6
6
 
7
7
  class PaperplanePlugin extends Plugin {
8
- static get name () {
8
+ static get id () {
9
9
  return 'paperplane'
10
10
  }
11
11
 
@@ -3,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class PaperplaneLoggerPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'paperplane'
8
8
  }
9
9
  }
@@ -4,7 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class PaperplaneServerPlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'paperplane'
9
9
  }
10
10
 
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
5
 
5
6
  class PGPlugin extends DatabasePlugin {
6
- static get name () { return 'pg' }
7
+ static get id () { return 'pg' }
7
8
  static get operation () { return 'query' }
8
9
  static get system () { return 'postgres' }
9
10
 
@@ -22,7 +23,7 @@ class PGPlugin extends DatabasePlugin {
22
23
  'db.name': params.database,
23
24
  'db.user': params.user,
24
25
  'out.host': params.host,
25
- 'out.port': params.port
26
+ [CLIENT_PORT_KEY]: params.port
26
27
  }
27
28
  })
28
29
 
@@ -3,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class PinoPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'pino'
8
8
  }
9
9
  }
@@ -13,7 +13,7 @@ const { RESOURCE_NAME } = require('../../../ext/tags')
13
13
  const { COMPONENT } = require('../../dd-trace/src/constants')
14
14
 
15
15
  class PlaywrightPlugin extends CiPlugin {
16
- static get name () {
16
+ static get id () {
17
17
  return 'playwright'
18
18
  }
19
19
 
@@ -39,13 +39,14 @@ class PlaywrightPlugin extends CiPlugin {
39
39
  const testSuiteMetadata = getTestSuiteCommonTags(
40
40
  this.command,
41
41
  this.frameworkVersion,
42
- testSuite
42
+ testSuite,
43
+ 'playwright'
43
44
  )
44
45
 
45
46
  const testSuiteSpan = this.tracer.startSpan('playwright.test_suite', {
46
47
  childOf: this.testModuleSpan,
47
48
  tags: {
48
- [COMPONENT]: this.constructor.name,
49
+ [COMPONENT]: this.constructor.id,
49
50
  ...this.testEnvironmentMetadata,
50
51
  ...testSuiteMetadata
51
52
  }
@@ -87,7 +88,7 @@ class PlaywrightPlugin extends CiPlugin {
87
88
  childOf: span,
88
89
  startTime: stepStartTime,
89
90
  tags: {
90
- [COMPONENT]: this.constructor.name,
91
+ [COMPONENT]: this.constructor.id,
91
92
  'playwright.step': step.title,
92
93
  [RESOURCE_NAME]: step.title
93
94
  }
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const CachePlugin = require('../../dd-trace/src/plugins/cache')
4
5
  const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
5
6
 
6
7
  class RedisPlugin extends CachePlugin {
7
- static get name () { return 'redis' }
8
+ static get id () { return 'redis' }
8
9
  static get system () { return 'redis' }
9
10
 
10
11
  start ({ db, command, args, connectionOptions = {}, connectionName }) {
@@ -20,7 +21,7 @@ class RedisPlugin extends CachePlugin {
20
21
  'db.name': db || '0',
21
22
  'redis.raw_command': formatCommand(command, args),
22
23
  'out.host': connectionOptions.host,
23
- 'out.port': connectionOptions.port
24
+ [CLIENT_PORT_KEY]: connectionOptions.port
24
25
  }
25
26
  })
26
27
  }
@@ -4,7 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class RestifyPlugin extends RouterPlugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'restify'
9
9
  }
10
10
 
@@ -4,7 +4,7 @@ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
4
  const { storage } = require('../../datadog-core')
5
5
 
6
6
  class RheaConsumerPlugin extends ConsumerPlugin {
7
- static get name () { return 'rhea' }
7
+ static get id () { return 'rhea' }
8
8
 
9
9
  constructor (...args) {
10
10
  super(...args)
@@ -5,7 +5,7 @@ const ConsumerPlugin = require('./consumer')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class RheaPlugin extends CompositePlugin {
8
- static get name () { return 'rhea' }
8
+ static get id () { return 'rhea' }
9
9
  static get plugins () {
10
10
  return {
11
11
  producer: ProducerPlugin,
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
5
 
5
6
  class RheaProducerPlugin extends ProducerPlugin {
6
- static get name () { return 'rhea' }
7
+ static get id () { return 'rhea' }
7
8
  static get operation () { return 'send' }
8
9
 
9
10
  constructor (...args) {
@@ -24,7 +25,7 @@ class RheaProducerPlugin extends ProducerPlugin {
24
25
  'amqp.link.target.address': name,
25
26
  'amqp.link.role': 'sender',
26
27
  'out.host': host,
27
- 'out.port': port
28
+ [CLIENT_PORT_KEY]: port
28
29
  }
29
30
  })
30
31
  }
@@ -7,7 +7,7 @@ const { storage } = require('../../datadog-core')
7
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
8
8
 
9
9
  class RouterPlugin extends WebPlugin {
10
- static get name () {
10
+ static get id () {
11
11
  return 'router'
12
12
  }
13
13
 
@@ -17,7 +17,7 @@ class RouterPlugin extends WebPlugin {
17
17
  this._storeStack = []
18
18
  this._contexts = new WeakMap()
19
19
 
20
- this.addSub(`apm:${this.constructor.name}:middleware:enter`, ({ req, name, route }) => {
20
+ this.addSub(`apm:${this.constructor.id}:middleware:enter`, ({ req, name, route }) => {
21
21
  const childOf = this._getActive(req) || this._getStoreSpan()
22
22
 
23
23
  if (!childOf) return
@@ -37,7 +37,7 @@ class RouterPlugin extends WebPlugin {
37
37
  web.setRoute(req, context.route)
38
38
  })
39
39
 
40
- this.addSub(`apm:${this.constructor.name}:middleware:next`, ({ req }) => {
40
+ this.addSub(`apm:${this.constructor.id}:middleware:next`, ({ req }) => {
41
41
  const context = this._contexts.get(req)
42
42
 
43
43
  if (!context) return
@@ -45,7 +45,7 @@ class RouterPlugin extends WebPlugin {
45
45
  context.stack.pop()
46
46
  })
47
47
 
48
- this.addSub(`apm:${this.constructor.name}:middleware:finish`, ({ req }) => {
48
+ this.addSub(`apm:${this.constructor.id}:middleware:finish`, ({ req }) => {
49
49
  const context = this._contexts.get(req)
50
50
 
51
51
  if (!context || context.middleware.length === 0) return
@@ -53,13 +53,13 @@ class RouterPlugin extends WebPlugin {
53
53
  context.middleware.pop().finish()
54
54
  })
55
55
 
56
- this.addSub(`apm:${this.constructor.name}:middleware:exit`, ({ req }) => {
56
+ this.addSub(`apm:${this.constructor.id}:middleware:exit`, ({ req }) => {
57
57
  const savedStore = this._storeStack.pop()
58
58
  const span = savedStore && savedStore.span
59
59
  this.enter(span, savedStore)
60
60
  })
61
61
 
62
- this.addSub(`apm:${this.constructor.name}:middleware:error`, ({ req, error }) => {
62
+ this.addSub(`apm:${this.constructor.id}:middleware:error`, ({ req, error }) => {
63
63
  web.addError(req, error)
64
64
 
65
65
  if (!this.config.middleware) return
@@ -104,10 +104,10 @@ class RouterPlugin extends WebPlugin {
104
104
  return childOf
105
105
  }
106
106
 
107
- const span = this.tracer.startSpan(`${this.constructor.name}.middleware`, {
107
+ const span = this.tracer.startSpan(`${this.constructor.id}.middleware`, {
108
108
  childOf,
109
109
  tags: {
110
- [COMPONENT]: this.constructor.name,
110
+ [COMPONENT]: this.constructor.id,
111
111
  'resource.name': name || '<anonymous>'
112
112
  }
113
113
  })
@@ -3,7 +3,7 @@
3
3
  const ServerPlugin = require('../../dd-trace/src/plugins/server')
4
4
 
5
5
  class SharedbPlugin extends ServerPlugin {
6
- static get name () { return 'sharedb' }
6
+ static get id () { return 'sharedb' }
7
7
 
8
8
  start ({ actionName, request }) {
9
9
  const span = this.startSpan('sharedb.request', {
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
 
3
+ const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
3
4
  const DatabasePlugin = require('../../dd-trace/src/plugins/database')
4
5
 
5
6
  class TediousPlugin extends DatabasePlugin {
6
- static get name () { return 'tedious' }
7
+ static get id () { return 'tedious' }
7
8
  static get operation () { return 'request' } // TODO: change to match other database plugins
8
9
  static get system () { return 'mssql' }
9
10
 
@@ -17,7 +18,7 @@ class TediousPlugin extends DatabasePlugin {
17
18
  'db.type': 'mssql',
18
19
  'component': 'tedious',
19
20
  'out.host': connectionConfig.server,
20
- 'out.port': connectionConfig.options.port,
21
+ [CLIENT_PORT_KEY]: connectionConfig.options.port,
21
22
  'db.user': connectionConfig.userName || connectionConfig.authentication.options.userName,
22
23
  'db.name': connectionConfig.options.database,
23
24
  'db.instance': connectionConfig.options.instanceName
@@ -4,7 +4,7 @@ const Plugin = require('../../dd-trace/src/plugins/plugin')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class WebPlugin extends Plugin {
7
- static get name () {
7
+ static get id () {
8
8
  return 'web'
9
9
  }
10
10
 
@@ -3,7 +3,7 @@
3
3
  const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
4
4
 
5
5
  class WinstonPlugin extends LogPlugin {
6
- static get name () {
6
+ static get id () {
7
7
  return 'winston'
8
8
  }
9
9
  }
@@ -1,4 +1,7 @@
1
- <!-- Sorry, you’ve been blocked -->
1
+ /* eslint-disable max-len */
2
+ 'use strict'
3
+
4
+ const html = `<!-- Sorry, you've been blocked -->
2
5
  <!DOCTYPE html>
3
6
  <html lang="en">
4
7
 
@@ -97,3 +100,18 @@
97
100
  </body>
98
101
 
99
102
  </html>
103
+ `
104
+
105
+ const json = `{
106
+ "errors": [
107
+ {
108
+ "title": "You've been blocked",
109
+ "detail": "Sorry, you cannot access this page. Please contact the customer service team. Security provided by Datadog."
110
+ }
111
+ ]
112
+ }`
113
+
114
+ module.exports = {
115
+ html,
116
+ json
117
+ }
@@ -1,12 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const log = require('../log')
4
- const fs = require('fs')
4
+ const blockedTemplates = require('./blocked_templates')
5
5
 
6
- // TODO: move template loading to a proper spot.
7
- let templateLoaded = false
8
- let templateHtml = ''
9
- let templateJson = ''
6
+ let templateHtml = blockedTemplates.html
7
+ let templateJson = blockedTemplates.json
10
8
 
11
9
  function block (req, res, rootSpan, abortController) {
12
10
  if (res.headersSent) {
@@ -42,29 +40,16 @@ function block (req, res, rootSpan, abortController) {
42
40
  }
43
41
  }
44
42
 
45
- function loadTemplates (config) {
46
- if (!templateLoaded) {
47
- templateHtml = fs.readFileSync(config.appsec.blockedTemplateHtml)
48
- templateJson = fs.readFileSync(config.appsec.blockedTemplateJson)
49
- templateLoaded = true
43
+ function setTemplates (config) {
44
+ if (config.appsec.blockedTemplateHtml) {
45
+ templateHtml = config.appsec.blockedTemplateHtml
50
46
  }
51
- }
52
-
53
- async function loadTemplatesAsync (config) {
54
- if (!templateLoaded) {
55
- templateHtml = await fs.promises.readFile(config.appsec.blockedTemplateHtml)
56
- templateJson = await fs.promises.readFile(config.appsec.blockedTemplateJson)
57
- templateLoaded = true
47
+ if (config.appsec.blockedTemplateJson) {
48
+ templateJson = config.appsec.blockedTemplateJson
58
49
  }
59
50
  }
60
51
 
61
- function resetTemplates () {
62
- templateLoaded = false
63
- }
64
-
65
52
  module.exports = {
66
53
  block,
67
- loadTemplates,
68
- loadTemplatesAsync,
69
- resetTemplates
54
+ setTemplates
70
55
  }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const als = require('../als')
4
+ const log = require('../../../log')
4
5
 
5
6
  let lock = false // lock to prevent recursive calls to runSubscriptions
6
7
 
@@ -25,7 +26,7 @@ function runSubscriptions (subscriptions, params) {
25
26
  try {
26
27
  result = subscription.callback.method(params, store)
27
28
  } catch (err) {
28
- // TODO: log ?
29
+ log.warn(`Error running subscription ${err}`)
29
30
  }
30
31
 
31
32
  results.push(result)
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  module.exports = {
2
4
  'WEAK_CIPHER_ANALYZER': require('./weak-cipher-analyzer'),
3
5
  'WEAK_HASH_ANALYZER': require('./weak-hash-analyzer'),
@@ -1,4 +1,6 @@
1
1
  'use strict'
2
+
3
+ const path = require('path')
2
4
  const { getIastContext } = require('../iast-context')
3
5
  const { storage } = require('../../../../../datadog-core')
4
6
  const InjectionAnalyzer = require('./injection-analyzer')
@@ -37,6 +39,16 @@ class PathTraversalAnalyzer extends InjectionAnalyzer {
37
39
  }
38
40
  this.analyze(pathArguments)
39
41
  })
42
+
43
+ this.exclusionList = [ path.join('node_modules', 'send') + path.sep ]
44
+ }
45
+
46
+ _isExcluded (location) {
47
+ let ret = false
48
+ if (location && location.path) {
49
+ ret = this.exclusionList.some(elem => location.path.includes(elem))
50
+ }
51
+ return ret
40
52
  }
41
53
 
42
54
  analyze (value) {
@@ -6,7 +6,7 @@ class SqlInjectionAnalyzer extends InjectionAnalyzer {
6
6
  super('SQL_INJECTION')
7
7
  this.addSub('apm:mysql:query:start', ({ sql }) => this.analyze(sql))
8
8
  this.addSub('apm:mysql2:query:start', ({ sql }) => this.analyze(sql))
9
- this.addSub('apm:pg:query:start', ({ originalQuery }) => this.analyze(originalQuery))
9
+ this.addSub('apm:pg:query:start', ({ query }) => this.analyze(query.text))
10
10
  }
11
11
  }
12
12
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const Plugin = require('../../../../src/plugins/plugin')
4
4
  const { storage } = require('../../../../../datadog-core')
5
- const log = require('../../../log')
5
+ const iastLog = require('../iast-log')
6
6
  const { getFirstNonDDPathAndLine } = require('../path-line')
7
7
  const { createVulnerability, addVulnerability } = require('../vulnerability-reporter')
8
8
  const { getIastContext } = require('../iast-context')
@@ -19,7 +19,7 @@ class Analyzer extends Plugin {
19
19
  try {
20
20
  handler(message, name)
21
21
  } catch (e) {
22
- log.debug(e)
22
+ iastLog.errorAndPublish(e)
23
23
  }
24
24
  }
25
25
  }
@@ -32,12 +32,18 @@ class Analyzer extends Plugin {
32
32
  return false
33
33
  }
34
34
 
35
+ _isExcluded (location) {
36
+ return false
37
+ }
38
+
35
39
  _report (value, context) {
36
40
  const evidence = this._getEvidence(value, context)
37
41
  const location = this._getLocation()
38
- const spanId = context && context.rootSpan && context.rootSpan.context().toSpanId()
39
- const vulnerability = createVulnerability(this._type, evidence, spanId, location)
40
- addVulnerability(context, vulnerability)
42
+ if (!this._isExcluded(location)) {
43
+ const spanId = context && context.rootSpan && context.rootSpan.context().toSpanId()
44
+ const vulnerability = createVulnerability(this._type, evidence, spanId, location)
45
+ addVulnerability(context, vulnerability)
46
+ }
41
47
  }
42
48
 
43
49
  _reportIfVulnerable (value, context) {
@@ -0,0 +1,111 @@
1
+ 'use strict'
2
+
3
+ const log = require('../../log')
4
+ const telemetryLogs = require('./telemetry/logs')
5
+ const { calculateDDBasePath } = require('../../util')
6
+
7
+ const ddBasePath = calculateDDBasePath(__dirname)
8
+ const EOL = '\n'
9
+ const STACK_FRAME_LINE_REGEX = /^\s*at\s/gm
10
+
11
+ function sanitize (logEntry, stack) {
12
+ if (!stack) return logEntry
13
+
14
+ let stackLines = stack.split(EOL)
15
+
16
+ const firstIndex = stackLines.findIndex(l => l.match(STACK_FRAME_LINE_REGEX))
17
+
18
+ const isDDCode = firstIndex > -1 && stackLines[firstIndex].includes(ddBasePath)
19
+ stackLines = stackLines
20
+ .filter((line, index) => (isDDCode && index < firstIndex) || line.includes(ddBasePath))
21
+ .map(line => line.replace(ddBasePath, ''))
22
+
23
+ logEntry.stack_trace = stackLines.join(EOL)
24
+
25
+ if (!isDDCode) {
26
+ logEntry.message = 'omitted'
27
+ }
28
+
29
+ return logEntry
30
+ }
31
+
32
+ function getTelemetryLog (data, level) {
33
+ try {
34
+ data = typeof data === 'function' ? data() : data
35
+
36
+ let message
37
+ if (typeof data !== 'object' || !data) {
38
+ message = String(data)
39
+ } else {
40
+ message = String(data.message || data)
41
+ }
42
+
43
+ let logEntry = {
44
+ message,
45
+ level
46
+ }
47
+
48
+ if (data.stack) {
49
+ logEntry = sanitize(logEntry, data.stack)
50
+ if (logEntry.stack_trace === '') {
51
+ return
52
+ }
53
+ }
54
+
55
+ return logEntry
56
+ } catch (e) {
57
+ log.error(e)
58
+ }
59
+ }
60
+
61
+ const iastLog = {
62
+ debug (data) {
63
+ log.debug(data)
64
+ return this
65
+ },
66
+
67
+ info (data) {
68
+ log.info(data)
69
+ return this
70
+ },
71
+
72
+ warn (data) {
73
+ log.warn(data)
74
+ return this
75
+ },
76
+
77
+ error (data) {
78
+ log.error(data)
79
+ return this
80
+ },
81
+
82
+ publish (data, level) {
83
+ if (telemetryLogs.isLevelEnabled(level)) {
84
+ const telemetryLog = getTelemetryLog(data, level)
85
+ telemetryLogs.publish(telemetryLog)
86
+ }
87
+ return this
88
+ },
89
+
90
+ debugAndPublish (data) {
91
+ this.debug(data)
92
+ return this.publish(data, 'DEBUG')
93
+ },
94
+
95
+ infoAndPublish (data) {
96
+ this.info(data)
97
+ return this.publish(data, 'DEBUG')
98
+ },
99
+
100
+ warnAndPublish (data) {
101
+ this.warn(data)
102
+ return this.publish(data, 'WARN')
103
+ },
104
+
105
+ errorAndPublish (data) {
106
+ this.error(data)
107
+ return this.publish(data, 'ERROR')
108
+ }
109
+ }
110
+
111
+ module.exports = iastLog