Skip to content

Commit 8cb3a50

Browse files
committed
linter
1 parent 329916f commit 8cb3a50

File tree

9 files changed

+36
-18
lines changed

9 files changed

+36
-18
lines changed

packages/datadog-instrumentations/src/fastify.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ addHook({ name: 'fastify', versions: ['1'] }, fastify => {
259259
return shimmer.wrapFunction(fastify, fastify => wrapFastify(fastify, false))
260260
})
261261

262-
263262
function wrapReplyHeader (Reply) {
264263
shimmer.wrap(Reply.prototype, 'header', header => function (key, value) {
265264
const result = header.apply(this, arguments)

packages/dd-trace/src/appsec/iast/analyzers/set-cookies-header-interceptor.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ class SetCookiesHeaderInterceptor extends Plugin {
88
super()
99
this.cookiesInRequest = new WeakMap()
1010

11-
this.addSub('datadog:http:server:response:set-header:finish', ({ name, value, res }) => this._handleCookies(name, value, res))
12-
this.addSub('datadog:fastify:set-header:finish', ({ name, value, res }) => this._handleCookies(name, value, res))
11+
this.addSub('datadog:http:server:response:set-header:finish',
12+
({ name, value, res }) => this._handleCookies(name, value, res))
13+
14+
this.addSub('datadog:fastify:set-header:finish',
15+
({ name, value, res }) => this._handleCookies(name, value, res))
1316
}
1417

1518
_handleCookies (name, value, res) {

packages/dd-trace/src/appsec/iast/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,4 @@ function onResponseWriteHeadCollect ({ res, responseHeaders = {} }) {
123123
}
124124
}
125125

126-
127126
module.exports = { enable, disable, onIncomingHttpRequestEnd, onIncomingHttpRequestStart }

packages/dd-trace/src/appsec/rasp/fs-plugin.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function enterWith (fsProps, store = storage('legacy').getStore()) {
2929

3030
class AppsecFsPlugin extends Plugin {
3131
enable () {
32-
this.addSub('apm:fs:operation:start', this._onFsOperationStart)
32+
// Use bindStore so `fs.root` is set on the ALS store before any other
33+
// subscriber for `apm:fs:operation:start` runs.
34+
// This will help to prevents a Fastify race where IAST analyzers saw `root` still undefined.
35+
this.addBind('apm:fs:operation:start', this._onFsOperationStart)
3336
this.addSub('apm:fs:operation:finish', this._onFsOperationFinishOrRenderEnd)
3437
this.addSub('tracing:datadog:express:response:render:start', this._onResponseRenderStart)
3538
this.addSub('tracing:datadog:express:response:render:end', this._onFsOperationFinishOrRenderEnd)
@@ -43,9 +46,18 @@ class AppsecFsPlugin extends Plugin {
4346

4447
_onFsOperationStart () {
4548
const store = storage('legacy').getStore()
46-
if (store) {
47-
enterWith({ root: store.fs?.root === undefined }, store)
49+
if (store && !store.fs?.opExcluded) {
50+
return {
51+
...store,
52+
fs: {
53+
...store.fs,
54+
root: store.fs?.root === undefined,
55+
parentStore: store
56+
}
57+
}
4858
}
59+
60+
return store
4961
}
5062

5163
_onResponseRenderStart () {

packages/dd-trace/test/appsec/iast/analyzers/unvalidated-redirect-analyzer.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ describe('unvalidated-redirect-analyzer', () => {
9797
unvalidatedRedirectAnalyzer.configure(true)
9898

9999
it('should subscribe to set-header:finish channel', () => {
100-
expect(unvalidatedRedirectAnalyzer._subscriptions).to.have.lengthOf(1)
100+
expect(unvalidatedRedirectAnalyzer._subscriptions).to.have.lengthOf(2)
101101
expect(unvalidatedRedirectAnalyzer._subscriptions[0]._channel.name).to
102102
.equals('datadog:http:server:response:set-header:finish')
103+
expect(unvalidatedRedirectAnalyzer._subscriptions[1]._channel.name).to
104+
.equals('datadog:fastify:set-header:finish')
103105
})
104106

105107
it('should not report headers other than Location', () => {

packages/dd-trace/test/appsec/iast/taint-tracking/plugin.fastify.plugin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { URL } = require('url')
77
function noop () {}
88

99
describe('Taint tracking plugin sources fastify tests', () => {
10-
withVersions('fastify', 'fastify', version => {
10+
withVersions('fastify', 'fastify', '>=2', version => {
1111
prepareTestServerForIastInFastify('in fastify', version,
1212
(testThatRequestHasVulnerability, _, config) => {
1313
describe('tainted body', () => {

packages/dd-trace/test/appsec/iast/taint-tracking/plugin.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('IAST Taint tracking plugin', () => {
4949
})
5050

5151
it('Should subscribe to body parser, qs, cookie and process_params channel', () => {
52-
expect(taintTrackingPlugin._subscriptions).to.have.lengthOf(16)
52+
expect(taintTrackingPlugin._subscriptions).to.have.lengthOf(17)
5353
let i = 0
5454
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:body-parser:read:finish')
5555
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:multer:read:finish')
@@ -59,11 +59,12 @@ describe('IAST Taint tracking plugin', () => {
5959
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:fastify:query-params:finish')
6060
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:express:query:finish')
6161
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:cookie:parse:finish')
62+
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:fastify-cookie:read:finish')
6263
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:sequelize:query:finish')
6364
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('apm:pg:query:finish')
6465
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:express:process_params:start')
65-
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:fastify:path-params:finish')
6666
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:router:param:start')
67+
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:fastify:path-params:finish')
6768
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('apm:graphql:resolve:start')
6869
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:url:parse:finish')
6970
expect(taintTrackingPlugin._subscriptions[i++]._channel.name).to.equals('datadog:url:getter:finish')

packages/dd-trace/test/appsec/iast/taint-tracking/sources/taint-tracking.fastify.plugin.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ describe('Path params sourcing with fastify', () => {
122122
reply.code(200).send()
123123
})
124124

125-
126125
await appInstance.listen({ port: 0 })
127126

128127
const port = appInstance.server.address().port
@@ -132,4 +131,4 @@ describe('Path params sourcing with fastify', () => {
132131
expect(response.status).to.be.equal(200)
133132
})
134133
})
135-
})
134+
})

packages/dd-trace/test/appsec/rasp/fs-plugin.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('AppsecFsPlugin', () => {
2828
configure = sinon.stub()
2929
class PluginClass {
3030
addSub (channelName, handler) {}
31+
addBind (channelName, transform) {}
3132

3233
configure (config) {
3334
configure(config)
@@ -97,7 +98,8 @@ describe('AppsecFsPlugin', () => {
9798
const origStore = {}
9899
storage('legacy').enterWith(origStore)
99100

100-
appsecFsPlugin._onFsOperationStart()
101+
const newStore = appsecFsPlugin._onFsOperationStart()
102+
storage('legacy').enterWith(newStore)
101103

102104
let store = storage('legacy').getStore()
103105
assert.property(store, 'fs')
@@ -115,16 +117,17 @@ describe('AppsecFsPlugin', () => {
115117
const origStore = { orig: true }
116118
storage('legacy').enterWith(origStore)
117119

118-
appsecFsPlugin._onFsOperationStart()
120+
const rootStore = appsecFsPlugin._onFsOperationStart()
121+
storage('legacy').enterWith(rootStore)
119122

120-
const rootStore = storage('legacy').getStore()
121123
assert.property(rootStore, 'fs')
122124
assert.propertyVal(rootStore.fs, 'parentStore', origStore)
123125
assert.propertyVal(rootStore.fs, 'root', true)
124126

125-
appsecFsPlugin._onFsOperationStart()
127+
const childStore = appsecFsPlugin._onFsOperationStart()
128+
storage('legacy').enterWith(childStore)
126129

127-
let store = storage('legacy').getStore()
130+
let store = childStore
128131
assert.property(store, 'fs')
129132
assert.propertyVal(store.fs, 'parentStore', rootStore)
130133
assert.propertyVal(store.fs, 'root', false)

0 commit comments

Comments
 (0)