Skip to content

Commit

Permalink
Unsubscribe NextJS body and query channels on appsec disable (#4776)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlesDD authored Oct 14, 2024
1 parent c085df1 commit f62cbfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/dd-trace/src/appsec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ function disable () {
if (incomingHttpRequestStart.hasSubscribers) incomingHttpRequestStart.unsubscribe(incomingHttpStartTranslator)
if (incomingHttpRequestEnd.hasSubscribers) incomingHttpRequestEnd.unsubscribe(incomingHttpEndTranslator)
if (queryParser.hasSubscribers) queryParser.unsubscribe(onRequestQueryParsed)
if (nextBodyParsed.hasSubscribers) nextBodyParsed.unsubscribe(onRequestBodyParsed)
if (nextQueryParsed.hasSubscribers) nextQueryParsed.unsubscribe(onRequestQueryParsed)
if (cookieParser.hasSubscribers) cookieParser.unsubscribe(onRequestCookieParser)
if (responseBody.hasSubscribers) responseBody.unsubscribe(onResponseBody)
if (passportVerify.hasSubscribers) passportVerify.unsubscribe(onPassportVerify)
Expand Down
8 changes: 8 additions & 0 deletions packages/dd-trace/test/appsec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const {
incomingHttpRequestStart,
incomingHttpRequestEnd,
queryParser,
nextBodyParsed,
nextQueryParsed,
passportVerify,
responseBody,
responseWriteHead,
Expand Down Expand Up @@ -168,6 +170,8 @@ describe('AppSec Index', function () {
expect(bodyParser.hasSubscribers).to.be.false
expect(cookieParser.hasSubscribers).to.be.false
expect(queryParser.hasSubscribers).to.be.false
expect(nextBodyParsed.hasSubscribers).to.be.false
expect(nextQueryParsed.hasSubscribers).to.be.false
expect(passportVerify.hasSubscribers).to.be.false
expect(responseWriteHead.hasSubscribers).to.be.false
expect(responseSetHeader.hasSubscribers).to.be.false
Expand All @@ -177,6 +181,8 @@ describe('AppSec Index', function () {
expect(bodyParser.hasSubscribers).to.be.true
expect(cookieParser.hasSubscribers).to.be.true
expect(queryParser.hasSubscribers).to.be.true
expect(nextBodyParsed.hasSubscribers).to.be.true
expect(nextQueryParsed.hasSubscribers).to.be.true
expect(passportVerify.hasSubscribers).to.be.true
expect(responseWriteHead.hasSubscribers).to.be.true
expect(responseSetHeader.hasSubscribers).to.be.true
Expand Down Expand Up @@ -255,6 +261,8 @@ describe('AppSec Index', function () {
expect(bodyParser.hasSubscribers).to.be.false
expect(cookieParser.hasSubscribers).to.be.false
expect(queryParser.hasSubscribers).to.be.false
expect(nextBodyParsed.hasSubscribers).to.be.false
expect(nextQueryParsed.hasSubscribers).to.be.false
expect(passportVerify.hasSubscribers).to.be.false
expect(responseWriteHead.hasSubscribers).to.be.false
expect(responseSetHeader.hasSubscribers).to.be.false
Expand Down

0 comments on commit f62cbfa

Please sign in to comment.