dd-trace 2.31.0 → 2.32.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 (58) hide show
  1. package/package.json +6 -6
  2. package/packages/datadog-instrumentations/src/body-parser.js +15 -9
  3. package/packages/datadog-instrumentations/src/express.js +32 -0
  4. package/packages/datadog-instrumentations/src/http/server.js +2 -1
  5. package/packages/datadog-instrumentations/src/playwright.js +3 -0
  6. package/packages/datadog-plugin-amqp10/src/consumer.js +1 -3
  7. package/packages/datadog-plugin-amqp10/src/producer.js +1 -3
  8. package/packages/datadog-plugin-amqplib/src/client.js +4 -3
  9. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -3
  10. package/packages/datadog-plugin-amqplib/src/producer.js +1 -3
  11. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +4 -3
  12. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -3
  13. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -3
  14. package/packages/datadog-plugin-http/src/server.js +2 -2
  15. package/packages/datadog-plugin-http2/src/server.js +0 -5
  16. package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -4
  17. package/packages/datadog-plugin-kafkajs/src/producer.js +1 -3
  18. package/packages/datadog-plugin-rhea/src/consumer.js +1 -3
  19. package/packages/datadog-plugin-rhea/src/producer.js +1 -5
  20. package/packages/dd-trace/src/appsec/addresses.js +0 -3
  21. package/packages/dd-trace/src/appsec/blocked_templates.js +2 -9
  22. package/packages/dd-trace/src/appsec/blocking.js +1 -1
  23. package/packages/dd-trace/src/appsec/{gateway/channels.js → channels.js} +4 -4
  24. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
  25. package/packages/dd-trace/src/appsec/index.js +87 -79
  26. package/packages/dd-trace/src/appsec/recommended.json +448 -121
  27. package/packages/dd-trace/src/appsec/remote_config/apply_states.js +7 -0
  28. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +2 -0
  29. package/packages/dd-trace/src/appsec/remote_config/index.js +29 -10
  30. package/packages/dd-trace/src/appsec/remote_config/manager.js +33 -12
  31. package/packages/dd-trace/src/appsec/reporter.js +27 -58
  32. package/packages/dd-trace/src/appsec/rule_manager.js +160 -32
  33. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +4 -12
  34. package/packages/dd-trace/src/appsec/waf/index.js +75 -0
  35. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +57 -0
  36. package/packages/dd-trace/src/appsec/waf/waf_manager.js +66 -0
  37. package/packages/dd-trace/src/config.js +17 -1
  38. package/packages/dd-trace/src/encode/0.4.js +12 -4
  39. package/packages/dd-trace/src/plugin_manager.js +2 -0
  40. package/packages/dd-trace/src/plugins/client.js +3 -2
  41. package/packages/dd-trace/src/plugins/consumer.js +17 -2
  42. package/packages/dd-trace/src/plugins/inbound.js +7 -0
  43. package/packages/dd-trace/src/plugins/{outgoing.js → outbound.js} +2 -2
  44. package/packages/dd-trace/src/plugins/producer.js +17 -2
  45. package/packages/dd-trace/src/plugins/server.js +2 -2
  46. package/packages/dd-trace/src/plugins/tracing.js +11 -0
  47. package/packages/dd-trace/src/service-naming/index.js +41 -0
  48. package/packages/dd-trace/src/service-naming/schemas/definition.js +28 -0
  49. package/packages/dd-trace/src/service-naming/schemas/index.js +6 -0
  50. package/packages/dd-trace/src/service-naming/schemas/v0.js +66 -0
  51. package/packages/dd-trace/src/service-naming/schemas/v1.js +58 -0
  52. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +0 -137
  53. package/packages/dd-trace/src/appsec/callbacks/index.js +0 -7
  54. package/packages/dd-trace/src/appsec/gateway/als.js +0 -6
  55. package/packages/dd-trace/src/appsec/gateway/engine/engine.js +0 -140
  56. package/packages/dd-trace/src/appsec/gateway/engine/index.js +0 -51
  57. package/packages/dd-trace/src/appsec/gateway/engine/runner.js +0 -42
  58. package/packages/dd-trace/src/plugins/incoming.js +0 -7
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- // lazy loading
4
- // TODO: cache the returned value
5
- module.exports = {
6
- get DDWAF () { return require('./ddwaf') }
7
- }
@@ -1,6 +0,0 @@
1
- 'use strict'
2
-
3
- // TODO: use datadog-core storage instead
4
- const { AsyncLocalStorage } = require('async_hooks')
5
-
6
- module.exports = new AsyncLocalStorage()
@@ -1,140 +0,0 @@
1
- 'use strict'
2
-
3
- const Runner = require('./runner')
4
-
5
- const MAX_CONTEXT_SIZE = 1024
6
-
7
- class SubscriptionManager {
8
- constructor () {
9
- this.addressToSubscriptions = new Map()
10
- this.addresses = new Set()
11
- this.subscriptions = new Set()
12
- }
13
-
14
- clear () {
15
- this.addressToSubscriptions = new Map()
16
- this.addresses = new Set()
17
- this.subscriptions = new Set()
18
- }
19
-
20
- addSubscription (subscription) {
21
- if (!subscription.addresses.length || this.subscriptions.has(subscription)) return
22
-
23
- for (let i = 0; i < subscription.addresses.length; ++i) {
24
- const address = subscription.addresses[i]
25
-
26
- this.addresses.add(address)
27
-
28
- const list = this.addressToSubscriptions.get(address)
29
-
30
- if (list === undefined) {
31
- this.addressToSubscriptions.set(address, [subscription])
32
- } else {
33
- list.push(subscription)
34
- }
35
- }
36
-
37
- this.subscriptions.add(subscription)
38
- }
39
-
40
- matchSubscriptions (newAddresses, allAddresses) {
41
- const addresses = new Set()
42
- const subscriptions = new Set()
43
- const knownSubscriptions = new Set()
44
-
45
- // TODO: possible optimization: collect matchedSubscriptions on the fly in Context#setValue
46
- newAddresses.forEach((newAddress) => {
47
- const matchedSubscriptions = this.addressToSubscriptions.get(newAddress)
48
-
49
- if (matchedSubscriptions === undefined) return
50
-
51
- for (let j = 0; j < matchedSubscriptions.length; ++j) {
52
- const subscription = matchedSubscriptions[j]
53
-
54
- if (knownSubscriptions.has(subscription) === true) continue
55
- knownSubscriptions.add(subscription)
56
-
57
- const isFulfilled = subscription.addresses.every(allAddresses.has, allAddresses)
58
-
59
- if (isFulfilled === true) {
60
- for (let k = 0; k < subscription.addresses.length; ++k) {
61
- addresses.add(subscription.addresses[k])
62
- }
63
-
64
- subscriptions.add(subscription)
65
- }
66
- }
67
- })
68
-
69
- return { addresses, subscriptions }
70
- }
71
-
72
- dispatch (newAddresses, allAddresses, context) {
73
- const matches = this.matchSubscriptions(newAddresses, allAddresses)
74
-
75
- // TODO: possible optimization
76
- // check if matches.subscriptions is empty here instead of in runner.js
77
-
78
- const params = {}
79
-
80
- matches.addresses.forEach((address) => {
81
- params[address] = context.resolve(address)
82
- })
83
-
84
- return Runner.runSubscriptions(matches.subscriptions, params)
85
- }
86
- }
87
-
88
- class Context {
89
- static setManager (manager) {
90
- this.manager = manager
91
- }
92
-
93
- constructor () {
94
- // TODO: this probably don't need to be a Map()
95
- this.store = new Map()
96
- this.allAddresses = new Set()
97
- this.newAddresses = new Set()
98
- }
99
-
100
- clear () {
101
- this.store = new Map()
102
- this.allAddresses = new Set()
103
- this.newAddresses = new Set()
104
- }
105
-
106
- setValue (address, value) {
107
- if (this.allAddresses.size >= MAX_CONTEXT_SIZE) return this
108
-
109
- // cannot optimize for objects because they're pointers
110
- if (typeof value !== 'object') {
111
- const oldValue = this.store.get(address)
112
- if (oldValue === value) return this
113
- }
114
-
115
- this.store.set(address, value)
116
- this.allAddresses.add(address)
117
- this.newAddresses.add(address)
118
-
119
- return this
120
- }
121
-
122
- dispatch () {
123
- if (this.newAddresses.size === 0) return []
124
-
125
- const result = Context.manager.dispatch(this.newAddresses, this.allAddresses, this)
126
-
127
- this.newAddresses.clear()
128
-
129
- return result
130
- }
131
-
132
- resolve (address) {
133
- return this.store.get(address)
134
- }
135
- }
136
-
137
- module.exports = {
138
- SubscriptionManager,
139
- Context
140
- }
@@ -1,51 +0,0 @@
1
- 'use strict'
2
-
3
- const { SubscriptionManager, Context } = require('./engine')
4
- const als = require('../als')
5
-
6
- const manager = new SubscriptionManager()
7
- Context.setManager(manager)
8
-
9
- function startContext () {
10
- const store = new Map()
11
-
12
- store.set('context', new Context())
13
-
14
- als.enterWith(store)
15
-
16
- return store
17
- }
18
-
19
- function getContext () {
20
- const store = als.getStore()
21
-
22
- return store && store.get('context')
23
- }
24
-
25
- function needsAddress (address) {
26
- return manager.addresses.has(address)
27
- }
28
-
29
- function propagate (data, context = getContext()) {
30
- if (!context) return
31
-
32
- const keys = Object.keys(data)
33
-
34
- for (let i = 0; i < keys.length; ++i) {
35
- const key = keys[i]
36
-
37
- if (needsAddress(key)) {
38
- context.setValue(key, data[key])
39
- }
40
- }
41
-
42
- return context.dispatch()
43
- }
44
-
45
- module.exports = {
46
- manager,
47
- startContext,
48
- getContext,
49
- needsAddress,
50
- propagate
51
- }
@@ -1,42 +0,0 @@
1
- 'use strict'
2
-
3
- const als = require('../als')
4
- const log = require('../../../log')
5
-
6
- let lock = false // lock to prevent recursive calls to runSubscriptions
7
-
8
- function runSubscriptions (subscriptions, params) {
9
- const results = []
10
-
11
- if (lock || !subscriptions.size) return results
12
- lock = true
13
-
14
- const store = als.getStore()
15
-
16
- // TODO: possible optimization
17
- // can we deduplicate those before ?
18
- const executedCallbacks = new Set()
19
-
20
- for (const subscription of subscriptions) {
21
- if (executedCallbacks.has(subscription.callback)) continue
22
- executedCallbacks.add(subscription.callback)
23
-
24
- let result
25
-
26
- try {
27
- result = subscription.callback.method(params, store)
28
- } catch (err) {
29
- log.warn(`Error running subscription ${err}`)
30
- }
31
-
32
- results.push(result)
33
- }
34
-
35
- lock = false
36
-
37
- return results
38
- }
39
-
40
- module.exports = {
41
- runSubscriptions
42
- }
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- const TracingPlugin = require('./tracing')
4
-
5
- class IncomingPlugin extends TracingPlugin {}
6
-
7
- module.exports = IncomingPlugin