Socket
Socket
Sign inDemoInstall

@sentry-internal/tracing

Package Overview
Dependencies
Maintainers
10
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry-internal/tracing - npm Package Compare versions

Comparing version 7.74.0 to 7.74.1

134

cjs/node/integrations/express.js

@@ -245,4 +245,21 @@ var {

// Otherwise, the hardcoded path (i.e. a partial route without params) is stored in layer.path
const partialRoute = layerRoutePath || layer.path || '';
let partialRoute;
if (layerRoutePath) {
partialRoute = layerRoutePath;
} else {
/**
* prevent duplicate segment in _reconstructedRoute param if router match multiple routes before final path
* example:
* original url: /api/v1/1234
* prevent: /api/api/v1/:userId
* router structure
* /api -> middleware
* /api/v1 -> middleware
* /1234 -> endpoint with param :userId
* final _reconstructedRoute is /api/v1/:userId
*/
partialRoute = preventDuplicateSegments(req.originalUrl, req._reconstructedRoute, layer.path) || '';
}
// Normalize the partial route so that it doesn't contain leading or trailing slashes

@@ -292,2 +309,75 @@ // and exclude empty or '*' wildcard routes.

/**
* Recreate layer.route.path from layer.regexp and layer.keys.
* Works until express.js used package path-to-regexp@0.1.7
* or until layer.keys contain offset attribute
*
* @param layer the layer to extract the stringified route from
*
* @returns string in layer.route.path structure 'router/:pathParam' or undefined
*/
const extractOriginalRoute = (
path,
regexp,
keys,
) => {
if (!path || !regexp || !keys || Object.keys(keys).length === 0 || !_optionalChain([keys, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.offset])) {
return undefined;
}
const orderedKeys = keys.sort((a, b) => a.offset - b.offset);
// add d flag for getting indices from regexp result
const pathRegex = new RegExp(regexp, `${regexp.flags}d`);
/**
* use custom type cause of TS error with missing indices in RegExpExecArray
*/
const execResult = pathRegex.exec(path) ;
if (!execResult || !execResult.indices) {
return undefined;
}
/**
* remove first match from regex cause contain whole layer.path
*/
const [, ...paramIndices] = execResult.indices;
if (paramIndices.length !== orderedKeys.length) {
return undefined;
}
let resultPath = path;
let indexShift = 0;
/**
* iterate param matches from regexp.exec
*/
paramIndices.forEach(([startOffset, endOffset], index) => {
/**
* isolate part before param
*/
const substr1 = resultPath.substring(0, startOffset - indexShift);
/**
* define paramName as replacement in format :pathParam
*/
const replacement = `:${orderedKeys[index].name}`;
/**
* isolate part after param
*/
const substr2 = resultPath.substring(endOffset - indexShift);
/**
* recreate original path but with param replacement
*/
resultPath = substr1 + replacement + substr2;
/**
* calculate new index shift after resultPath was modified
*/
indexShift = indexShift + (endOffset - startOffset - replacement.length);
});
return resultPath;
};
/**
* Extracts and stringifies the layer's route which can either be a string with parameters (`users/:id`),

@@ -304,3 +394,3 @@ * a RegEx (`/test/`) or an array of strings and regexes (`['/path1', /\/path[2-5]/, /path/:id]`). Additionally

function getLayerRoutePathInfo(layer) {
const lrp = _optionalChain([layer, 'access', _10 => _10.route, 'optionalAccess', _11 => _11.path]);
let lrp = _optionalChain([layer, 'access', _12 => _12.route, 'optionalAccess', _13 => _13.path]);

@@ -311,2 +401,15 @@ const isRegex = utils.isRegExp(lrp);

if (!lrp) {
// parse node.js major version
const [major] = process.versions.node.split('.').map(Number);
// allow call extractOriginalRoute only if node version support Regex d flag, node 16+
if (major >= 16) {
/**
* If lrp does not exist try to recreate original layer path from route regexp
*/
lrp = extractOriginalRoute(layer.path, layer.regexp, layer.keys);
}
}
if (!lrp) {
return { isRegex, isArray, numExtraSegments: 0 };

@@ -349,3 +452,30 @@ }

/**
* remove duplicate segment contain in layerPath against reconstructedRoute,
* and return only unique segment that can be added into reconstructedRoute
*/
function preventDuplicateSegments(
originalUrl,
reconstructedRoute,
layerPath,
) {
const originalUrlSplit = _optionalChain([originalUrl, 'optionalAccess', _14 => _14.split, 'call', _15 => _15('/'), 'access', _16 => _16.filter, 'call', _17 => _17(v => !!v)]);
let tempCounter = 0;
const currentOffset = _optionalChain([reconstructedRoute, 'optionalAccess', _18 => _18.split, 'call', _19 => _19('/'), 'access', _20 => _20.filter, 'call', _21 => _21(v => !!v), 'access', _22 => _22.length]) || 0;
const result = _optionalChain([layerPath
, 'optionalAccess', _23 => _23.split, 'call', _24 => _24('/')
, 'access', _25 => _25.filter, 'call', _26 => _26(segment => {
if (_optionalChain([originalUrlSplit, 'optionalAccess', _27 => _27[currentOffset + tempCounter]]) === segment) {
tempCounter += 1;
return true;
}
return false;
})
, 'access', _28 => _28.join, 'call', _29 => _29('/')]);
return result;
}
exports.Express = Express;
exports.extractOriginalRoute = extractOriginalRoute;
exports.preventDuplicateSegments = preventDuplicateSegments;
//# sourceMappingURL=express.js.map

