ntlogger 2.8.1 → 2.8.2

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.
@@ -90,11 +90,37 @@ function reportPath(callSite, callerOfCaller = null) {
90
90
  // Get base path (project root)
91
91
  const basePath = require.main?.path || process.cwd();
92
92
 
93
- // Build relative path
94
- const relativeDir = path
95
- .relative(basePath, path.dirname(file))
96
- .replace(/\\/g, '/')
97
- .replace(/(\.\.\/)+/g, '');
93
+ // Build relative path and sanitize path traversal attempts
94
+ let relativeDir = path.relative(basePath, path.dirname(file));
95
+
96
+ // Normalize the path (resolves .. and . segments safely)
97
+ relativeDir = path.normalize(relativeDir);
98
+
99
+ // Ensure the normalized path doesn't escape the base directory
100
+ // If normalization results in a path outside basePath, use just the filename
101
+ const resolvedPath = path.resolve(basePath, relativeDir);
102
+ const resolvedBase = path.resolve(basePath);
103
+ if (!resolvedPath.startsWith(resolvedBase)) {
104
+ // Path traversal detected, use only filename
105
+ relativeDir = '';
106
+ }
107
+
108
+ // Convert to forward slashes for consistency
109
+ relativeDir = relativeDir.replace(/\\/g, '/');
110
+
111
+ // Remove any remaining path traversal sequences (defense in depth)
112
+ // Use multiple passes to catch all variations: ../, ..\, .., etc.
113
+ let previousDir = '';
114
+ while (relativeDir !== previousDir) {
115
+ previousDir = relativeDir;
116
+ relativeDir = relativeDir
117
+ .replace(/\.\.\//g, '') // Remove ../
118
+ .replace(/\.\.\\/g, '') // Remove ..\
119
+ .replace(/\/\.\./g, '') // Remove /..
120
+ .replace(/\\\.\./g, '') // Remove \..
121
+ .replace(/^\.\./g, '') // Remove leading ..
122
+ .replace(/\.\.$/g, ''); // Remove trailing ..
123
+ }
98
124
 
99
125
  const shortPath = './' + (relativeDir ? relativeDir + '/' : '') + path.basename(file);
100
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntlogger",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "description": "A Custom Ready-To-Go Logging Wrapper Built on Winston",
5
5
  "keywords": [
6
6
  "custom logger",
@@ -44,5 +44,8 @@
44
44
  "@sentry/profiling-node": "^10.25.0",
45
45
  "dotenv": "^17.2.3",
46
46
  "jest": "^30.2.0"
47
+ },
48
+ "overrides": {
49
+ "glob": "^11.1.0"
47
50
  }
48
51
  }