Skip to content

Commit c0e5a76

Browse files
authored
support next 15.4.x on appsec (#6135)
1 parent a216c23 commit c0e5a76

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

.github/workflows/appsec.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ jobs:
219219
version:
220220
- oldest
221221
- latest
222-
range: ['>=10.2.0 <11', '>=11.0.0 <13', '11.1.4', '>=13.0.0 <14', '13.2.0', '>=14.0.0 <=14.2.6', '>=14.2.7 <15', '>=15.0.0 <15.4.1']
222+
range: ['>=10.2.0 <11', '>=11.0.0 <13', '11.1.4', '>=13.0.0 <14', '13.2.0', '>=14.0.0 <=14.2.6', '>=14.2.7 <15', '>=15.0.0']
223223
include:
224224
- range: '>=10.2.0 <11'
225225
range_clean: gte.10.2.0.and.lt.11
@@ -235,7 +235,7 @@ jobs:
235235
range_clean: gte.14.0.0.and.lte.14.2.6
236236
- range: '>=14.2.7 <15'
237237
range_clean: gte.14.2.7.and.lt.15
238-
- range: '>=15.0.0 <15.4.1'
238+
- range: '>=15.0.0'
239239
range_clean: gte.15.0.0
240240
runs-on: ubuntu-latest
241241
env:

packages/datadog-instrumentations/src/next.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ function instrument (req, res, handler, error) {
141141
requests.add(req)
142142

143143
const ctx = { req, res }
144+
// Parse query parameters from request URL
145+
if (queryParsedChannel.hasSubscribers && req.url) {
146+
// req.url is only the relative path (/foo?bar=baz) and new URL() needs a full URL
147+
// so we give it a dummy base
148+
const { searchParams } = new URL(req.url, 'http://dummy')
149+
const query = {}
150+
for (const key of searchParams.keys()) {
151+
if (!query[key]) {
152+
query[key] = searchParams.getAll(key)
153+
}
154+
}
155+
156+
queryParsedChannel.publish({ query })
157+
}
144158

145159
return startChannel.runStores(ctx, () => {
146160
try {
@@ -280,24 +294,9 @@ addHook({
280294
versions: ['>=13'],
281295
file: 'dist/server/web/spec-extension/request.js'
282296
}, request => {
283-
shimmer.wrap(request.NextRequest.prototype, 'nextUrl', function (originalGet) {
284-
return function wrappedGet () {
285-
const nextUrl = originalGet.apply(this, arguments)
286-
if (queryParsedChannel.hasSubscribers) {
287-
const query = {}
288-
for (const key of nextUrl.searchParams.keys()) {
289-
if (!query[key]) {
290-
query[key] = nextUrl.searchParams.getAll(key)
291-
}
292-
}
293-
294-
queryParsedChannel.publish({ query })
295-
}
296-
return nextUrl
297-
}
298-
})
297+
const requestProto = Object.getPrototypeOf(request.NextRequest.prototype)
299298

300-
shimmer.massWrap(request.NextRequest.prototype, ['text', 'json'], function (originalMethod) {
299+
shimmer.massWrap(requestProto, ['text', 'json'], function (originalMethod) {
301300
return async function wrappedJson () {
302301
const body = await originalMethod.apply(this, arguments)
303302

@@ -307,7 +306,7 @@ addHook({
307306
}
308307
})
309308

310-
shimmer.wrap(request.NextRequest.prototype, 'formData', function (originalFormData) {
309+
shimmer.wrap(requestProto, 'formData', function (originalFormData) {
311310
return async function wrappedFormData () {
312311
const body = await originalFormData.apply(this, arguments)
313312

packages/dd-trace/test/appsec/index.next.plugin.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('test suite', () => {
1616

1717
const satisfiesStandalone = version => satisfies(version, '>=12.0.0')
1818

19-
withVersions('next', 'next', '>=11.1 <15.4.1', version => {
19+
withVersions('next', 'next', '>=11.1', version => {
2020
if (version === '>=11.0.0 <13' && NODE_MAJOR === 24 &&
2121
NODE_MINOR === 0 && NODE_PATCH === 0) {
2222
return // node 24.0.0 fails, but 24.0.1 works

0 commit comments

Comments
 (0)