@@ -240,4 +240,21 @@ import { _optionalChain } from '@sentry/utils/esm/buildPolyfills';

// Otherwise, the hardcoded path (i.e. a partial route without params) is stored in layer.path
const partialRoute = layerRoutePath || layer.path || '';
let partialRoute;
if (layerRoutePath) {
partialRoute = layerRoutePath;
} else {
/**
* prevent duplicate segment in _reconstructedRoute param if router match multiple routes before final path
* example:
* original url: /api/v1/1234
* prevent: /api/api/v1/:userId
* router structure
* /api -> middleware
* /api/v1 -> middleware
* /1234 -> endpoint with param :userId
* final _reconstructedRoute is /api/v1/:userId
*/
partialRoute = preventDuplicateSegments(req.originalUrl, req._reconstructedRoute, layer.path) || '';
}
// Normalize the partial route so that it doesn't contain leading or trailing slashes

@@ -287,2 +304,75 @@ // and exclude empty or '*' wildcard routes.

/**
* Recreate layer.route.path from layer.regexp and layer.keys.
* Works until express.js used package path-to-regexp@0.1.7
* or until layer.keys contain offset attribute
*
* @param layer the layer to extract the stringified route from
*
* @returns string in layer.route.path structure 'router/:pathParam' or undefined
*/
const extractOriginalRoute = (
path,
regexp,
keys,
) => {
if (!path || !regexp || !keys || Object.keys(keys).length === 0 || !_optionalChain([keys, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.offset])) {
return undefined;
}
const orderedKeys = keys.sort((a, b) => a.offset - b.offset);
// add d flag for getting indices from regexp result
const pathRegex = new RegExp(regexp, `${regexp.flags}d`);
/**
* use custom type cause of TS error with missing indices in RegExpExecArray
*/
const execResult = pathRegex.exec(path) ;
if (!execResult || !execResult.indices) {
return undefined;
}
/**
* remove first match from regex cause contain whole layer.path
*/
const [, ...paramIndices] = execResult.indices;
if (paramIndices.length !== orderedKeys.length) {
return undefined;
}
let resultPath = path;
let indexShift = 0;
/**
* iterate param matches from regexp.exec
*/
paramIndices.forEach(([startOffset, endOffset], index) => {
/**
* isolate part before param
*/
const substr1 = resultPath.substring(0, startOffset - indexShift);
/**
* define paramName as replacement in format :pathParam
*/
const replacement = `:${orderedKeys[index].name}`;
/**
* isolate part after param
*/
const substr2 = resultPath.substring(endOffset - indexShift);
/**
* recreate original path but with param replacement
*/
resultPath = substr1 + replacement + substr2;
/**
* calculate new index shift after resultPath was modified
*/
indexShift = indexShift + (endOffset - startOffset - replacement.length);
});
return resultPath;
};
/**
* Extracts and stringifies the layer's route which can either be a string with parameters (`users/:id`),

@@ -299,3 +389,3 @@ * a RegEx (`/test/`) or an array of strings and regexes (`['/path1', /\/path[2-5]/, /path/:id]`). Additionally

function getLayerRoutePathInfo(layer) {
const lrp = _optionalChain([layer, 'access', _10 => _10.route, 'optionalAccess', _11 => _11.path]);
let lrp = _optionalChain([layer, 'access', _12 => _12.route, 'optionalAccess', _13 => _13.path]);

@@ -306,2 +396,15 @@ const isRegex = isRegExp(lrp);

if (!lrp) {
// parse node.js major version
const [major] = process.versions.node.split('.').map(Number);
// allow call extractOriginalRoute only if node version support Regex d flag, node 16+
if (major >= 16) {
/**
* If lrp does not exist try to recreate original layer path from route regexp
*/
lrp = extractOriginalRoute(layer.path, layer.regexp, layer.keys);
}
}
if (!lrp) {
return { isRegex, isArray, numExtraSegments: 0 };

@@ -344,3 +447,28 @@ }

