dd-trace 5.0.0-pre-8ce9a1a → 5.0.0-pre-17fa54d
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.
- package/LICENSE-3rdparty.csv +1 -1
- package/README.md +3 -3
- package/index.d.ts +9 -1
- package/package.json +5 -5
- package/packages/datadog-core/src/storage/async_resource.js +1 -1
- package/packages/datadog-esbuild/index.js +1 -20
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -2
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
- package/packages/datadog-instrumentations/src/knex.js +24 -17
- package/packages/datadog-instrumentations/src/next.js +58 -23
- package/packages/datadog-plugin-http/src/client.js +2 -0
- package/packages/datadog-plugin-kafkajs/src/consumer.js +4 -2
- package/packages/datadog-plugin-kafkajs/src/producer.js +9 -6
- package/packages/datadog-plugin-next/src/index.js +4 -3
- package/packages/dd-trace/src/appsec/channels.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +1 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-analyzer.js +60 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +269 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +5 -2
- package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +22 -4
- package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +9 -2
- package/packages/dd-trace/src/appsec/iast/analyzers/xcontenttype-header-missing-analyzer.js +2 -2
- package/packages/dd-trace/src/appsec/iast/iast-log.js +9 -4
- package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
- package/packages/dd-trace/src/appsec/iast/index.js +1 -1
- package/packages/dd-trace/src/appsec/iast/path-line.js +7 -2
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +13 -2
- package/packages/dd-trace/src/appsec/iast/telemetry/index.js +1 -14
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +19 -0
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +2 -1
- package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +1 -0
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +5 -1
- package/packages/dd-trace/src/appsec/recommended.json +272 -48
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +17 -7
- package/packages/dd-trace/src/config.js +27 -12
- package/packages/dd-trace/src/datastreams/processor.js +53 -13
- package/packages/dd-trace/src/iitm.js +1 -1
- package/packages/dd-trace/src/log/channels.js +1 -1
- package/packages/dd-trace/src/plugin_manager.js +1 -1
- package/packages/dd-trace/src/plugins/plugin.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +3 -17
- package/packages/dd-trace/src/profiling/profilers/wall.js +38 -39
- package/packages/dd-trace/src/ritm.js +1 -1
- package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
- package/packages/dd-trace/src/telemetry/index.js +5 -1
- package/packages/dd-trace/src/telemetry/logs/index.js +65 -0
- package/packages/dd-trace/src/{appsec/iast/telemetry/log → telemetry/logs}/log-collector.js +9 -22
- package/packages/dd-trace/src/tracer.js +4 -2
- package/packages/dd-trace/src/appsec/iast/telemetry/log/index.js +0 -87
- package/packages/diagnostics_channel/index.js +0 -3
- package/packages/diagnostics_channel/src/index.js +0 -121
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -8,7 +8,7 @@ require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
|
|
|
8
8
|
require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
|
|
9
9
|
require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
|
|
10
10
|
require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
|
|
11
|
-
require,
|
|
11
|
+
require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
|
|
12
12
|
require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
|
|
13
13
|
require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
|
|
14
14
|
require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
|
package/README.md
CHANGED
|
@@ -202,11 +202,11 @@ To get around this, one can treat all third party modules, or at least third par
|
|
|
202
202
|
|
|
203
203
|
For these reasons it's necessary to have custom-built bundler plugins. Such plugins are able to instruct the bundler on how to behave, injecting intermediary code and otherwise intercepting the "translated" `require()` calls. The result is that many more packages are then included in the bundled JavaScript file. Some applications can have 100% of modules bundled, however native modules still need to remain external to the bundle.
|
|
204
204
|
|
|
205
|
-
###
|
|
205
|
+
### ESBuild Support
|
|
206
206
|
|
|
207
|
-
This library provides experimental
|
|
207
|
+
This library provides experimental ESBuild support in the form of an ESBuild plugin. Require the `dd-trace/esbuild` module when building your bundle to enable the plugin.
|
|
208
208
|
|
|
209
|
-
Here's an example of how one might use `dd-trace` with
|
|
209
|
+
Here's an example of how one might use `dd-trace` with ESBuild:
|
|
210
210
|
|
|
211
211
|
```javascript
|
|
212
212
|
const ddPlugin = require('dd-trace/esbuild')
|
package/index.d.ts
CHANGED
|
@@ -453,7 +453,15 @@ export declare interface TracerOptions {
|
|
|
453
453
|
* Whether to enable vulnerability redaction
|
|
454
454
|
* @default true
|
|
455
455
|
*/
|
|
456
|
-
redactionEnabled?: boolean
|
|
456
|
+
redactionEnabled?: boolean,
|
|
457
|
+
/**
|
|
458
|
+
* Specifies a regex that will redact sensitive source names in vulnerability reports.
|
|
459
|
+
*/
|
|
460
|
+
redactionNamePattern?: string,
|
|
461
|
+
/**
|
|
462
|
+
* Specifies a regex that will redact sensitive source values in vulnerability reports.
|
|
463
|
+
*/
|
|
464
|
+
redactionValuePattern?: string
|
|
457
465
|
}
|
|
458
466
|
};
|
|
459
467
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "5.0.0-pre-
|
|
3
|
+
"version": "5.0.0-pre-17fa54d",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
|
|
20
20
|
"test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
|
|
21
21
|
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
|
|
22
|
-
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
|
|
22
|
+
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
|
|
23
23
|
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
|
|
24
24
|
"test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
|
|
25
25
|
"test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"node": ">=16"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@datadog/native-appsec": "
|
|
72
|
-
"@datadog/native-iast-rewriter": "2.1
|
|
71
|
+
"@datadog/native-appsec": "4.0.0",
|
|
72
|
+
"@datadog/native-iast-rewriter": "2.2.1",
|
|
73
73
|
"@datadog/native-iast-taint-tracking": "1.6.3",
|
|
74
74
|
"@datadog/native-metrics": "^2.0.0",
|
|
75
75
|
"@datadog/pprof": "4.0.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@opentelemetry/api": "^1.0.0",
|
|
78
78
|
"@opentelemetry/core": "^1.14.0",
|
|
79
79
|
"crypto-randomuuid": "^1.0.0",
|
|
80
|
-
"
|
|
80
|
+
"dc-polyfill": "^0.1.2",
|
|
81
81
|
"ignore": "^5.2.4",
|
|
82
82
|
"import-in-the-middle": "^1.4.2",
|
|
83
83
|
"int64-buffer": "^0.1.9",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { createHook, executionAsyncResource } = require('async_hooks')
|
|
4
|
-
const { channel } = require('
|
|
4
|
+
const { channel } = require('dc-polyfill')
|
|
5
5
|
|
|
6
6
|
const beforeCh = channel('dd-trace:storage:before')
|
|
7
7
|
const afterCh = channel('dd-trace:storage:after')
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations.js')
|
|
6
6
|
const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
|
|
7
7
|
|
|
8
|
-
warnIfUnsupported()
|
|
9
|
-
|
|
10
8
|
for (const hook of Object.values(hooks)) {
|
|
11
9
|
hook()
|
|
12
10
|
}
|
|
@@ -144,7 +142,7 @@ module.exports.setup = function (build) {
|
|
|
144
142
|
${fileCode}
|
|
145
143
|
})(...arguments);
|
|
146
144
|
{
|
|
147
|
-
const dc = require('
|
|
145
|
+
const dc = require('dc-polyfill');
|
|
148
146
|
const ch = dc.channel('${CHANNEL}');
|
|
149
147
|
const mod = module.exports
|
|
150
148
|
const payload = {
|
|
@@ -167,23 +165,6 @@ module.exports.setup = function (build) {
|
|
|
167
165
|
})
|
|
168
166
|
}
|
|
169
167
|
|
|
170
|
-
// Currently esbuild support requires Node.js >=v16.17 or >=v18.7
|
|
171
|
-
// Better yet it would support Node >=v14.17 or >=v16
|
|
172
|
-
// Of course, the most ideal would be to support all versions of Node that dd-trace supports.
|
|
173
|
-
// Version constraints based on Node's diagnostics_channel support
|
|
174
|
-
function warnIfUnsupported () {
|
|
175
|
-
const [major, minor] = process.versions.node.split('.').map(Number)
|
|
176
|
-
if (
|
|
177
|
-
major < 16 ||
|
|
178
|
-
(major === 16 && minor < 17) ||
|
|
179
|
-
(major === 18 && minor < 7)) {
|
|
180
|
-
console.error('WARNING: Esbuild support isn\'t available for older versions of Node.js.')
|
|
181
|
-
console.error(`Expected: Node.js >=v16.17 or >=v18.7. Actual: Node.js = ${process.version}.`)
|
|
182
|
-
console.error('This application may build properly with this version of Node.js, but unless a')
|
|
183
|
-
console.error('more recent version is used at runtime, third party packages won\'t be instrumented.')
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
168
|
// @see https://github.com/nodejs/node/issues/47000
|
|
188
169
|
function dotFriendlyResolve (path, directory) {
|
|
189
170
|
if (path === '.') {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { addHook, channel } = require('./helpers/instrument')
|
|
3
|
+
const { addHook, channel, AsyncResource } = require('./helpers/instrument')
|
|
4
4
|
const { wrapThen } = require('./helpers/promise')
|
|
5
5
|
const shimmer = require('../../datadog-shimmer')
|
|
6
6
|
|
|
@@ -39,34 +39,41 @@ addHook({
|
|
|
39
39
|
return raw.apply(this, arguments)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
43
|
+
|
|
42
44
|
function finish () {
|
|
43
45
|
finishRawQueryCh.publish()
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
return asyncResource.runInAsyncScope(() => {
|
|
49
|
+
startRawQueryCh.publish({ sql, dialect: this.dialect })
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
const rawResult = raw.apply(this, arguments)
|
|
52
|
+
shimmer.wrap(rawResult, 'then', originalThen => function () {
|
|
53
|
+
return asyncResource.runInAsyncScope(() => {
|
|
54
|
+
arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
|
|
55
|
+
if (arguments[1]) arguments[1] = wrapCallbackWithFinish(arguments[1], finish)
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
|
|
52
|
-
arguments[1] = wrapCallbackWithFinish(arguments[1], finish)
|
|
57
|
+
const originalThenResult = originalThen.apply(this, arguments)
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
shimmer.wrap(originalThenResult, 'catch', originalCatch => function () {
|
|
60
|
+
arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
|
|
61
|
+
return originalCatch.apply(this, arguments)
|
|
62
|
+
})
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return originalCatch.apply(this, arguments)
|
|
64
|
+
return originalThenResult
|
|
65
|
+
})
|
|
59
66
|
})
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
shimmer.wrap(rawResult, 'asCallback', originalAsCallback => function () {
|
|
69
|
+
return asyncResource.runInAsyncScope(() => {
|
|
70
|
+
arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
|
|
71
|
+
return originalAsCallback.apply(this, arguments)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
|
|
66
|
-
return originalAsCallback.apply(this, arguments)
|
|
75
|
+
return rawResult
|
|
67
76
|
})
|
|
68
|
-
|
|
69
|
-
return rawResult
|
|
70
77
|
})
|
|
71
78
|
return Knex
|
|
72
79
|
})
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
// TODO: either instrument all or none of the render functions
|
|
4
|
-
|
|
5
3
|
const { channel, addHook } = require('./helpers/instrument')
|
|
6
4
|
const shimmer = require('../../datadog-shimmer')
|
|
7
5
|
const { DD_MAJOR } = require('../../../version')
|
|
@@ -14,6 +12,9 @@ const bodyParsedChannel = channel('apm:next:body-parsed')
|
|
|
14
12
|
const queryParsedChannel = channel('apm:next:query-parsed')
|
|
15
13
|
|
|
16
14
|
const requests = new WeakSet()
|
|
15
|
+
const nodeNextRequestsToNextRequests = new WeakMap()
|
|
16
|
+
|
|
17
|
+
const MIDDLEWARE_HEADER = 'x-middleware-invoke'
|
|
17
18
|
|
|
18
19
|
function wrapHandleRequest (handleRequest) {
|
|
19
20
|
return function (req, res, pathname, query) {
|
|
@@ -56,18 +57,6 @@ function wrapHandleApiRequestWithMatch (handleApiRequest) {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
function wrapRenderToResponse (renderToResponse) {
|
|
60
|
-
return function (ctx) {
|
|
61
|
-
return instrument(ctx.req, ctx.res, () => renderToResponse.apply(this, arguments))
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function wrapRenderErrorToResponse (renderErrorToResponse) {
|
|
66
|
-
return function (ctx) {
|
|
67
|
-
return instrument(ctx.req, ctx.res, () => renderErrorToResponse.apply(this, arguments))
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
60
|
function wrapRenderToHTML (renderToHTML) {
|
|
72
61
|
return function (req, res, pathname, query, parsedUrl) {
|
|
73
62
|
return instrument(req, res, () => renderToHTML.apply(this, arguments))
|
|
@@ -80,6 +69,18 @@ function wrapRenderErrorToHTML (renderErrorToHTML) {
|
|
|
80
69
|
}
|
|
81
70
|
}
|
|
82
71
|
|
|
72
|
+
function wrapRenderToResponse (renderToResponse) {
|
|
73
|
+
return function (ctx) {
|
|
74
|
+
return instrument(ctx.req, ctx.res, () => renderToResponse.apply(this, arguments))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function wrapRenderErrorToResponse (renderErrorToResponse) {
|
|
79
|
+
return function (ctx) {
|
|
80
|
+
return instrument(ctx.req, ctx.res, () => renderErrorToResponse.apply(this, arguments))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
83
84
|
function wrapFindPageComponents (findPageComponents) {
|
|
84
85
|
return function (pathname, query) {
|
|
85
86
|
const result = findPageComponents.apply(this, arguments)
|
|
@@ -114,7 +115,9 @@ function instrument (req, res, handler) {
|
|
|
114
115
|
req = req.originalRequest || req
|
|
115
116
|
res = res.originalResponse || res
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
// TODO support middleware properly in the future?
|
|
119
|
+
const isMiddleware = req.headers[MIDDLEWARE_HEADER]
|
|
120
|
+
if (isMiddleware || requests.has(req)) return handler()
|
|
118
121
|
|
|
119
122
|
requests.add(req)
|
|
120
123
|
|
|
@@ -154,6 +157,11 @@ function finish (ctx, result, err) {
|
|
|
154
157
|
errorChannel.publish(ctx)
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
const maybeNextRequest = nodeNextRequestsToNextRequests.get(ctx.req)
|
|
161
|
+
if (maybeNextRequest) {
|
|
162
|
+
ctx.nextRequest = maybeNextRequest
|
|
163
|
+
}
|
|
164
|
+
|
|
157
165
|
finishChannel.publish(ctx)
|
|
158
166
|
|
|
159
167
|
if (err) {
|
|
@@ -163,6 +171,24 @@ function finish (ctx, result, err) {
|
|
|
163
171
|
return result
|
|
164
172
|
}
|
|
165
173
|
|
|
174
|
+
// also wrapped in dist/server/future/route-handlers/app-route-route-handler.js
|
|
175
|
+
// in versions below 13.3.0 that support middleware,
|
|
176
|
+
// however, it is not provided as a class function or exported property
|
|
177
|
+
addHook({
|
|
178
|
+
name: 'next',
|
|
179
|
+
versions: ['>=13.3.0'],
|
|
180
|
+
file: 'dist/server/web/spec-extension/adapters/next-request.js'
|
|
181
|
+
}, NextRequestAdapter => {
|
|
182
|
+
shimmer.wrap(NextRequestAdapter.NextRequestAdapter, 'fromNodeNextRequest', fromNodeNextRequest => {
|
|
183
|
+
return function (nodeNextRequest) {
|
|
184
|
+
const nextRequest = fromNodeNextRequest.apply(this, arguments)
|
|
185
|
+
nodeNextRequestsToNextRequests.set(nodeNextRequest.originalRequest, nextRequest)
|
|
186
|
+
return nextRequest
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
return NextRequestAdapter
|
|
190
|
+
})
|
|
191
|
+
|
|
166
192
|
addHook({
|
|
167
193
|
name: 'next',
|
|
168
194
|
versions: ['>=11.1'],
|
|
@@ -175,27 +201,32 @@ addHook({
|
|
|
175
201
|
file: 'dist/next-server/server/serve-static.js'
|
|
176
202
|
}, serveStatic => shimmer.wrap(serveStatic, 'serveStatic', wrapServeStatic))
|
|
177
203
|
|
|
178
|
-
addHook({ name: 'next', versions: ['>=
|
|
204
|
+
addHook({ name: 'next', versions: ['>=11.1'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
179
205
|
const Server = nextServer.default
|
|
180
206
|
|
|
181
207
|
shimmer.wrap(Server.prototype, 'handleRequest', wrapHandleRequest)
|
|
182
|
-
|
|
208
|
+
|
|
209
|
+
// Wrapping these makes sure any public API render methods called in a custom server
|
|
210
|
+
// are traced properly
|
|
211
|
+
// (instead of wrapping the top-level API methods, just wrapping these covers them all)
|
|
183
212
|
shimmer.wrap(Server.prototype, 'renderToResponse', wrapRenderToResponse)
|
|
184
213
|
shimmer.wrap(Server.prototype, 'renderErrorToResponse', wrapRenderErrorToResponse)
|
|
214
|
+
|
|
185
215
|
shimmer.wrap(Server.prototype, 'findPageComponents', wrapFindPageComponents)
|
|
186
216
|
|
|
187
217
|
return nextServer
|
|
188
218
|
})
|
|
189
219
|
|
|
190
|
-
|
|
220
|
+
// `handleApiRequest` changes parameters/implementation at 13.2.0
|
|
221
|
+
addHook({ name: 'next', versions: ['>=13.2'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
191
222
|
const Server = nextServer.default
|
|
223
|
+
shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequestWithMatch)
|
|
224
|
+
return nextServer
|
|
225
|
+
})
|
|
192
226
|
|
|
193
|
-
|
|
227
|
+
addHook({ name: 'next', versions: ['>=11.1 <13.2'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
228
|
+
const Server = nextServer.default
|
|
194
229
|
shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequest)
|
|
195
|
-
shimmer.wrap(Server.prototype, 'renderToResponse', wrapRenderToResponse)
|
|
196
|
-
shimmer.wrap(Server.prototype, 'renderErrorToResponse', wrapRenderErrorToResponse)
|
|
197
|
-
shimmer.wrap(Server.prototype, 'findPageComponents', wrapFindPageComponents)
|
|
198
|
-
|
|
199
230
|
return nextServer
|
|
200
231
|
})
|
|
201
232
|
|
|
@@ -208,8 +239,12 @@ addHook({
|
|
|
208
239
|
|
|
209
240
|
shimmer.wrap(Server.prototype, 'handleRequest', wrapHandleRequest)
|
|
210
241
|
shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequest)
|
|
242
|
+
|
|
243
|
+
// Likewise with newer versions, these correlate to public API render methods for custom servers
|
|
244
|
+
// all public ones use these methods somewhere in their code path
|
|
211
245
|
shimmer.wrap(Server.prototype, 'renderToHTML', wrapRenderToHTML)
|
|
212
246
|
shimmer.wrap(Server.prototype, 'renderErrorToHTML', wrapRenderErrorToHTML)
|
|
247
|
+
|
|
213
248
|
shimmer.wrap(Server.prototype, 'findPageComponents', wrapFindPageComponents)
|
|
214
249
|
|
|
215
250
|
return nextServer
|
|
@@ -76,6 +76,7 @@ class HttpClientPlugin extends ClientPlugin {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
finish ({ req, res, span }) {
|
|
79
|
+
if (!span) return
|
|
79
80
|
if (res) {
|
|
80
81
|
const status = res.status || res.statusCode
|
|
81
82
|
|
|
@@ -98,6 +99,7 @@ class HttpClientPlugin extends ClientPlugin {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
error ({ span, error }) {
|
|
102
|
+
if (!span) return
|
|
101
103
|
if (error) {
|
|
102
104
|
span.addTags({
|
|
103
105
|
[ERROR_TYPE]: error.name,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { getMessageSize, CONTEXT_PROPAGATION_KEY } = require('../../dd-trace/src/datastreams/processor')
|
|
3
4
|
const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
|
|
4
5
|
|
|
5
6
|
class KafkajsConsumerPlugin extends ConsumerPlugin {
|
|
@@ -8,9 +9,10 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
|
|
|
8
9
|
|
|
9
10
|
start ({ topic, partition, message, groupId }) {
|
|
10
11
|
if (this.config.dsmEnabled) {
|
|
11
|
-
|
|
12
|
+
const payloadSize = getMessageSize(message)
|
|
13
|
+
this.tracer.decodeDataStreamsContext(message.headers[CONTEXT_PROPAGATION_KEY])
|
|
12
14
|
this.tracer
|
|
13
|
-
.setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'])
|
|
15
|
+
.setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'], payloadSize)
|
|
14
16
|
}
|
|
15
17
|
const childOf = extract(this.tracer, message.headers)
|
|
16
18
|
this.startSpan({
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
|
|
4
4
|
const { encodePathwayContext } = require('../../dd-trace/src/datastreams/pathway')
|
|
5
|
+
const { getMessageSize, CONTEXT_PROPAGATION_KEY } = require('../../dd-trace/src/datastreams/processor')
|
|
6
|
+
|
|
5
7
|
const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
|
|
6
8
|
|
|
7
9
|
class KafkajsProducerPlugin extends ProducerPlugin {
|
|
@@ -11,11 +13,6 @@ class KafkajsProducerPlugin extends ProducerPlugin {
|
|
|
11
13
|
|
|
12
14
|
start ({ topic, messages, bootstrapServers }) {
|
|
13
15
|
let pathwayCtx
|
|
14
|
-
if (this.config.dsmEnabled) {
|
|
15
|
-
const dataStreamsContext = this.tracer
|
|
16
|
-
.setCheckpoint(['direction:out', `topic:${topic}`, 'type:kafka'])
|
|
17
|
-
pathwayCtx = encodePathwayContext(dataStreamsContext)
|
|
18
|
-
}
|
|
19
16
|
const span = this.startSpan({
|
|
20
17
|
resource: topic,
|
|
21
18
|
meta: {
|
|
@@ -31,8 +28,14 @@ class KafkajsProducerPlugin extends ProducerPlugin {
|
|
|
31
28
|
}
|
|
32
29
|
for (const message of messages) {
|
|
33
30
|
if (typeof message === 'object') {
|
|
34
|
-
if (this.config.dsmEnabled) message.headers['dd-pathway-ctx'] = pathwayCtx
|
|
35
31
|
this.tracer.inject(span, 'text_map', message.headers)
|
|
32
|
+
if (this.config.dsmEnabled) {
|
|
33
|
+
const payloadSize = getMessageSize(message)
|
|
34
|
+
const dataStreamsContext = this.tracer
|
|
35
|
+
.setCheckpoint(['direction:out', `topic:${topic}`, 'type:kafka'], payloadSize)
|
|
36
|
+
pathwayCtx = encodePathwayContext(dataStreamsContext)
|
|
37
|
+
message.headers[CONTEXT_PROPAGATION_KEY] = pathwayCtx
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -43,7 +43,7 @@ class NextPlugin extends ServerPlugin {
|
|
|
43
43
|
this.addError(error, span)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
finish ({ req, res }) {
|
|
46
|
+
finish ({ req, res, nextRequest = {} }) {
|
|
47
47
|
const store = storage.getStore()
|
|
48
48
|
|
|
49
49
|
if (!store) return
|
|
@@ -52,7 +52,8 @@ class NextPlugin extends ServerPlugin {
|
|
|
52
52
|
const error = span.context()._tags['error']
|
|
53
53
|
|
|
54
54
|
if (!this.config.validateStatus(res.statusCode) && !error) {
|
|
55
|
-
span.setTag('error', true)
|
|
55
|
+
span.setTag('error', req.error || nextRequest.error || true)
|
|
56
|
+
web.addError(req, req.error || nextRequest.error || true)
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
span.addTags({
|
|
@@ -64,7 +65,7 @@ class NextPlugin extends ServerPlugin {
|
|
|
64
65
|
span.finish()
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
pageLoad ({ page, isAppPath }) {
|
|
68
|
+
pageLoad ({ page, isAppPath = false }) {
|
|
68
69
|
const store = storage.getStore()
|
|
69
70
|
|
|
70
71
|
if (!store) return
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
'COMMAND_INJECTION_ANALYZER': require('./command-injection-analyzer'),
|
|
5
|
+
'HARCODED_SECRET_ANALYZER': require('./hardcoded-secret-analyzer'),
|
|
5
6
|
'HSTS_HEADER_MISSING_ANALYZER': require('./hsts-header-missing-analyzer'),
|
|
6
7
|
'INSECURE_COOKIE_ANALYZER': require('./insecure-cookie-analyzer'),
|
|
7
8
|
'LDAP_ANALYZER': require('./ldap-injection-analyzer'),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Analyzer = require('./vulnerability-analyzer')
|
|
4
|
+
const { HARDCODED_SECRET } = require('../vulnerabilities')
|
|
5
|
+
const { getRelativePath } = require('../path-line')
|
|
6
|
+
|
|
7
|
+
const secretRules = require('./hardcoded-secrets-rules')
|
|
8
|
+
|
|
9
|
+
class HardcodedSecretAnalyzer extends Analyzer {
|
|
10
|
+
constructor () {
|
|
11
|
+
super(HARDCODED_SECRET)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
onConfigure () {
|
|
15
|
+
this.addSub('datadog:secrets:result', (secrets) => { this.analyze(secrets) })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
analyze (secrets) {
|
|
19
|
+
if (!secrets?.file || !secrets.literals) return
|
|
20
|
+
|
|
21
|
+
const matches = secrets.literals
|
|
22
|
+
.filter(literal => literal.value && literal.locations?.length)
|
|
23
|
+
.map(literal => {
|
|
24
|
+
const match = secretRules.find(rule => literal.value.match(rule.regex))
|
|
25
|
+
|
|
26
|
+
return match ? { locations: literal.locations, ruleId: match.id } : undefined
|
|
27
|
+
})
|
|
28
|
+
.filter(match => !!match)
|
|
29
|
+
|
|
30
|
+
if (matches.length) {
|
|
31
|
+
const file = getRelativePath(secrets.file)
|
|
32
|
+
|
|
33
|
+
matches.forEach(match => {
|
|
34
|
+
match.locations
|
|
35
|
+
.filter(location => location.line)
|
|
36
|
+
.forEach(location => this._report({
|
|
37
|
+
file,
|
|
38
|
+
line: location.line,
|
|
39
|
+
column: location.column,
|
|
40
|
+
data: match.ruleId
|
|
41
|
+
}))
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_getEvidence (value) {
|
|
47
|
+
return { value: `${value.data}` }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_getLocation (value) {
|
|
51
|
+
return {
|
|
52
|
+
path: value.file,
|
|
53
|
+
line: value.line,
|
|
54
|
+
column: value.column,
|
|
55
|
+
isInternal: false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = new HardcodedSecretAnalyzer()
|