compressing 1.10.3 → 1.10.4

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # compressing
1
+ # compressing@1
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![Test coverage][codecov-image]][codecov-url]
@@ -14,6 +14,10 @@
14
14
  [download-image]: https://img.shields.io/npm/dm/compressing.svg?style=flat-square
15
15
  [download-url]: https://npmjs.org/package/compressing
16
16
 
17
+ ## ⚠️ Warning
18
+
19
+ **Version 1.x is no longer maintained. Please upgrade to version 2.x as soon as possible.**
20
+
17
21
  The missing compressing and uncompressing lib for node.
18
22
 
19
23
  Currently supported:
@@ -26,7 +30,7 @@ Currently supported:
26
30
  ## Install
27
31
 
28
32
  ```bash
29
- npm install compressing
33
+ npm install compressing@1
30
34
  ```
31
35
 
32
36
  ## Usage
package/lib/utils.js CHANGED
@@ -5,6 +5,22 @@ const path = require('path');
5
5
  const mkdirp = require('mkdirp');
6
6
  const pump = require('pump');
7
7
 
8
+ /**
9
+ * Check if childPath is within parentPath (prevents path traversal attacks)
10
+ * @param {string} childPath - The path to check
11
+ * @param {string} parentPath - The parent directory path
12
+ * @returns {boolean} - True if childPath is within parentPath
13
+ */
14
+ function isPathWithinParent(childPath, parentPath) {
15
+ const normalizedChild = path.resolve(childPath);
16
+ const normalizedParent = path.resolve(parentPath);
17
+ const parentWithSep = normalizedParent.endsWith(path.sep)
18
+ ? normalizedParent
19
+ : normalizedParent + path.sep;
20
+ return normalizedChild === normalizedParent ||
21
+ normalizedChild.startsWith(parentWithSep);
22
+ }
23
+
8
24
  // file/fileBuffer/stream
9
25
  exports.sourceType = source => {
10
26
  if (!source) return undefined;
@@ -93,6 +109,9 @@ exports.makeUncompressFn = StreamClass => {
93
109
  mkdirp(destDir, err => {
94
110
  if (err) return reject(err);
95
111
 
112
+ // Resolve destDir to absolute path for security validation
113
+ const resolvedDestDir = path.resolve(destDir);
114
+
96
115
  let entryCount = 0;
97
116
  let successCount = 0;
98
117
  let isFinish = false;
@@ -109,7 +128,15 @@ exports.makeUncompressFn = StreamClass => {
109
128
  .on('error', reject)
110
129
  .on('entry', (header, stream, next) => {
111
130
  stream.on('end', next);
112
- const destFilePath = path.join(destDir, header.name);
131
+ const destFilePath = path.join(resolvedDestDir, header.name);
132
+ const resolvedDestPath = path.resolve(destFilePath);
133
+
134
+ // Security: Validate that the entry path doesn't escape the destination directory
135
+ if (!isPathWithinParent(resolvedDestPath, resolvedDestDir)) {
136
+ console.warn(`[compressing] Skipping entry with path traversal: "${header.name}" -> "${resolvedDestPath}"`);
137
+ stream.resume();
138
+ return;
139
+ }
113
140
 
114
141
  if (header.type === 'file') {
115
142
  const dir = path.dirname(destFilePath);
@@ -126,6 +153,14 @@ exports.makeUncompressFn = StreamClass => {
126
153
  } else if (header.type === 'symlink') {
127
154
  const dir = path.dirname(destFilePath);
128
155
  const target = path.resolve(dir, header.linkname);
156
+
157
+ // Security: Validate that the symlink target doesn't escape the destination directory
158
+ if (!isPathWithinParent(target, resolvedDestDir)) {
159
+ console.warn(`[compressing] Skipping symlink "${header.name}": target "${target}" escapes extraction directory`);
160
+ stream.resume();
161
+ return;
162
+ }
163
+
129
164
  entryCount++;
130
165
 
131
166
  mkdirp(dir, err => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compressing",
3
- "version": "1.10.3",
3
+ "version": "1.10.4",
4
4
  "description": "Everything you need for compressing and uncompressing",
5
5
  "main": "index.js",
6
6
  "scripts": {