@contrast/route-coverage 1.50.0 → 1.52.0

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.
@@ -1,157 +0,0 @@
1
- /*
2
- * Copyright: 2025 Contrast Security, Inc
3
- * Contact: support@contrastsecurity.com
4
- * License: Commercial
5
-
6
- * NOTICE: This Software and the patented inventions embodied within may only be
7
- * used as part of Contrast Security’s commercial offerings. Even though it is
8
- * made available through public repositories, use of this Software is subject to
9
- * the applicable End User Licensing Agreement found at
10
- * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
- * between Contrast Security and the End User. The Software may not be reverse
12
- * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
- * way not consistent with the End User License Agreement.
14
- */
15
- 'use strict';
16
-
17
- const METHODS = [
18
- 'all',
19
- 'get',
20
- 'post',
21
- 'put',
22
- 'delete',
23
- 'patch',
24
- 'options',
25
- 'head',
26
- ];
27
-
28
- const fnInspect = require('@contrast/fn-inspect');
29
- const { createSignature, patchType } = require('../../utils/route-info');
30
- const { isString, primordials: { ArrayPrototypeJoin, StringPrototypeToLowerCase, StringPrototypeReplace, StringPrototypeReplaceAll, StringPrototypeSplit, StringPrototypeSlice } } = require('@contrast/common');
31
-
32
- // Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Express
33
- module.exports = function init(core) {
34
- const { patcher, depHooks, routeCoverage } = core;
35
- const discover = (route) => routeCoverage.discover(route);
36
- const observe = (route) => routeCoverage.observe(route);
37
-
38
- const isRoute = (layer) => !!layer.route;
39
- const isRouter = (layer) => layer.name && StringPrototypeToLowerCase.call(layer.name) === 'router';
40
- const isValidPath = (path) => isString(path) || Array.isArray(path) || path instanceof RegExp;
41
- const getHandleMethod = (layer) => fnInspect.funcInfo(layer.__handle)?.file.includes('express-async-errors') ? '__handle' : 'handle';
42
- const getLastLayer = (router) => router?.stack[router.stack.length - 1];
43
-
44
- function regExpToPath(regex) {
45
- if (regex.source) {
46
- let [path] = StringPrototypeSplit.call(regex?.source, '/?');
47
- path = StringPrototypeReplaceAll.call(path, '\\', '');
48
- path = StringPrototypeReplace.call(path, '^', '');
49
- return path;
50
- }
51
- }
52
-
53
- function format(url) {
54
- if (Array.isArray(url)) {
55
- return `/[${ArrayPrototypeJoin.call(url)}]`;
56
- } else if (url instanceof RegExp) {
57
- return `/{${StringPrototypeSlice.call(url.toString(), 1, -1)}}`;
58
- } else {
59
- return url;
60
- }
61
- }
62
-
63
- function parseRoute(route) {
64
- const { path } = route;
65
- const method = route.methods._all ? 'all' : route.stack[0].method;
66
- return { url: format(path), method };
67
- }
68
-
69
-
70
- function createRouteInfo(url, method, obj) {
71
- return {
72
- signature: createSignature(url, method, obj),
73
- url,
74
- normalizedUrl: url,
75
- method,
76
- framework: 'express'
77
- };
78
- }
79
-
80
- function patchHandle(layer, routeInfo) {
81
- const handle = getHandleMethod(layer);
82
- patcher.patch(layer, handle, {
83
- name: 'express.Route.handle',
84
- patchType,
85
- post({ args }) {
86
- const [req] = args;
87
- const [url] = StringPrototypeSplit.call(req.originalUrl, '?');
88
- const { method } = req;
89
- if (url && method) {
90
- observe({ ...routeInfo, url, method: StringPrototypeToLowerCase.call(method) });
91
- }
92
- }
93
- });
94
- }
95
-
96
- function traverse(stack, path = '', depth = 0) {
97
- path = format(path);
98
- stack.forEach((layer) => {
99
- if (isRoute(layer)) {
100
- const { url, method } = parseRoute(layer.route);
101
- const routeInfo = createRouteInfo(path + url, method);
102
- discover(routeInfo);
103
- patchHandle(layer, routeInfo);
104
- } else if (isRouter(layer)) {
105
- const regexPath = regExpToPath(layer.regexp);
106
- if (depth < 3) traverse(layer.handle.stack, path + regexPath, depth += 1);
107
- } else {
108
- const regexPath = regExpToPath(layer.regexp);
109
- const routeInfo = createRouteInfo(path + regexPath, 'use');
110
- discover(routeInfo);
111
- patchHandle(layer, routeInfo);
112
- }
113
- });
114
- }
115
- return core.routeCoverage.express4 = {
116
- install() {
117
- depHooks.resolve({ name: 'express', version: '>=4 <5' }, (express) => {
118
- patcher.patch(express.application, 'use', {
119
- name: 'express.application.use',
120
- patchType,
121
- post({ args, result }) {
122
- const len = args.length;
123
- const fn = args[len - 1];
124
- const path = len > 1 ? args[0] : undefined;
125
- if (path && !isValidPath(path)) return;
126
- const handlers = Array.isArray(fn) ? fn : [fn];
127
- handlers.forEach((layer) => {
128
- if (isRouter(layer)) {
129
- traverse(layer.stack, path);
130
- } else if (path) {
131
- const routeInfo = createRouteInfo(format(path), 'use', 'App');
132
- discover(routeInfo);
133
- const lastLayer = getLastLayer(result._router);
134
- if (lastLayer) patchHandle(lastLayer, routeInfo);
135
- }
136
- });
137
- }
138
- });
139
-
140
- METHODS.forEach((method) => {
141
- patcher.patch(express.application, method, {
142
- name: `express.application.${method}`,
143
- patchType,
144
- post({ args, result }) {
145
- const [url, fn] = args;
146
- if (!url || !fn || !isValidPath(url)) return;
147
- const routeInfo = createRouteInfo(format(url), method, 'App');
148
- discover(routeInfo);
149
- const lastLayer = getLastLayer(result._router);
150
- if (lastLayer) patchHandle(lastLayer, routeInfo);
151
- }
152
- });
153
- });
154
- });
155
- }
156
- };
157
- };
@@ -1,538 +0,0 @@
1
- /*
2
- * Copyright: 2025 Contrast Security, Inc
3
- * Contact: support@contrastsecurity.com
4
- * License: Commercial
5
-
6
- * NOTICE: This Software and the patented inventions embodied within may only be
7
- * used as part of Contrast Security’s commercial offerings. Even though it is
8
- * made available through public repositories, use of this Software is subject to
9
- * the applicable End User Licensing Agreement found at
10
- * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
- * between Contrast Security and the End User. The Software may not be reverse
12
- * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
- * way not consistent with the End User License Agreement.
14
- */
15
- 'use strict';
16
-
17
- const { AsyncLocalStorage } = require('node:async_hooks');
18
- const {
19
- get,
20
- set,
21
- isString,
22
- Event,
23
- primordials: {
24
- ArrayPrototypeJoin,
25
- StringPrototypeSubstring,
26
- StringPrototypeToLowerCase,
27
- StringPrototypeReplace,
28
- }
29
- } = require('@contrast/common');
30
- const { funcInfo } = require('@contrast/fn-inspect');
31
- const Core = require('@contrast/core/lib/ioc/core');
32
-
33
- const METHODS = [
34
- 'all',
35
- 'get',
36
- 'post',
37
- 'put',
38
- 'delete',
39
- 'patch',
40
- 'options',
41
- 'head',
42
- ];
43
- const componentName = 'routeCoverage.express5';
44
- const kMetaKey = Symbol('cs_meta');
45
- const enumerable = false;
46
-
47
- module.exports = Core.makeComponent({
48
- name: componentName,
49
- factory: (core) => new ExpressInstrumentation(core),
50
- });
51
-
52
- class ExpressInstrumentation {
53
- constructor(core) {
54
- // decorate
55
- set(core, componentName, this);
56
-
57
- this.core = core;
58
- this.methodScope = new AsyncLocalStorage();
59
- this.handleScope = new AsyncLocalStorage();
60
- }
61
-
62
- install() {
63
- const self = this;
64
- const { core, handleScope, methodScope } = this;
65
- const patchType = 'route-coverage-express';
66
- const name = 'express-5';
67
-
68
- //
69
- // discovery instrumentation
70
- //
71
-
72
- core.depHooks.resolve({ name: 'express', version: '5' }, (express) => {
73
- // wrap router and app methods in "method scope" to capture info to help build signatures.
74
- // express has a number of APIs that work at different levels of abstraction, and we need to patch
75
- // all of them. the scopes let us know what top-level APIs are being called by application code.
76
- [...METHODS, 'use', 'route'].forEach((method) => {
77
- // then setup app and router to run in method scopes
78
- core.patcher.patch(express.application, method, {
79
- name: `express.application.${method}`,
80
- patchType: `${patchType}-discovery`,
81
- around(next, data) {
82
- if (methodScope.getStore()) return next();
83
- return methodScope.run({ method, args: data.args, type: 'app' }, next);
84
- }
85
- });
86
-
87
- core.patcher.patch(express.Router.prototype, method, {
88
- name: `express.Router.prototype.${method}`,
89
- patchType: `${patchType}-discovery`,
90
- around(next, data) {
91
- if (methodScope.getStore()) return next();
92
- return methodScope.run({ method, args: data.args, type: 'router' }, next);
93
- }
94
- });
95
- });
96
-
97
- // app[method] and router[method] end up calling this
98
- // Append metadata to the created Route object at layer.route.
99
- // we also patch the returned Route's methods for building signatures
100
- core.patcher.patch(express.Router.prototype, 'route', {
101
- name: 'express.Route',
102
- patchType: `${patchType}-discovery`,
103
- post(data) {
104
- const { result } = data;
105
- const methodStore = methodScope.getStore();
106
- const meta = {
107
- paths: ExpressInstrumentation.normalizePaths(data.args[0]),
108
- method: methodStore?.method,
109
- type: methodStore?.type || 'route',
110
- };
111
-
112
- Object.defineProperty(result, kMetaKey, {
113
- enumerable,
114
- value: meta
115
- });
116
-
117
- // patch route instance methods we do that here when we have
118
- // todo move to prototype to help w/ memory
119
- METHODS.forEach((method) => {
120
- if (result[method]) {
121
- core.patcher.patch(result, method, {
122
- name: `express.Router.prototype.route${method}`,
123
- patchType: `${patchType}-discovery`,
124
- pre(data) {
125
- data._stackIdx = data.obj.stack?.length;
126
- },
127
- post(data) {
128
- if (data.obj.stack?.length > data._stackIdx) {
129
- for (let i = data._stackIdx; i < data.obj.stack.length; i++) {
130
- const layer = data.obj.stack[i];
131
- const methodStore = methodScope.getStore();
132
- const meta = {
133
- type: methodStore?.type || 'route',
134
- method: methodStore?.method == 'all' ? 'all' : method,
135
- };
136
-
137
- Object.defineProperty(layer, kMetaKey, {
138
- enumerable,
139
- value: meta,
140
- });
141
- }
142
- }
143
- },
144
- });
145
- }
146
- });
147
-
148
- return result;
149
- },
150
- });
151
-
152
- core.patcher.patch(express.Router.prototype, 'use', {
153
- name: `${name}.Router.prototype.use`,
154
- patchType: `${patchType}-discovery`,
155
- pre(data) {
156
- data._stackLength = data.obj.stack?.length;
157
- },
158
- post(data) {
159
- if (data.obj.stack.length > data._stackLength) {
160
- for (let i = data._stackLength; i < data.obj.stack.length; i++) {
161
- const layer = data.obj.stack[i];
162
- const paths = ExpressInstrumentation.normalizePaths(data.args[0]);
163
- const methodStore = methodScope.getStore();
164
- const meta = {
165
- paths,
166
- method: 'use',
167
- type: methodStore?.type || 'router',
168
- };
169
-
170
- if (layer) {
171
- Object.defineProperty(layer, kMetaKey, {
172
- enumerable: false,
173
- value: meta
174
- });
175
- }
176
- }
177
- }
178
- },
179
- });
180
-
181
- return core.patcher.patch(express, {
182
- name: 'express-5.application',
183
- patchType: `${patchType}-discovery`,
184
- post(data) {
185
- const app = data.result;
186
- core.messages.on(Event.SERVER_LISTENING, () => {
187
- if (!app.router.stack[0]) {
188
- core.logger.debug('no routes detected in express router stack');
189
- return;
190
- }
191
- self.handleDiscovery(app);
192
- });
193
- return app;
194
- }
195
- });
196
- });
197
-
198
- core.depHooks.resolve({ name: 'express', version: '5' }, (express) => {
199
- core.patcher.patch(express.application, 'handle', {
200
- name: 'express.application.handle',
201
- patchType: `${patchType}-discovery`,
202
- around(next, data) {
203
- // wrap request handling in "handle scope". the scope's store data
204
- // helps for building observation templates as routing occurs
205
- const store = {
206
- matchIdx: -1,
207
- templateSegments: [],
208
- };
209
- return handleScope.run(store, next);
210
- }
211
- });
212
- });
213
-
214
- //
215
- // observation instrumentation
216
- //
217
-
218
- // when Layer.match gets called, matchers functions run underneath. the API doesn't present a really clean
219
- // way to instrument, so we're using scopes. we reference the scope's store in the instrumented matcher
220
- // functions so we can correlate a matcher that succeeds to its corresponding route template segment.
221
- core.depHooks.resolve({ name: 'router', file: 'lib/layer.js', version: '2' }, (Layer) => {
222
- core.patcher.patch(Layer.prototype, 'match', {
223
- name: 'Layer.prototype.match',
224
- patchType: `${patchType}-observation`,
225
- pre(data) {
226
- data._store = handleScope.getStore();
227
- if (!data._store) return;
228
-
229
- // we check in post hook whether any matcher instrumentation reset this in scope.
230
- // matchers will set this to a number only if multiple matchers run and one succeeds.
231
- // use the index of that matcher to get associated template segment from the metadata.
232
- data._store.matcherIdx = null;
233
- // save reference to metadata source
234
- data[kMetaKey] = data.obj[kMetaKey] || data.obj.route?.[kMetaKey];
235
- },
236
- post(data) {
237
- // whenever a layer matches, save the corresponding
238
- // template segment metadata in the handle scope store
239
- const { result } = data;
240
- if (!result || !data._store || !data[kMetaKey]?.paths) return;
241
-
242
- let template;
243
- if (data._store.matcherIdx != null) {
244
- template = data[kMetaKey].paths[data._store.matcherIdx];
245
- } else {
246
- template = data[kMetaKey].paths[0];
247
- }
248
-
249
- // if the layer matches, we know to push corresponding path to store's template segments.
250
- // we pop this value from the array in hook to all `next` callbacks below.
251
- data._store.templateSegments.push(template);
252
- }
253
- });
254
-
255
- // patch the `next` callback of every Layer's request handler.
256
- // we pop the value from the stack of route template segments being managed.
257
- core.patcher.patch(Layer.prototype, 'handleRequest', {
258
- name: 'Layer.prototype.handleRequest',
259
- patchType: `${patchType}-observation`,
260
- pre(data) {
261
- const next = data.args[2];
262
- const meta = data.obj[kMetaKey] || data.obj.route?.[kMetaKey];
263
- if (meta?.paths) {
264
- const store = handleScope.getStore();
265
- // this runs often and there's no need to use patcher here. monkey patch directly to optimize
266
- data.args[2] = function(...args) {
267
- if (store) store.templateSegments.pop();
268
- const ret = next(...args);
269
- return ret;
270
- };
271
- }
272
- }
273
- });
274
-
275
- // instrument the Layer constructor. this will allow us to patch
276
- // created matchers to help us build observation template from metadata.
277
- // if matcher was successful we store index of it in handle scope.
278
- return core.patcher.patch(Layer, {
279
- name: 'router.Layer',
280
- patchType: `${patchType}-observation`,
281
- pre(data) {
282
- data._methodScope = methodScope.getStore();
283
- },
284
- post(data) {
285
- const instance = data.result;
286
- // only instrument matchers if the Layer is being instantiated within method scope, and
287
- // if there are multiple matchers and we need the index to correlate to tempate segment
288
- if (data._methodScope && instance.matchers.length > 1) {
289
- for (let i = 0; i < instance.matchers.length; i++) {
290
- const matcher = instance.matchers[i];
291
- instance.matchers[i] = function(...args) {
292
- const result = matcher.apply(this, args);
293
- if (result) {
294
- const store = handleScope.getStore();
295
- if (store) store.matcherIdx = i;
296
- }
297
- return result;
298
- };
299
- }
300
- }
301
- // patch handle to report observation when called. it checks handle
302
- // scope to get current request's template to match with discovery info
303
- core.patcher.patch(instance, 'handle', {
304
- name: 'router.Layer.handle',
305
- patchType: `${patchType}-observation`,
306
- pre(data) {
307
- if (instance[kMetaKey]?.observables) {
308
- const store = handleScope.getStore();
309
- if (store) {
310
- const method = StringPrototypeToLowerCase.call(data.args[0].method || '');
311
- const template = ArrayPrototypeJoin.call(store.templateSegments, '') || '/';
312
-
313
- if (instance[kMetaKey]?.observables?.[template]) {
314
- self.observe({
315
- url: data.args[0].originalUrl,
316
- normalizedUrl: template,
317
- method,
318
- signature: instance[kMetaKey].observables[template],
319
- });
320
- } else {
321
- core.logger.error({
322
- // url: data.args[0].originalUrl, // this would need masking to log
323
- method,
324
- template,
325
- observables: instance[kMetaKey]?.observables,
326
- }, 'unable to map route template to signature');
327
- }
328
- }
329
- }
330
- },
331
- });
332
- },
333
- });
334
- });
335
- }
336
-
337
- discover(info) {
338
- const { method, observables } = info;
339
- if (!method || !observables) return;
340
-
341
- for (const [normalizedUrl, signature] of Object.entries(observables)) {
342
- this.core.routeCoverage.discover({
343
- url: normalizedUrl,
344
- normalizedUrl,
345
- method,
346
- signature,
347
- framework: 'express',
348
- });
349
- }
350
- }
351
-
352
- observe(info) {
353
- this.core.routeCoverage.observe({ framework: 'express', ...info });
354
- }
355
-
356
- /**
357
- * Traverse the application's router "stack" and generate route discovery events
358
- * using layer/route metadata that was appended by methods like router.post().
359
- * @param {object} app express instance
360
- */
361
- handleDiscovery(app) {
362
- const self = this;
363
- const router = app.router || app._router;
364
-
365
- // traverse fn executes this callback when visiting Layer instances
366
- this.traverse(router, (path, key, value, target, state) => {
367
- if (value.stack?.length > 0 || value.route) return;
368
-
369
- // get metadata for this Layer
370
- // metadata is on Layers within stacks and on Routes instances.
371
- const metas = [];
372
- for (let i = 0; i < path.length; i++) {
373
- const seg = path[i];
374
- if (Number.isFinite((Number(seg))) || seg == 'route') {
375
- const metaPath = ArrayPrototypeJoin.call(path.slice(0, i + 1), '.');
376
- const layerOrRoute = get(router, metaPath);
377
- if (layerOrRoute?.[kMetaKey]) {
378
- metas.push(layerOrRoute[kMetaKey]);
379
- }
380
- }
381
- }
382
-
383
- // mounted routers aren't discoverable since they themselves don't
384
- // represent routes, they dispatch to sub routers/route handlers.
385
- if (value.name != 'router' && value.handle?.name != 'router') {
386
- // `value` is a terminal Layer with observable signatures.
387
- // emit discovery after appending metadata.
388
- if (value[kMetaKey]) {
389
- const observables = this.generateObservables(metas, value.handle);
390
- if (observables) {
391
- if (!value[kMetaKey].observables) {
392
- value[kMetaKey].observables = observables;
393
- } else {
394
- Object.assign(value[kMetaKey].observables, observables);
395
- }
396
- }
397
- self.discover(value[kMetaKey]);
398
- }
399
- }
400
- });
401
- }
402
-
403
- /**
404
- * Traverses the top-level app's routing stack and executes the provided callback when
405
- * visiting nodes. The callback is invoked only to visit Layer instances, objects and
406
- * functions, since these are the only 2 types that could have our metadata attached.
407
- */
408
- traverse(target, cb, path = [], data = new Map()) {
409
- loopKeys: for (const key in target) {
410
- path.push(key);
411
-
412
- // only visit Layer instances
413
- const maybeLayer = target[key];
414
- if (
415
- maybeLayer?.constructor?.name == 'Layer' &&
416
- !maybeLayer?.stack?.length
417
- ) {
418
- let _data = data.get(maybeLayer);
419
-
420
- if (!_data) {
421
- _data = { paths: [] };
422
- data.set(maybeLayer, _data);
423
- }
424
-
425
- // you can mount a router on itself
426
- // prevent infinitely recursing into self-mounted routers
427
- for (const visitedPath of _data.paths) {
428
- // these conditions indicate recursive nesting at particular path
429
- if (
430
- path.length > visitedPath.length &&
431
- visitedPath.every((el, i) => path[i] == el)
432
- ) {
433
- path.pop();
434
- continue loopKeys;
435
- }
436
- }
437
-
438
- _data.paths.push([...path]); // copy because path argument mutates
439
-
440
- const halt = cb(path, key, maybeLayer, target) === false;
441
- if (halt) return;
442
- }
443
-
444
- // might be able to fine-tune this a bit more
445
- if (typeof maybeLayer == 'object' || typeof maybeLayer == 'function') {
446
- this.traverse(maybeLayer, cb, path, data);
447
- }
448
-
449
- path.pop();
450
- }
451
- }
452
-
453
- generateObservables(metas, handler) {
454
- const { core } = this;
455
- handler = core.patcher.unwrap(handler);
456
-
457
- let type = '';
458
- let method = '';
459
- let templates = [];
460
- const info = funcInfo(handler);
461
-
462
- let file = info.file ?
463
- StringPrototypeReplace.call(info.file, core.appInfo.app_dir, '') :
464
- '';
465
- if (file.length > 30) {
466
- file = `...${StringPrototypeSubstring.call(file, file.length - 40)}`;
467
- }
468
- const handlerName = info.method || handler.name || 'anonymous';
469
- const formattedHandler = (file && Number.isFinite(info.lineNumber) && Number.isFinite(info.column)) ?
470
- `[${handlerName} ${file} ${info.lineNumber}:${info.column}]` :
471
- `[Function: ${handlerName}]`; // what util.inspect(handler) would return
472
-
473
- // loop backwards
474
- for (let i = metas.length - 1; i >= 0; i--) {
475
- const meta = metas[i];
476
- // use the most recent `type` and `method` used when building routes, so don't overwrite if set
477
- if (!type && meta.type) type = meta.type;
478
- if (!method && meta.method) method = meta.method;
479
-
480
- // builds out all possible template combinations that the Layer is able to handle during routing
481
- if (Array.isArray(meta.paths)) {
482
- if (!templates.length) {
483
- templates = [...meta.paths];
484
- } else {
485
- const _t = [];
486
- for (const templateSegment of meta.paths) {
487
- for (const templateAcc of templates) {
488
- _t.push(`${templateSegment}${templateAcc}`);
489
- }
490
- }
491
- templates = [..._t];
492
- }
493
- }
494
- }
495
-
496
- // build signature lookup based on each template (normalizeUri)
497
- const map = templates.reduce((acc, routeTemplate) => {
498
- if (!routeTemplate) routeTemplate = '/';
499
- acc[routeTemplate] = `${type}.${method}('${routeTemplate}', ${formattedHandler})`;
500
- return acc;
501
- }, {});
502
-
503
- return map;
504
- }
505
-
506
- static normalizePathSegment(value) {
507
- if (!value || value == '/') {
508
- // app.[method](handler) and app.[method]('/', handler) are the same so default to empty string
509
- return '';
510
- }
511
- if (value instanceof RegExp) {
512
- const rxString = value.toString();
513
- // todo: figure out best way to represent regexp in route template
514
- return `/[${StringPrototypeSubstring.call(rxString, 1, rxString.length - 1)}]`;
515
- }
516
- return value;
517
- }
518
-
519
- static normalizePaths(paths) {
520
- const ret = [];
521
-
522
- // same as mounting as /
523
- if (typeof paths == 'function') {
524
- // default to ''
525
- ret.push('');
526
- } else if (isString(paths)) {
527
- ret.push(ExpressInstrumentation.normalizePathSegment(paths));
528
- } else if (Array.isArray(paths)) {
529
- paths = paths.flat(Infinity).filter((v) => typeof v !== 'function');
530
- if (paths.length) ret.push(...paths.map(ExpressInstrumentation.normalizePathSegment));
531
- else ret.push('');
532
- } else if (paths instanceof RegExp) {
533
- ret.push(ExpressInstrumentation.normalizePathSegment(paths));
534
- }
535
-
536
- return ret;
537
- }
538
- }