export { Express };
/**
* remove duplicate segment contain in layerPath against reconstructedRoute,
* and return only unique segment that can be added into reconstructedRoute
*/
function preventDuplicateSegments(
originalUrl,
reconstructedRoute,
layerPath,
) {
const originalUrlSplit = _optionalChain([originalUrl, 'optionalAccess', _14 => _14.split, 'call', _15 => _15('/'), 'access', _16 => _16.filter, 'call', _17 => _17(v => !!v)]);
let tempCounter = 0;
const currentOffset = _optionalChain([reconstructedRoute, 'optionalAccess', _18 => _18.split, 'call', _19 => _19('/'), 'access', _20 => _20.filter, 'call', _21 => _21(v => !!v), 'access', _22 => _22.length]) || 0;
const result = _optionalChain([layerPath
, 'optionalAccess', _23 => _23.split, 'call', _24 => _24('/')
, 'access', _25 => _25.filter, 'call', _26 => _26(segment => {
if (_optionalChain([originalUrlSplit, 'optionalAccess', _27 => _27[currentOffset + tempCounter]]) === segment) {
tempCounter += 1;
return true;
}
return false;
})
, 'access', _28 => _28.join, 'call', _29 => _29('/')]);
return result;
}
export { Express, extractOriginalRoute, preventDuplicateSegments };
//# sourceMappingURL=express.js.map

8

package.json
{
"name": "@sentry-internal/tracing",
"version": "7.74.0",
"version": "7.74.1",
"description": "Sentry Internal Tracing Package",

@@ -26,5 +26,5 @@ "repository": "git://github.com/getsentry/sentry-javascript.git",

"dependencies": {
"@sentry/core": "7.74.0",
"@sentry/types": "7.74.0",
"@sentry/utils": "7.74.0",
"@sentry/core": "7.74.1",
"@sentry/types": "7.74.1",
"@sentry/utils": "7.74.1",
"tslib": "^2.4.1 || ^1.9.3"

@@ -31,0 +31,0 @@ },

@@ -1,2 +0,2 @@

import { Hub, Integration } from '@sentry/types';
import { Hub, Integration, PolymorphicRequest } from '@sentry/types';
type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe' | 'use';

@@ -6,2 +6,24 @@ type Router = {

};
type PatchedRequest = PolymorphicRequest & {
_reconstructedRoute?: string;
_hasParameters?: boolean;
};
type Layer = {
match: (path: string) => boolean;
handle_request: (req: PatchedRequest, res: ExpressResponse, next: () => void) => void;
route?: {
path: RouteType | RouteType[];
};
path?: string;
regexp?: RegExp;
keys?: {
name: string;
offset: number;
optional: boolean;
}[];
};
type RouteType = string | RegExp;
interface ExpressResponse {
once(name: string, callback: () => void): void;
}
/**

@@ -39,3 +61,18 @@ * Express integration

}
/**
* Recreate layer.route.path from layer.regexp and layer.keys.
* Works until express.js used package path-to-regexp@0.1.7
* or until layer.keys contain offset attribute
*
* @param layer the layer to extract the stringified route from
*
* @returns string in layer.route.path structure 'router/:pathParam' or undefined
*/
export declare const extractOriginalRoute: (path?: Layer['path'], regexp?: Layer['regexp'], keys?: Layer['keys']) => string | undefined;
/**
* remove duplicate segment contain in layerPath against reconstructedRoute,
* and return only unique segment that can be added into reconstructedRoute
*/
export declare function preventDuplicateSegments(originalUrl?: string, reconstructedRoute?: string, layerPath?: string): string | undefined;
export {};
//# sourceMappingURL=express.d.ts.map

@@ -1,2 +0,2 @@

import type { Hub, Integration } from '@sentry/types';
import type { Hub, Integration, PolymorphicRequest } from '@sentry/types';
type Method = 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'checkout' | 'copy' | 'lock' | 'merge' | 'mkactivity' | 'mkcol' | 'move' | 'm-search' | 'notify' | 'purge' | 'report' | 'search' | 'subscribe' | 'trace' | 'unlock' | 'unsubscribe' | 'use';

@@ -6,2 +6,24 @@ type Router = {

};
type PatchedRequest = PolymorphicRequest & {
_reconstructedRoute?: string;
_hasParameters?: boolean;
};
type Layer = {
match: (path: string) => boolean;
handle_request: (req: PatchedRequest, res: ExpressResponse, next: () => void) => void;
route?: {
path: RouteType | RouteType[];
};
path?: string;
regexp?: RegExp;
keys?: {
name: string;
offset: number;
optional: boolean;
}[];
};
type RouteType = string | RegExp;
interface ExpressResponse {
once(name: string, callback: () => void): void;
}
/**

@@ -39,3 +61,18 @@ * Express integration

}
/**
* Recreate layer.route.path from layer.regexp and layer.keys.
* Works until express.js used package path-to-regexp@0.1.7
* or until layer.keys contain offset attribute
*
* @param layer the layer to extract the stringified route from
*
* @returns string in layer.route.path structure 'router/:pathParam' or undefined
*/
export declare const extractOriginalRoute: (path?: Layer['path'], regexp?: Layer['regexp'], keys?: Layer['keys']) => string | undefined;
/**
* remove duplicate segment contain in layerPath against reconstructedRoute,
* and return only unique segment that can be added into reconstructedRoute
*/
export declare function preventDuplicateSegments(originalUrl?: string, reconstructedRoute?: string, layerPath?: string): string | undefined;
export {};
//# sourceMappingURL=express.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc