dd-trace 6.0.0-pre-1106f0c → 6.0.0-pre-c879030

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.0.0-pre-1106f0c",
3
+ "version": "6.0.0-pre-c879030",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -1,51 +1,12 @@
1
1
  'use strict'
2
2
 
3
3
  const shimmer = require('../../datadog-shimmer')
4
- const { channel } = require('./helpers/instrument')
5
-
6
- const startChannel = channel('apm:fetch:request:start')
7
- const finishChannel = channel('apm:fetch:request:finish')
8
- const errorChannel = channel('apm:fetch:request:error')
9
-
10
- function wrapFetch (fetch, Request) {
11
- if (typeof fetch !== 'function') return fetch
12
-
13
- return function (input, init) {
14
- if (!startChannel.hasSubscribers) return fetch.apply(this, arguments)
15
-
16
- const req = new Request(input, init)
17
- const headers = req.headers
18
- const message = { req, headers }
19
-
20
- return startChannel.runStores(message, () => {
21
- // Request object is read-only so we need new objects to change headers.
22
- arguments[0] = message.req
23
- arguments[1] = { headers: message.headers }
24
-
25
- return fetch.apply(this, arguments)
26
- .then(
27
- res => {
28
- message.res = res
29
-
30
- finishChannel.publish(message)
31
-
32
- return res
33
- },
34
- err => {
35
- if (err.name !== 'AbortError') {
36
- message.error = err
37
- errorChannel.publish(message)
38
- }
39
-
40
- finishChannel.publish(message)
41
-
42
- throw err
43
- }
44
- )
45
- })
46
- }
47
- }
4
+ const { tracingChannel } = require('dc-polyfill')
5
+ const { createWrapFetch } = require('./helpers/fetch')
48
6
 
49
7
  if (globalThis.fetch) {
50
- globalThis.fetch = shimmer.wrap(fetch, wrapFetch(fetch, globalThis.Request))
8
+ const ch = tracingChannel('apm:fetch:request')
9
+ const wrapFetch = createWrapFetch(globalThis.Request, ch)
10
+
11
+ globalThis.fetch = shimmer.wrap(fetch, wrapFetch(fetch))
51
12
  }
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ exports.createWrapFetch = function createWrapFetch (Request, ch) {
4
+ return function wrapFetch (fetch) {
5
+ if (typeof fetch !== 'function') return fetch
6
+
7
+ return function (input, init) {
8
+ if (!ch.start.hasSubscribers) return fetch.apply(this, arguments)
9
+
10
+ const req = new Request(input, init)
11
+ const headers = req.headers
12
+ const ctx = { req, headers }
13
+
14
+ return ch.tracePromise(() => fetch.call(this, req, { headers: ctx.headers }), ctx)
15
+ }
16
+ }
17
+ }
@@ -338,7 +338,7 @@ function applySuiteSkipping (originalTests, rootDir, frameworkVersion) {
338
338
  numSkippedSuites = jestSuitesToRun.skippedSuites.length
339
339
 
340
340
  itrSkippedSuitesCh.publish({ skippedSuites: jestSuitesToRun.skippedSuites, frameworkVersion })
341
- skippableSuites = []
341
+
342
342
  return jestSuitesToRun.suitesToRun
343
343
  }
344
344
 
@@ -4,28 +4,34 @@ const HttpClientPlugin = require('../../datadog-plugin-http/src/client')
4
4
 
5
5
  class FetchPlugin extends HttpClientPlugin {
6
6
  static get id () { return 'fetch' }
7
- static get prefix () { return 'apm:fetch:request' }
7
+ static get prefix () { return 'tracing:apm:fetch:request' }
8
8
 
9
- addTraceSub (eventName, handler) {
10
- this.addSub(`apm:${this.constructor.id}:${this.operation}:${eventName}`, handler)
11
- }
12
-
13
- bindStart (message) {
14
- const req = message.req
9
+ bindStart (ctx) {
10
+ const req = ctx.req
15
11
  const options = new URL(req.url)
16
12
  const headers = options.headers = Object.fromEntries(req.headers.entries())
17
13
 
18
14
  options.method = req.method
19
15
 
20
- message.args = { options }
16
+ ctx.args = { options }
21
17
 
22
- const store = super.bindStart(message)
18
+ const store = super.bindStart(ctx)
23
19
 
24
- message.headers = headers
25
- message.req = new globalThis.Request(req, { headers })
20
+ ctx.headers = headers
21
+ ctx.req = new globalThis.Request(req, { headers })
26
22
 
27
23
  return store
28
24
  }
25
+
26
+ error (ctx) {
27
+ if (ctx.error.name === 'AbortError') return
28
+ return super.error(ctx)
29
+ }
30
+
31
+ asyncEnd (ctx) {
32
+ ctx.res = ctx.result
33
+ return this.finish(ctx)
34
+ }
29
35
  }
30
36
 
31
37
  module.exports = FetchPlugin
@@ -2,6 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  COMMAND_INJECTION_ANALYZER: require('./command-injection-analyzer'),
5
+ HARCODED_PASSWORD_ANALYZER: require('./hardcoded-password-analyzer'),
5
6
  HARCODED_SECRET_ANALYZER: require('./hardcoded-secret-analyzer'),
6
7
  HEADER_INJECTION_ANALYZER: require('./header-injection-analyzer'),
7
8
  HSTS_HEADER_MISSING_ANALYZER: require('./hsts-header-missing-analyzer'),
@@ -0,0 +1,70 @@
1
+ 'use strict'
2
+
3
+ const Analyzer = require('./vulnerability-analyzer')
4
+ const { getRelativePath } = require('../path-line')
5
+
6
+ class HardcodedBaseAnalyzer extends Analyzer {
7
+ constructor (type, allRules = [], valueOnlyRules = []) {
8
+ super(type)
9
+
10
+ this.allRules = allRules
11
+ this.valueOnlyRules = valueOnlyRules
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 { allRules, valueOnlyRules } = this
22
+
23
+ const matches = []
24
+ for (const literal of secrets.literals) {
25
+ const { value, locations } = literal
26
+ if (!value || !locations) continue
27
+
28
+ for (const location of locations) {
29
+ let match
30
+ if (location.ident) {
31
+ const fullValue = `${location.ident}=${value}`
32
+ match = allRules.find(rule => fullValue.match(rule.regex))
33
+ } else {
34
+ match = valueOnlyRules.find(rule => value.match(rule.regex))
35
+ }
36
+
37
+ if (match) {
38
+ matches.push({ location, ruleId: match.id })
39
+ }
40
+ }
41
+ }
42
+
43
+ if (matches.length) {
44
+ const file = getRelativePath(secrets.file)
45
+
46
+ matches
47
+ .forEach(match => this._report({
48
+ file,
49
+ line: match.location.line,
50
+ column: match.location.column,
51
+ data: match.ruleId
52
+ }))
53
+ }
54
+ }
55
+
56
+ _getEvidence (value) {
57
+ return { value: `${value.data}` }
58
+ }
59
+
60
+ _getLocation (value) {
61
+ return {
62
+ path: value.file,
63
+ line: value.line,
64
+ column: value.column,
65
+ isInternal: false
66
+ }
67
+ }
68
+ }
69
+
70
+ module.exports = HardcodedBaseAnalyzer
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const { HARDCODED_PASSWORD } = require('../vulnerabilities')
4
+ const HardcodedBaseAnalyzer = require('./hardcoded-base-analyzer')
5
+
6
+ const allRules = require('./hardcoded-password-rules')
7
+
8
+ class HardcodedPasswordAnalyzer extends HardcodedBaseAnalyzer {
9
+ constructor () {
10
+ super(HARDCODED_PASSWORD, allRules)
11
+ }
12
+ }
13
+
14
+ module.exports = new HardcodedPasswordAnalyzer()
@@ -0,0 +1,12 @@
1
+ /* eslint-disable max-len */
2
+ 'use strict'
3
+
4
+ const { NameAndValue } = require('./hardcoded-rule-type')
5
+
6
+ module.exports = [
7
+ {
8
+ id: 'hardcoded-password',
9
+ regex: /(?:pwd|pswd|pass|secret)(?:[0-9a-z\-_\t.]{0,20})(?:[\s|']|[\s|""]){0,3}(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|""|\s|=|\x60){0,5}([0-9a-z\-_.=]{10,150})(?:['"\s\x60;]|$)/i,
10
+ type: NameAndValue
11
+ }
12
+ ]
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ ValueOnly: 'ValueOnly',
5
+ NameAndValue: 'NameAndValue'
6
+ }
@@ -1,59 +1,14 @@
1
1
  'use strict'
2
2
 
3
- const Analyzer = require('./vulnerability-analyzer')
4
3
  const { HARDCODED_SECRET } = require('../vulnerabilities')
5
- const { getRelativePath } = require('../path-line')
4
+ const HardcodedBaseAnalyzer = require('./hardcoded-base-analyzer')
5
+ const { ValueOnly } = require('./hardcoded-rule-type')
6
6
 
7
- const secretRules = require('./hardcoded-secrets-rules')
7
+ const allRules = require('./hardcoded-secret-rules')
8
8
 
9
- class HardcodedSecretAnalyzer extends Analyzer {
9
+ class HardcodedSecretAnalyzer extends HardcodedBaseAnalyzer {
10
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
- }
11
+ super(HARDCODED_SECRET, allRules, allRules.filter(rule => rule.type === ValueOnly))
57
12
  }
58
13
  }
59
14