extract-base-iterator 3.4.2 → 3.4.3
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/dist/cjs/DirectoryEntry.js +2 -1
- package/dist/cjs/DirectoryEntry.js.map +1 -1
- package/dist/cjs/FileEntry.js +2 -1
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/LinkEntry.js +9 -2
- package/dist/cjs/LinkEntry.js.map +1 -1
- package/dist/cjs/SymbolicLinkEntry.js +12 -7
- package/dist/cjs/SymbolicLinkEntry.js.map +1 -1
- package/dist/cjs/shared/index.d.cts +1 -0
- package/dist/cjs/shared/index.d.ts +1 -0
- package/dist/cjs/shared/index.js +4 -0
- package/dist/cjs/shared/index.js.map +1 -1
- package/dist/cjs/shared/safeJoinPath.d.cts +1 -0
- package/dist/cjs/shared/safeJoinPath.d.ts +1 -0
- package/dist/cjs/shared/safeJoinPath.js +27 -0
- package/dist/cjs/shared/safeJoinPath.js.map +1 -0
- package/dist/esm/DirectoryEntry.js +2 -1
- package/dist/esm/DirectoryEntry.js.map +1 -1
- package/dist/esm/FileEntry.js +2 -1
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/LinkEntry.js +9 -2
- package/dist/esm/LinkEntry.js.map +1 -1
- package/dist/esm/SymbolicLinkEntry.js +12 -7
- package/dist/esm/SymbolicLinkEntry.js.map +1 -1
- package/dist/esm/shared/index.d.ts +1 -0
- package/dist/esm/shared/index.js +1 -0
- package/dist/esm/shared/index.js.map +1 -1
- package/dist/esm/shared/safeJoinPath.d.ts +1 -0
- package/dist/esm/shared/safeJoinPath.js +11 -0
- package/dist/esm/shared/safeJoinPath.js.map +1 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ var _chmodts = /*#__PURE__*/ _interop_require_default(require("./fs/chmod.js"));
|
|
|
15
15
|
var _chownts = /*#__PURE__*/ _interop_require_default(require("./fs/chown.js"));
|
|
16
16
|
var _utimests = /*#__PURE__*/ _interop_require_default(require("./fs/utimes.js"));
|
|
17
17
|
var _indexts = require("./shared/index.js");
|
|
18
|
+
var _safeJoinPathts = /*#__PURE__*/ _interop_require_default(require("./shared/safeJoinPath.js"));
|
|
18
19
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./shared/stripPath.js"));
|
|
19
20
|
var _validateAttributests = /*#__PURE__*/ _interop_require_default(require("./validateAttributes.js"));
|
|
20
21
|
var _waitForAccessts = /*#__PURE__*/ _interop_require_default(require("./waitForAccess.js"));
|
|
@@ -50,7 +51,7 @@ var DirectoryEntry = /*#__PURE__*/ function() {
|
|
|
50
51
|
if (typeof callback === 'function') {
|
|
51
52
|
try {
|
|
52
53
|
var normalizedPath = _path.default.normalize(this.path);
|
|
53
|
-
var fullPath =
|
|
54
|
+
var fullPath = (0, _safeJoinPathts.default)(dest, (0, _stripPathts.default)(normalizedPath, options));
|
|
54
55
|
// do not check for the existence of the directory but allow out-of-order calling
|
|
55
56
|
var queue = new _queuecb.default(1);
|
|
56
57
|
queue.defer(_mkdirpclassic.default.bind(null, fullPath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/DirectoryEntry.ts"],"sourcesContent":["import mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { DirectoryAttributes, ExtractOptions, NoParamCallback } from './types.ts';\n\nexport default class DirectoryEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: DirectoryAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.type === undefined) this.type = 'directory';\n if (this.basename === undefined) this.basename = path.basename(this.path);\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/DirectoryEntry.ts"],"sourcesContent":["import mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { DirectoryAttributes, ExtractOptions, NoParamCallback } from './types.ts';\n\nexport default class DirectoryEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: DirectoryAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.type === undefined) this.type = 'directory';\n if (this.basename === undefined) this.basename = path.basename(this.path);\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n // do not check for the existence of the directory but allow out-of-order calling\n const queue = new Queue(1);\n queue.defer(mkdirp.bind(null, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["DirectoryEntry","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","type","undefined","basename","path","create","dest","options","callback","normalizedPath","normalize","fullPath","safeJoinPath","stripPath","queue","Queue","defer","mkdirp","bind","waitForAccess","chmod","chown","utimes","await","err","Promise","resolve","reject","done","destroy"],"mappings":";;;;;;;eAiBqBA;;;oEAjBF;2DACF;8DACC;8DACA;8DACA;+DACC;uBACU;qEACJ;kEACH;2EACS;sEACL;;;;;;;;;;;AAE1B,IAAMC,uBAAuB;IAAC;IAAQ;IAAS;CAAO;AAKvC,IAAA,AAAMD,+BAAN;;aAAMA,eAOPE,UAA+B;gCAPxBF;QAQjBG,IAAAA,6BAAkB,EAACD,YAAYD;QAC/BG,IAAAA,qBAAY,EAAC,IAAI,EAAEF;QACnB,IAAI,IAAI,CAACG,IAAI,KAAKC,WAAW,IAAI,CAACD,IAAI,GAAG;QACzC,IAAI,IAAI,CAACE,QAAQ,KAAKD,WAAW,IAAI,CAACC,QAAQ,GAAGC,aAAI,CAACD,QAAQ,CAAC,IAAI,CAACC,IAAI;;iBAXvDR;IAiBnBS,OAAAA,MAwBC,GAxBDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzFA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,IAAI;gBACF,IAAMC,iBAAiBL,aAAI,CAACM,SAAS,CAAC,IAAI,CAACN,IAAI;gBAC/C,IAAMO,WAAWC,IAAAA,uBAAY,EAACN,MAAMO,IAAAA,oBAAS,EAACJ,gBAAgBF;gBAE9D,iFAAiF;gBACjF,IAAMO,QAAQ,IAAIC,gBAAK,CAAC;gBACxBD,MAAME,KAAK,CAACC,sBAAM,CAACC,IAAI,CAAC,MAAMP;gBAC9BG,MAAME,KAAK,CAACG,wBAAa,CAACD,IAAI,CAAC,MAAMP;gBACrCG,MAAME,KAAK,CAACI,gBAAK,CAACF,IAAI,CAAC,MAAMP,UAAU,IAAI,EAAEJ;gBAC7CO,MAAME,KAAK,CAACK,gBAAK,CAACH,IAAI,CAAC,MAAMP,UAAU,IAAI,EAAEJ;gBAC7CO,MAAME,KAAK,CAACM,iBAAM,CAACJ,IAAI,CAAC,MAAMP,UAAU,IAAI,EAAEJ;gBAC9CO,MAAMS,KAAK,CAACf;YACd,EAAE,OAAOgB,KAAK;gBACZhB,SAASgB;YACX;YACA;QACF;QAEA,OAAO,IAAIC,QAAQ,SAACC,SAASC;mBAAW,MAAKtB,MAAM,CAACC,MAAMC,SAAS,SAACiB,KAAaI;uBAAoBJ,MAAMG,OAAOH,OAAOE,QAAQE;;;IACnI;IAEAC,OAAAA,OAAY,GAAZA,SAAAA,WAAW;WA3CQjC"}
|
package/dist/cjs/FileEntry.js
CHANGED
|
@@ -17,6 +17,7 @@ var _chmodts = /*#__PURE__*/ _interop_require_default(require("./fs/chmod.js"));
|
|
|
17
17
|
var _chownts = /*#__PURE__*/ _interop_require_default(require("./fs/chown.js"));
|
|
18
18
|
var _utimests = /*#__PURE__*/ _interop_require_default(require("./fs/utimes.js"));
|
|
19
19
|
var _indexts = require("./shared/index.js");
|
|
20
|
+
var _safeJoinPathts = /*#__PURE__*/ _interop_require_default(require("./shared/safeJoinPath.js"));
|
|
20
21
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./shared/stripPath.js"));
|
|
21
22
|
var _validateAttributests = /*#__PURE__*/ _interop_require_default(require("./validateAttributes.js"));
|
|
22
23
|
var _waitForAccessts = /*#__PURE__*/ _interop_require_default(require("./waitForAccess.js"));
|
|
@@ -53,7 +54,7 @@ var FileEntry = /*#__PURE__*/ function() {
|
|
|
53
54
|
if (typeof callback === 'function') {
|
|
54
55
|
try {
|
|
55
56
|
var normalizedPath = _path.default.normalize(this.path);
|
|
56
|
-
var fullPath =
|
|
57
|
+
var fullPath = (0, _safeJoinPathts.default)(dest, (0, _stripPathts.default)(normalizedPath, options));
|
|
57
58
|
var queue = new _queuecb.default(1);
|
|
58
59
|
if (options.force) {
|
|
59
60
|
queue.defer(function(callback) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import { rm } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import { rm } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["FileEntry","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","basename","undefined","path","type","_writeFile","Error","create","dest","options","callback","normalizedPath","normalize","fullPath","safeJoinPath","stripPath","queue","Queue","force","defer","rm","err","code","fs","stat","existsErr","mkdirp","bind","dirname","waitForAccess","chmod","chown","utimes","await","Promise","resolve","reject","done","destroy"],"mappings":";;;;;;;eAuBqBA;;;8BAvBF;iEACJ;oEACI;2DACF;8DACC;8DACA;8DACA;+DACC;uBACU;qEACJ;kEACH;2EACS;sEACL;;;;;;;;;;;AAE1B,IAAMC,uBAAuB;IAAC;IAAQ;IAAS;CAAO;AASvC,IAAA,AAAMD,0BAAN;;aAAMA,UAOPE,UAA0B;gCAPnBF;QAQjBG,IAAAA,6BAAkB,EAACD,YAAYD;QAC/BG,IAAAA,qBAAY,EAAC,IAAI,EAAEF;QACnB,IAAI,IAAI,CAACG,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGE,aAAI,CAACF,QAAQ,CAAC,IAAI,CAACE,IAAI;QACxE,IAAI,IAAI,CAACC,IAAI,KAAKF,WAAW,IAAI,CAACE,IAAI,GAAG;QACzC,IAAI,AAAC,IAAI,CAAkCC,UAAU,KAAKH,WAAW,MAAM,IAAII,MAAM;;iBAZpEV;IAkBnBW,OAAAA,MA+CC,GA/CDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzFA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,IAAI;gBACF,IAAMC,iBAAiBR,aAAI,CAACS,SAAS,CAAC,IAAI,CAACT,IAAI;gBAC/C,IAAMU,WAAWC,IAAAA,uBAAY,EAACN,MAAMO,IAAAA,oBAAS,EAACJ,gBAAgBF;gBAE9D,IAAMO,QAAQ,IAAIC,gBAAK,CAAC;gBACxB,IAAIR,QAAQS,KAAK,EAAE;oBACjBF,MAAMG,KAAK,CAAC,SAACT;wBACXU,IAAAA,kBAAE,EAACP,UAAU,SAACQ;4BACZA,OAAOA,IAAIC,IAAI,KAAK,WAAWZ,SAASW,OAAOX;wBACjD;oBACF;gBACF,O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|
});
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _fsremovecompat = require("fs-remove-compat");
|
|
13
|
+
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
13
14
|
var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
|
|
14
15
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
15
16
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
@@ -17,6 +18,7 @@ var _chmodts = /*#__PURE__*/ _interop_require_default(require("./fs/chmod.js"));
|
|
|
17
18
|
var _chownts = /*#__PURE__*/ _interop_require_default(require("./fs/chown.js"));
|
|
18
19
|
var _utimests = /*#__PURE__*/ _interop_require_default(require("./fs/utimes.js"));
|
|
19
20
|
var _indexts = require("./shared/index.js");
|
|
21
|
+
var _safeJoinPathts = /*#__PURE__*/ _interop_require_default(require("./shared/safeJoinPath.js"));
|
|
20
22
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./shared/stripPath.js"));
|
|
21
23
|
var _validateAttributests = /*#__PURE__*/ _interop_require_default(require("./validateAttributes.js"));
|
|
22
24
|
var _waitForAccessts = /*#__PURE__*/ _interop_require_default(require("./waitForAccess.js"));
|
|
@@ -53,9 +55,14 @@ var LinkEntry = /*#__PURE__*/ function() {
|
|
|
53
55
|
if (typeof callback === 'function') {
|
|
54
56
|
try {
|
|
55
57
|
var normalizedPath = _path.default.normalize(this.path);
|
|
56
|
-
var fullPath =
|
|
58
|
+
var fullPath = (0, _safeJoinPathts.default)(dest, (0, _stripPathts.default)(normalizedPath, options));
|
|
59
|
+
if ((0, _isabsolute.default)(this.linkpath)) {
|
|
60
|
+
var _$err = new Error("Absolute linkpath rejected: '".concat(this.linkpath, "'"));
|
|
61
|
+
_$err.code = 'ETRAVERSAL';
|
|
62
|
+
throw _$err;
|
|
63
|
+
}
|
|
57
64
|
var normalizedLinkpath = _path.default.normalize(this.linkpath);
|
|
58
|
-
var linkFullPath =
|
|
65
|
+
var linkFullPath = (0, _safeJoinPathts.default)(dest, (0, _stripPathts.default)(normalizedLinkpath, options));
|
|
59
66
|
var queue = new _queuecb.default(1);
|
|
60
67
|
if (options.force) {
|
|
61
68
|
queue.defer(function(callback) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/LinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class LinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'link';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/LinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class LinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'link';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n if (isAbsolute(this.linkpath)) {\n const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n const normalizedLinkpath = path.normalize(this.linkpath);\n const linkFullPath = safeJoinPath(dest, stripPath(normalizedLinkpath, options));\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer(waitForAccess.bind(null, linkFullPath)); // ensure target file is accessible before linking\n queue.defer(fs.link.bind(fs, linkFullPath, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["LinkEntry","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","basename","undefined","path","type","create","dest","options","callback","normalizedPath","normalize","fullPath","safeJoinPath","stripPath","isAbsolute","linkpath","err","Error","code","normalizedLinkpath","linkFullPath","queue","Queue","force","defer","rm","mkdirp","bind","dirname","waitForAccess","fs","link","chmod","chown","utimes","await","Promise","resolve","reject","done","destroy"],"mappings":";;;;;;;eAoBqBA;;;yDApBN;8BACI;iEACI;oEACJ;2DACF;8DACC;8DACA;8DACA;+DACC;uBACU;qEACJ;kEACH;2EACS;sEACL;;;;;;;;;;;AAE1B,IAAMC,uBAAuB;IAAC;IAAQ;IAAS;IAAQ;CAAW;AAKnD,IAAA,AAAMD,0BAAN;;aAAMA,UAQPE,UAA0B;gCARnBF;QASjBG,IAAAA,6BAAkB,EAACD,YAAYD;QAC/BG,IAAAA,qBAAY,EAAC,IAAI,EAAEF;QACnB,IAAI,IAAI,CAACG,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGE,aAAI,CAACF,QAAQ,CAAC,IAAI,CAACE,IAAI;QACxE,IAAI,IAAI,CAACC,IAAI,KAAKF,WAAW,IAAI,CAACE,IAAI,GAAG;;iBAZxBR;IAkBnBS,OAAAA,MAu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gBACrCU,MAAMG,KAAK,CAACQ,gBAAK,CAACL,IAAI,CAAC,MAAMhB,UAAU,IAAI,EAAEJ;gBAC7Cc,MAAMG,KAAK,CAACS,gBAAK,CAACN,IAAI,CAAC,MAAMhB,UAAU,IAAI,EAAEJ;gBAC7Cc,MAAMG,KAAK,CAACU,iBAAM,CAACP,IAAI,CAAC,MAAMhB,UAAU,IAAI,EAAEJ;gBAC9Cc,MAAMc,KAAK,CAAC3B;YACd,EAAE,OAAOQ,KAAK;gBACZR,SAASQ;YACX;YACA;QACF;QAEA,OAAO,IAAIoB,QAAQ,SAACC,SAASC;mBAAW,MAAKjC,MAAM,CAACC,MAAMC,SAAS,SAACS,KAAauB;uBAAoBvB,MAAMsB,OAAOtB,OAAOqB,QAAQE;;;IACnI;IAEAC,OAAAA,OAAY,GAAZA,SAAAA,WAAW;WA3DQ5C"}
|
|
@@ -19,6 +19,7 @@ var _chownts = /*#__PURE__*/ _interop_require_default(require("./fs/chown.js"));
|
|
|
19
19
|
var _lutimests = /*#__PURE__*/ _interop_require_default(require("./fs/lutimes.js"));
|
|
20
20
|
var _symlinkWin32ts = /*#__PURE__*/ _interop_require_default(require("./fs/symlinkWin32.js"));
|
|
21
21
|
var _indexts = require("./shared/index.js");
|
|
22
|
+
var _safeJoinPathts = /*#__PURE__*/ _interop_require_default(require("./shared/safeJoinPath.js"));
|
|
22
23
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./shared/stripPath.js"));
|
|
23
24
|
var _validateAttributests = /*#__PURE__*/ _interop_require_default(require("./validateAttributes.js"));
|
|
24
25
|
var _waitForAccessts = /*#__PURE__*/ _interop_require_default(require("./waitForAccess.js"));
|
|
@@ -56,14 +57,18 @@ var SymbolicLinkEntry = /*#__PURE__*/ function() {
|
|
|
56
57
|
if (typeof callback === 'function') {
|
|
57
58
|
try {
|
|
58
59
|
var normalizedPath = _path.default.normalize(this.path);
|
|
59
|
-
var fullPath =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
linkFullPath = _path.default.join(dest, (0, _stripPathts.default)(linkRelativePath, options));
|
|
65
|
-
normalizedLinkpath = _path.default.relative(_path.default.dirname(fullPath), linkFullPath);
|
|
60
|
+
var fullPath = (0, _safeJoinPathts.default)(dest, (0, _stripPathts.default)(normalizedPath, options));
|
|
61
|
+
if ((0, _isabsolute.default)(this.linkpath)) {
|
|
62
|
+
var _$err = new Error("Absolute linkpath rejected: '".concat(this.linkpath, "'"));
|
|
63
|
+
_$err.code = 'ETRAVERSAL';
|
|
64
|
+
throw _$err;
|
|
66
65
|
}
|
|
66
|
+
// Resolve the symlink target against the symlink's own directory and verify it
|
|
67
|
+
// stays within dest. safeJoinPath throws ETRAVERSAL if it escapes.
|
|
68
|
+
var targetAbs = _path.default.resolve(_path.default.dirname(fullPath), this.linkpath);
|
|
69
|
+
(0, _safeJoinPathts.default)(dest, _path.default.relative(dest, targetAbs));
|
|
70
|
+
var normalizedLinkpath = _path.default.relative(_path.default.dirname(fullPath), targetAbs);
|
|
71
|
+
var linkFullPath = targetAbs;
|
|
67
72
|
var queue = new _queuecb.default(1);
|
|
68
73
|
if (options.force) {
|
|
69
74
|
queue.defer(function(callback) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/SymbolicLinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport lutimes from './fs/lutimes.ts';\nimport symlinkWin32 from './fs/symlinkWin32.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class SymbolicLinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'symlink';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/SymbolicLinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport lutimes from './fs/lutimes.ts';\nimport symlinkWin32 from './fs/symlinkWin32.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class SymbolicLinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'symlink';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n if (isAbsolute(this.linkpath)) {\n const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n // Resolve the symlink target against the symlink's own directory and verify it\n // stays within dest. safeJoinPath throws ETRAVERSAL if it escapes.\n const targetAbs = path.resolve(path.dirname(fullPath), this.linkpath);\n safeJoinPath(dest, path.relative(dest, targetAbs));\n const normalizedLinkpath = path.relative(path.dirname(fullPath), targetAbs);\n const linkFullPath = targetAbs;\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n if (isWindows) queue.defer(symlinkWin32.bind(null, linkFullPath, normalizedLinkpath, fullPath));\n else queue.defer(fs.symlink.bind(fs, normalizedLinkpath, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath, true)); // noFollow=true for symlinks\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(lutimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["SymbolicLinkEntry","isWindows","process","platform","test","env","OSTYPE","MANDATORY_ATTRIBUTES","attributes","validateAttributes","objectAssign","basename","undefined","path","type","create","dest","options","callback","normalizedPath","normalize","fullPath","safeJoinPath","stripPath","isAbsolute","linkpath","err","Error","code","targetAbs","resolve","dirname","relative","normalizedLinkpath","linkFullPath","queue","Queue","force","defer","rm","mkdirp","bind","symlinkWin32","fs","symlink","waitForAccess","chmod","chown","lutimes","await","Promise","reject","done","destroy"],"mappings":";;;;;;;eAuBqBA;;;yDAvBN;8BACI;iEACI;oEACJ;2DACF;8DACC;8DACA;8DACA;gEACE;qEACK;uBACI;qEACJ;kEACH;2EACS;sEACL;;;;;;;;;;;AAE1B,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,IAAMC,uBAAuB;IAAC;IAAQ;IAAS;IAAQ;CAAW;AAKnD,IAAA,AAAMP,kCAAN;;aAAMA,kBAQPQ,UAA0B;gCARnBR;QASjBS,IAAAA,6BAAkB,EAACD,YAAYD;QAC/BG,IAAAA,qBAAY,EAAC,IAAI,EAAEF;QACnB,IAAI,IAAI,CAACG,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGE,aAAI,CAACF,QAAQ,CAAC,IAAI,CAACE,IAAI;QACxE,IAAI,IAAI,CAACC,IAAI,KAAKF,WAAW,IAAI,CAACE,IAAI,GAAG;;iBAZxBd;IAkBnBe,OAAAA,MA4CC,GA5CDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzFA,WAAW,OAAOD,YAAY,aAAaA,UAAU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EAAEV,oBAAoBZ;gBACzDc,MAAMG,KAAK,CAACO,wBAAa,CAACJ,IAAI,CAAC,MAAMpB,UAAU,QAAQ,6BAA6B;gBACpFc,MAAMG,KAAK,CAACQ,gBAAK,CAACL,IAAI,CAAC,MAAMpB,UAAU,IAAI,EAAEJ;gBAC7CkB,MAAMG,KAAK,CAACS,gBAAK,CAACN,IAAI,CAAC,MAAMpB,UAAU,IAAI,EAAEJ;gBAC7CkB,MAAMG,KAAK,CAACU,kBAAO,CAACP,IAAI,CAAC,MAAMpB,UAAU,IAAI,EAAEJ;gBAC/CkB,MAAMc,KAAK,CAAC/B;YACd,EAAE,OAAOQ,KAAK;gBACZR,SAASQ;YACX;YACA;QACF;QAEA,OAAO,IAAIwB,QAAQ,SAACpB,SAASqB;mBAAW,MAAKpC,MAAM,CAACC,MAAMC,SAAS,SAACS,KAAa0B;uBAAoB1B,MAAMyB,OAAOzB,OAAOI,QAAQsB;;;IACnI;IAEAC,OAAAA,OAAY,GAAZA,SAAAA,WAAW;WAhEQrD"}
|
|
@@ -22,5 +22,6 @@ export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
|
|
|
22
22
|
export { default as EntryStream } from './EntryStream.js';
|
|
23
23
|
export { type CleanupFn, default as Lock } from './Lock.js';
|
|
24
24
|
export { default as normalizePath } from './normalizePath.js';
|
|
25
|
+
export { default as safeJoinPath } from './safeJoinPath.js';
|
|
25
26
|
export { default as streamToString, type StreamToStringCallback } from './streamToString.js';
|
|
26
27
|
export { default as stripPath } from './stripPath.js';
|
|
@@ -22,5 +22,6 @@ export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
|
|
|
22
22
|
export { default as EntryStream } from './EntryStream.js';
|
|
23
23
|
export { type CleanupFn, default as Lock } from './Lock.js';
|
|
24
24
|
export { default as normalizePath } from './normalizePath.js';
|
|
25
|
+
export { default as safeJoinPath } from './safeJoinPath.js';
|
|
25
26
|
export { default as streamToString, type StreamToStringCallback } from './streamToString.js';
|
|
26
27
|
export { default as stripPath } from './stripPath.js';
|
package/dist/cjs/shared/index.js
CHANGED
|
@@ -91,6 +91,9 @@ _export(exports, {
|
|
|
91
91
|
get readUInt64LE () {
|
|
92
92
|
return _compatts.readUInt64LE;
|
|
93
93
|
},
|
|
94
|
+
get safeJoinPath () {
|
|
95
|
+
return _safeJoinPathts.default;
|
|
96
|
+
},
|
|
94
97
|
get streamToString () {
|
|
95
98
|
return _streamToStringts.default;
|
|
96
99
|
},
|
|
@@ -113,6 +116,7 @@ var _crc32ts = require("./crc32.js");
|
|
|
113
116
|
var _EntryStreamts = /*#__PURE__*/ _interop_require_default(require("./EntryStream.js"));
|
|
114
117
|
var _Lockts = /*#__PURE__*/ _interop_require_default(require("./Lock.js"));
|
|
115
118
|
var _normalizePathts = /*#__PURE__*/ _interop_require_default(require("./normalizePath.js"));
|
|
119
|
+
var _safeJoinPathts = /*#__PURE__*/ _interop_require_default(require("./safeJoinPath.js"));
|
|
116
120
|
var _streamToStringts = /*#__PURE__*/ _interop_require_default(require("./streamToString.js"));
|
|
117
121
|
var _stripPathts = /*#__PURE__*/ _interop_require_default(require("./stripPath.js"));
|
|
118
122
|
function _interop_require_default(obj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nimport BufferList from './BufferList.ts';\n\nexport { BufferList };\n\n/**\n * Type alias for Buffer or BufferList - both can be read byte-by-byte.\n * Use this when an API should accept either contiguous data (Buffer)\n * or chunked streaming data (BufferList).\n */\nexport type BufferLike = Buffer | BufferList;\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n canAllocateBufferSize,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n MAX_SAFE_BUFFER_LENGTH,\n objectAssign,\n PassThrough,\n Readable,\n readUInt64LE,\n Transform,\n Writable,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\nexport { default as normalizePath } from './normalizePath.ts';\nexport { default as streamToString, type StreamToStringCallback } from './streamToString.ts';\nexport { default as stripPath } from './stripPath.ts';\n"],"names":["BufferList","EntryStream","Lock","MAX_SAFE_BUFFER_LENGTH","PassThrough","Readable","Transform","Writable","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","canAllocateBufferSize","crc32","crc32Region","createInflateRawStream","inflateRaw","isNaN","normalizePath","objectAssign","readUInt64LE","streamToString","stripPath","verifyCrc32","verifyCrc32Region","writeUInt64LE"],"mappings":"AAAA;;;;;;;;;;CAUC;;;;;;;;;;;QAIQA;eAAAA,qBAAU;;QA8BCC;eAAAA,sBAAW;;QACKC;eAAAA,eAAI;;QAXtCC;eAAAA,gCAAsB;;QAEtBC;eAAAA,qBAAW;;QACXC;eAAAA,kBAAQ;;QAERC;eAAAA,mBAAS;;QACTC;eAAAA,kBAAQ;;QAjBRC;eAAAA,qBAAW;;QACXC;eAAAA,2BAAiB;;QACjBC;eAAAA,uBAAa;;QACbC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,oBAAU;;QACVC;eAAAA,yBAAe;;QACfC;eAAAA,+BAAqB;;QAadC;eAAAA,cAAK;;QAAEC;eAAAA,oBAAW;;QAZzBC;eAAAA,gCAAsB;;QACtBC;eAAAA,oBAAU;;QACVC;eAAAA,eAAK;;QAaaC;eAAAA,wBAAa;;QAX/BC;eAAAA,sBAAY;;QAGZC;eAAAA,sBAAY;;QASMC;eAAAA,yBAAc;;QACdC;eAAAA,oBAAS;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nimport BufferList from './BufferList.ts';\n\nexport { BufferList };\n\n/**\n * Type alias for Buffer or BufferList - both can be read byte-by-byte.\n * Use this when an API should accept either contiguous data (Buffer)\n * or chunked streaming data (BufferList).\n */\nexport type BufferLike = Buffer | BufferList;\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n canAllocateBufferSize,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n MAX_SAFE_BUFFER_LENGTH,\n objectAssign,\n PassThrough,\n Readable,\n readUInt64LE,\n Transform,\n Writable,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\nexport { default as normalizePath } from './normalizePath.ts';\nexport { default as safeJoinPath } from './safeJoinPath.ts';\nexport { default as streamToString, type StreamToStringCallback } from './streamToString.ts';\nexport { default as stripPath } from './stripPath.ts';\n"],"names":["BufferList","EntryStream","Lock","MAX_SAFE_BUFFER_LENGTH","PassThrough","Readable","Transform","Writable","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","canAllocateBufferSize","crc32","crc32Region","createInflateRawStream","inflateRaw","isNaN","normalizePath","objectAssign","readUInt64LE","safeJoinPath","streamToString","stripPath","verifyCrc32","verifyCrc32Region","writeUInt64LE"],"mappings":"AAAA;;;;;;;;;;CAUC;;;;;;;;;;;QAIQA;eAAAA,qBAAU;;QA8BCC;eAAAA,sBAAW;;QACKC;eAAAA,eAAI;;QAXtCC;eAAAA,gCAAsB;;QAEtBC;eAAAA,qBAAW;;QACXC;eAAAA,kBAAQ;;QAERC;eAAAA,mBAAS;;QACTC;eAAAA,kBAAQ;;QAjBRC;eAAAA,qBAAW;;QACXC;eAAAA,2BAAiB;;QACjBC;eAAAA,uBAAa;;QACbC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,oBAAU;;QACVC;eAAAA,yBAAe;;QACfC;eAAAA,+BAAqB;;QAadC;eAAAA,cAAK;;QAAEC;eAAAA,oBAAW;;QAZzBC;eAAAA,gCAAsB;;QACtBC;eAAAA,oBAAU;;QACVC;eAAAA,eAAK;;QAaaC;eAAAA,wBAAa;;QAX/BC;eAAAA,sBAAY;;QAGZC;eAAAA,sBAAY;;QASMC;eAAAA,uBAAY;;QACZC;eAAAA,yBAAc;;QACdC;eAAAA,oBAAS;;QANAC;eAAAA,oBAAW;;QAAEC;eAAAA,0BAAiB;;QAFzDC;eAAAA,uBAAa;;;mEA7BQ;wBA8BhB;uBAC4D;oEAC5B;6DACS;sEACP;qEACD;uEAC+B;kEAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function safeJoinPath(dest: string, relPath: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function safeJoinPath(dest: string, relPath: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return safeJoinPath;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function safeJoinPath(dest, relPath) {
|
|
18
|
+
var resolvedDest = _path.default.resolve(dest);
|
|
19
|
+
var resolvedFull = _path.default.resolve(dest, relPath);
|
|
20
|
+
if (resolvedFull !== resolvedDest && !resolvedFull.startsWith(resolvedDest + _path.default.sep)) {
|
|
21
|
+
var err = new Error("Path traversal detected: '".concat(relPath, "' escapes destination '").concat(dest, "'"));
|
|
22
|
+
err.code = 'ETRAVERSAL';
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
return resolvedFull;
|
|
26
|
+
}
|
|
27
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/safeJoinPath.ts"],"sourcesContent":["import path from 'path';\n\nexport default function safeJoinPath(dest: string, relPath: string): string {\n const resolvedDest = path.resolve(dest);\n const resolvedFull = path.resolve(dest, relPath);\n if (resolvedFull !== resolvedDest && !resolvedFull.startsWith(resolvedDest + path.sep)) {\n const err = new Error(`Path traversal detected: '${relPath}' escapes destination '${dest}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n return resolvedFull;\n}\n"],"names":["safeJoinPath","dest","relPath","resolvedDest","path","resolve","resolvedFull","startsWith","sep","err","Error","code"],"mappings":";;;;+BAEA;;;eAAwBA;;;2DAFP;;;;;;AAEF,SAASA,aAAaC,IAAY,EAAEC,OAAe;IAChE,IAAMC,eAAeC,aAAI,CAACC,OAAO,CAACJ;IAClC,IAAMK,eAAeF,aAAI,CAACC,OAAO,CAACJ,MAAMC;IACxC,IAAII,iBAAiBH,gBAAgB,CAACG,aAAaC,UAAU,CAACJ,eAAeC,aAAI,CAACI,GAAG,GAAG;QACtF,IAAMC,MAAM,IAAIC,MAAM,AAAC,6BAA6DT,OAAjCC,SAAQ,2BAA8B,OAALD,MAAK;QACzFQ,IAAIE,IAAI,GAAG;QACX,MAAMF;IACR;IACA,OAAOH;AACT"}
|
|
@@ -5,6 +5,7 @@ import chmod from './fs/chmod.js';
|
|
|
5
5
|
import chown from './fs/chown.js';
|
|
6
6
|
import utimes from './fs/utimes.js';
|
|
7
7
|
import { objectAssign } from './shared/index.js';
|
|
8
|
+
import safeJoinPath from './shared/safeJoinPath.js';
|
|
8
9
|
import stripPath from './shared/stripPath.js';
|
|
9
10
|
import validateAttributes from './validateAttributes.js';
|
|
10
11
|
import waitForAccess from './waitForAccess.js';
|
|
@@ -20,7 +21,7 @@ let DirectoryEntry = class DirectoryEntry {
|
|
|
20
21
|
if (typeof callback === 'function') {
|
|
21
22
|
try {
|
|
22
23
|
const normalizedPath = path.normalize(this.path);
|
|
23
|
-
const fullPath =
|
|
24
|
+
const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));
|
|
24
25
|
// do not check for the existence of the directory but allow out-of-order calling
|
|
25
26
|
const queue = new Queue(1);
|
|
26
27
|
queue.defer(mkdirp.bind(null, fullPath));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/DirectoryEntry.ts"],"sourcesContent":["import mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { DirectoryAttributes, ExtractOptions, NoParamCallback } from './types.ts';\n\nexport default class DirectoryEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: DirectoryAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.type === undefined) this.type = 'directory';\n if (this.basename === undefined) this.basename = path.basename(this.path);\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/DirectoryEntry.ts"],"sourcesContent":["import mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { DirectoryAttributes, ExtractOptions, NoParamCallback } from './types.ts';\n\nexport default class DirectoryEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: DirectoryAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.type === undefined) this.type = 'directory';\n if (this.basename === undefined) this.basename = path.basename(this.path);\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n // do not check for the existence of the directory but allow out-of-order calling\n const queue = new Queue(1);\n queue.defer(mkdirp.bind(null, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["mkdirp","path","Queue","chmod","chown","utimes","objectAssign","safeJoinPath","stripPath","validateAttributes","waitForAccess","MANDATORY_ATTRIBUTES","DirectoryEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","queue","defer","bind","await","err","Promise","resolve","reject","done","destroy","attributes","type","undefined","basename"],"mappings":"AAAA,OAAOA,YAAY,iBAAiB;AACpC,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,YAAY,QAAQ,oBAAoB;AACjD,OAAOC,kBAAkB,2BAA2B;AACpD,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,wBAAwB,0BAA0B;AACzD,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,uBAAuB;IAAC;IAAQ;IAAS;CAAO;AAKvC,IAAA,AAAMC,iBAAN,MAAMA;IAiBnBC,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B,EAA2B;QACpHA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAA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|
|
7
7
|
import chown from './fs/chown.js';
|
|
8
8
|
import utimes from './fs/utimes.js';
|
|
9
9
|
import { objectAssign } from './shared/index.js';
|
|
10
|
+
import safeJoinPath from './shared/safeJoinPath.js';
|
|
10
11
|
import stripPath from './shared/stripPath.js';
|
|
11
12
|
import validateAttributes from './validateAttributes.js';
|
|
12
13
|
import waitForAccess from './waitForAccess.js';
|
|
@@ -22,7 +23,7 @@ let FileEntry = class FileEntry {
|
|
|
22
23
|
if (typeof callback === 'function') {
|
|
23
24
|
try {
|
|
24
25
|
const normalizedPath = path.normalize(this.path);
|
|
25
|
-
const fullPath =
|
|
26
|
+
const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));
|
|
26
27
|
const queue = new Queue(1);
|
|
27
28
|
if (options.force) {
|
|
28
29
|
queue.defer((callback)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import { rm } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/FileEntry.ts"],"sourcesContent":["import { rm } from 'fs-remove-compat';\nimport fs from 'graceful-fs';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, FileAttributes, NoParamCallback, WriteFileFn } from './types.ts';\n\ninterface AbstractFileEntry {\n _writeFile: WriteFileFn;\n}\n\nexport default class FileEntry {\n mode: Mode;\n mtime: number;\n path: string;\n basename: string;\n type: string;\n\n constructor(attributes: FileAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'file';\n if ((this as unknown as AbstractFileEntry)._writeFile === undefined) throw new Error('File this missing _writeFile. Please implement this method in your subclass');\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n } else {\n // Check if file exists - throw EEXIST if it does\n queue.defer((callback) => {\n fs.stat(fullPath, (err) => {\n if (!err) {\n const existsErr = new Error(`EEXIST: file already exists, open '${fullPath}'`) as NodeJS.ErrnoException;\n existsErr.code = 'EEXIST';\n existsErr.path = fullPath;\n return callback(existsErr);\n }\n // ENOENT means file doesn't exist - that's what we want\n if (err.code === 'ENOENT') return callback();\n // Other errors should be reported\n callback(err);\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer((this as unknown as AbstractFileEntry)._writeFile.bind(this, fullPath, options));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["rm","fs","mkdirp","path","Queue","chmod","chown","utimes","objectAssign","safeJoinPath","stripPath","validateAttributes","waitForAccess","MANDATORY_ATTRIBUTES","FileEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","queue","force","defer","err","code","stat","existsErr","Error","bind","dirname","_writeFile","await","Promise","resolve","reject","done","destroy","attributes","basename","undefined","type"],"mapp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kEntry.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { rm } from 'fs-remove-compat';
|
|
3
|
+
import isAbsolute from 'is-absolute';
|
|
3
4
|
import mkdirp from 'mkdirp-classic';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import Queue from 'queue-cb';
|
|
@@ -7,6 +8,7 @@ import chmod from './fs/chmod.js';
|
|
|
7
8
|
import chown from './fs/chown.js';
|
|
8
9
|
import utimes from './fs/utimes.js';
|
|
9
10
|
import { objectAssign } from './shared/index.js';
|
|
11
|
+
import safeJoinPath from './shared/safeJoinPath.js';
|
|
10
12
|
import stripPath from './shared/stripPath.js';
|
|
11
13
|
import validateAttributes from './validateAttributes.js';
|
|
12
14
|
import waitForAccess from './waitForAccess.js';
|
|
@@ -23,9 +25,14 @@ let LinkEntry = class LinkEntry {
|
|
|
23
25
|
if (typeof callback === 'function') {
|
|
24
26
|
try {
|
|
25
27
|
const normalizedPath = path.normalize(this.path);
|
|
26
|
-
const fullPath =
|
|
28
|
+
const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));
|
|
29
|
+
if (isAbsolute(this.linkpath)) {
|
|
30
|
+
const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`);
|
|
31
|
+
err.code = 'ETRAVERSAL';
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
27
34
|
const normalizedLinkpath = path.normalize(this.linkpath);
|
|
28
|
-
const linkFullPath =
|
|
35
|
+
const linkFullPath = safeJoinPath(dest, stripPath(normalizedLinkpath, options));
|
|
29
36
|
const queue = new Queue(1);
|
|
30
37
|
if (options.force) {
|
|
31
38
|
queue.defer((callback)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/LinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class LinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'link';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/LinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport utimes from './fs/utimes.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class LinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'link';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n if (isAbsolute(this.linkpath)) {\n const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n const normalizedLinkpath = path.normalize(this.linkpath);\n const linkFullPath = safeJoinPath(dest, stripPath(normalizedLinkpath, options));\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n queue.defer(waitForAccess.bind(null, linkFullPath)); // ensure target file is accessible before linking\n queue.defer(fs.link.bind(fs, linkFullPath, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath));\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(utimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["fs","rm","isAbsolute","mkdirp","path","Queue","chmod","chown","utimes","objectAssign","safeJoinPath","stripPath","validateAttributes","waitForAccess","MANDATORY_ATTRIBUTES","LinkEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","linkpath","err","Error","code","normalizedLinkpath","linkFullPath","queue","force","defer","bind","dirname","link","await","Promise","resolve","reject","done","destroy","attributes","basename","undefined","type"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,EAAE,QAAQ,mBAAmB;AACtC,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,WAAW,gBAAgB;AAClC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,YAAY,QAAQ,oBAAoB;AACjD,OAAOC,kBAAkB,2BAA2B;AACpD,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,wBAAwB,0BAA0B;AACzD,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,uBAAuB;IAAC;IAAQ;IAAS;IAAQ;CAAW;AAKnD,IAAA,AAAMC,YAAN,MAAMA;IAkBnBC,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B,EAA2B;QACpHA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,IAAI;gBACF,MAAMC,iBAAiBhB,KAAKiB,SAAS,CAAC,IAAI,CAACjB,IAAI;gBAC/C,MAAMkB,WAAWZ,aAAaO,MAAMN,UAAUS,gBAAgBF;gBAC9D,IAAIhB,WAAW,IAAI,CAACqB,QAAQ,GAAG;oBAC7B,MAAMC,MAAM,IAAIC,MAAM,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YAAY3B;QAC/BL,aAAa,IAAI,EAAEgC;QACnB,IAAI,IAAI,CAACC,QAAQ,KAAKC,WAAW,IAAI,CAACD,QAAQ,GAAGtC,KAAKsC,QAAQ,CAAC,IAAI,CAACtC,IAAI;QACxE,IAAI,IAAI,CAACwC,IAAI,KAAKD,WAAW,IAAI,CAACC,IAAI,GAAG;IAC3C;AA+CF;AA5DA,SAAqB7B,uBA4DpB"}
|
|
@@ -9,6 +9,7 @@ import chown from './fs/chown.js';
|
|
|
9
9
|
import lutimes from './fs/lutimes.js';
|
|
10
10
|
import symlinkWin32 from './fs/symlinkWin32.js';
|
|
11
11
|
import { objectAssign } from './shared/index.js';
|
|
12
|
+
import safeJoinPath from './shared/safeJoinPath.js';
|
|
12
13
|
import stripPath from './shared/stripPath.js';
|
|
13
14
|
import validateAttributes from './validateAttributes.js';
|
|
14
15
|
import waitForAccess from './waitForAccess.js';
|
|
@@ -26,14 +27,18 @@ let SymbolicLinkEntry = class SymbolicLinkEntry {
|
|
|
26
27
|
if (typeof callback === 'function') {
|
|
27
28
|
try {
|
|
28
29
|
const normalizedPath = path.normalize(this.path);
|
|
29
|
-
const fullPath =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
linkFullPath = path.join(dest, stripPath(linkRelativePath, options));
|
|
35
|
-
normalizedLinkpath = path.relative(path.dirname(fullPath), linkFullPath);
|
|
30
|
+
const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));
|
|
31
|
+
if (isAbsolute(this.linkpath)) {
|
|
32
|
+
const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`);
|
|
33
|
+
err.code = 'ETRAVERSAL';
|
|
34
|
+
throw err;
|
|
36
35
|
}
|
|
36
|
+
// Resolve the symlink target against the symlink's own directory and verify it
|
|
37
|
+
// stays within dest. safeJoinPath throws ETRAVERSAL if it escapes.
|
|
38
|
+
const targetAbs = path.resolve(path.dirname(fullPath), this.linkpath);
|
|
39
|
+
safeJoinPath(dest, path.relative(dest, targetAbs));
|
|
40
|
+
const normalizedLinkpath = path.relative(path.dirname(fullPath), targetAbs);
|
|
41
|
+
const linkFullPath = targetAbs;
|
|
37
42
|
const queue = new Queue(1);
|
|
38
43
|
if (options.force) {
|
|
39
44
|
queue.defer((callback)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/SymbolicLinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport lutimes from './fs/lutimes.ts';\nimport symlinkWin32 from './fs/symlinkWin32.ts';\nimport { objectAssign } from './shared/index.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class SymbolicLinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'symlink';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/SymbolicLinkEntry.ts"],"sourcesContent":["import fs from 'fs';\nimport { rm } from 'fs-remove-compat';\nimport isAbsolute from 'is-absolute';\nimport mkdirp from 'mkdirp-classic';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport chmod from './fs/chmod.ts';\nimport chown from './fs/chown.ts';\nimport lutimes from './fs/lutimes.ts';\nimport symlinkWin32 from './fs/symlinkWin32.ts';\nimport { objectAssign } from './shared/index.ts';\nimport safeJoinPath from './shared/safeJoinPath.ts';\nimport stripPath from './shared/stripPath.ts';\nimport validateAttributes from './validateAttributes.ts';\nimport waitForAccess from './waitForAccess.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst MANDATORY_ATTRIBUTES = ['mode', 'mtime', 'path', 'linkpath'];\n\nimport type { Mode } from 'fs';\nimport type { ExtractOptions, LinkAttributes, NoParamCallback } from './types.ts';\n\nexport default class SymbolicLinkEntry {\n mode: Mode;\n mtime: number;\n path: string;\n linkpath: string;\n basename: string;\n type: string;\n\n constructor(attributes: LinkAttributes) {\n validateAttributes(attributes, MANDATORY_ATTRIBUTES);\n objectAssign(this, attributes);\n if (this.basename === undefined) this.basename = path.basename(this.path);\n if (this.type === undefined) this.type = 'symlink';\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n try {\n const normalizedPath = path.normalize(this.path);\n const fullPath = safeJoinPath(dest, stripPath(normalizedPath, options));\n\n if (isAbsolute(this.linkpath)) {\n const err = new Error(`Absolute linkpath rejected: '${this.linkpath}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n // Resolve the symlink target against the symlink's own directory and verify it\n // stays within dest. safeJoinPath throws ETRAVERSAL if it escapes.\n const targetAbs = path.resolve(path.dirname(fullPath), this.linkpath);\n safeJoinPath(dest, path.relative(dest, targetAbs));\n const normalizedLinkpath = path.relative(path.dirname(fullPath), targetAbs);\n const linkFullPath = targetAbs;\n\n const queue = new Queue(1);\n if (options.force) {\n queue.defer((callback) => {\n rm(fullPath, (err) => {\n err && err.code !== 'ENOENT' ? callback(err) : callback();\n });\n });\n }\n queue.defer(mkdirp.bind(null, path.dirname(fullPath)));\n if (isWindows) queue.defer(symlinkWin32.bind(null, linkFullPath, normalizedLinkpath, fullPath));\n else queue.defer(fs.symlink.bind(fs, normalizedLinkpath, fullPath));\n queue.defer(waitForAccess.bind(null, fullPath, true)); // noFollow=true for symlinks\n queue.defer(chmod.bind(null, fullPath, this, options));\n queue.defer(chown.bind(null, fullPath, this, options));\n queue.defer(lutimes.bind(null, fullPath, this, options));\n queue.await(callback);\n } catch (err) {\n callback(err);\n }\n return;\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n destroy() {}\n}\n"],"names":["fs","rm","isAbsolute","mkdirp","path","Queue","chmod","chown","lutimes","symlinkWin32","objectAssign","safeJoinPath","stripPath","validateAttributes","waitForAccess","isWindows","process","platform","test","env","OSTYPE","MANDATORY_ATTRIBUTES","SymbolicLinkEntry","create","dest","options","callback","normalizedPath","normalize","fullPath","linkpath","err","Error","code","targetAbs","resolve","dirname","relative","normalizedLinkpath","linkFullPath","queue","force","defer","bind","symlink","await","Promise","reject","done","destroy","attributes","basename","undefined","type"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,EAAE,QAAQ,mBAAmB;AACtC,O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AAKC,WAAW,IAAI,CAACD,QAAQ,GAAG/C,KAAK+C,QAAQ,CAAC,IAAI,CAAC/C,IAAI;QACxE,IAAI,IAAI,CAACiD,IAAI,KAAKD,WAAW,IAAI,CAACC,IAAI,GAAG;IAC3C;AAoDF;AAjEA,SAAqB/B,+BAiEpB"}
|
|
@@ -22,5 +22,6 @@ export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
|
|
|
22
22
|
export { default as EntryStream } from './EntryStream.js';
|
|
23
23
|
export { type CleanupFn, default as Lock } from './Lock.js';
|
|
24
24
|
export { default as normalizePath } from './normalizePath.js';
|
|
25
|
+
export { default as safeJoinPath } from './safeJoinPath.js';
|
|
25
26
|
export { default as streamToString, type StreamToStringCallback } from './streamToString.js';
|
|
26
27
|
export { default as stripPath } from './stripPath.js';
|
package/dist/esm/shared/index.js
CHANGED
|
@@ -15,5 +15,6 @@ export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
|
|
|
15
15
|
export { default as EntryStream } from './EntryStream.js';
|
|
16
16
|
export { default as Lock } from './Lock.js';
|
|
17
17
|
export { default as normalizePath } from './normalizePath.js';
|
|
18
|
+
export { default as safeJoinPath } from './safeJoinPath.js';
|
|
18
19
|
export { default as streamToString } from './streamToString.js';
|
|
19
20
|
export { default as stripPath } from './stripPath.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nimport BufferList from './BufferList.ts';\n\nexport { BufferList };\n\n/**\n * Type alias for Buffer or BufferList - both can be read byte-by-byte.\n * Use this when an API should accept either contiguous data (Buffer)\n * or chunked streaming data (BufferList).\n */\nexport type BufferLike = Buffer | BufferList;\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n canAllocateBufferSize,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n MAX_SAFE_BUFFER_LENGTH,\n objectAssign,\n PassThrough,\n Readable,\n readUInt64LE,\n Transform,\n Writable,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\nexport { default as normalizePath } from './normalizePath.ts';\nexport { default as streamToString, type StreamToStringCallback } from './streamToString.ts';\nexport { default as stripPath } from './stripPath.ts';\n"],"names":["BufferList","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","canAllocateBufferSize","createInflateRawStream","inflateRaw","isNaN","MAX_SAFE_BUFFER_LENGTH","objectAssign","PassThrough","Readable","readUInt64LE","Transform","Writable","writeUInt64LE","crc32","crc32Region","verifyCrc32","verifyCrc32Region","default","EntryStream","Lock","normalizePath","streamToString","stripPath"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,OAAOA,gBAAgB,kBAAkB;AAEzC,SAASA,UAAU,GAAG;AAQtB,SACEC,WAAW,EACXC,iBAAiB,EACjBC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,UAAU,EACVC,eAAe,EACfC,qBAAqB,EACrBC,sBAAsB,EACtBC,UAAU,EACVC,KAAK,EACLC,sBAAsB,EACtBC,YAAY,EACZC,WAAW,EACXC,QAAQ,EACRC,YAAY,EACZC,SAAS,EACTC,QAAQ,EACRC,aAAa,QACR,cAAc;AACrB,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,aAAa;AAChF,SAASC,WAAWC,WAAW,QAAQ,mBAAmB;AAC1D,SAAyBD,WAAWE,IAAI,QAAQ,YAAY;AAC5D,SAASF,WAAWG,aAAa,QAAQ,qBAAqB;AAC9D,SAASH,WAAWI,cAAc,QAAqC,sBAAsB;AAC7F,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nimport BufferList from './BufferList.ts';\n\nexport { BufferList };\n\n/**\n * Type alias for Buffer or BufferList - both can be read byte-by-byte.\n * Use this when an API should accept either contiguous data (Buffer)\n * or chunked streaming data (BufferList).\n */\nexport type BufferLike = Buffer | BufferList;\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n canAllocateBufferSize,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n MAX_SAFE_BUFFER_LENGTH,\n objectAssign,\n PassThrough,\n Readable,\n readUInt64LE,\n Transform,\n Writable,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\nexport { default as normalizePath } from './normalizePath.ts';\nexport { default as safeJoinPath } from './safeJoinPath.ts';\nexport { default as streamToString, type StreamToStringCallback } from './streamToString.ts';\nexport { default as stripPath } from './stripPath.ts';\n"],"names":["BufferList","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","canAllocateBufferSize","createInflateRawStream","inflateRaw","isNaN","MAX_SAFE_BUFFER_LENGTH","objectAssign","PassThrough","Readable","readUInt64LE","Transform","Writable","writeUInt64LE","crc32","crc32Region","verifyCrc32","verifyCrc32Region","default","EntryStream","Lock","normalizePath","safeJoinPath","streamToString","stripPath"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,OAAOA,gBAAgB,kBAAkB;AAEzC,SAASA,UAAU,GAAG;AAQtB,SACEC,WAAW,EACXC,iBAAiB,EACjBC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,UAAU,EACVC,eAAe,EACfC,qBAAqB,EACrBC,sBAAsB,EACtBC,UAAU,EACVC,KAAK,EACLC,sBAAsB,EACtBC,YAAY,EACZC,WAAW,EACXC,QAAQ,EACRC,YAAY,EACZC,SAAS,EACTC,QAAQ,EACRC,aAAa,QACR,cAAc;AACrB,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,aAAa;AAChF,SAASC,WAAWC,WAAW,QAAQ,mBAAmB;AAC1D,SAAyBD,WAAWE,IAAI,QAAQ,YAAY;AAC5D,SAASF,WAAWG,aAAa,QAAQ,qBAAqB;AAC9D,SAASH,WAAWI,YAAY,QAAQ,oBAAoB;AAC5D,SAASJ,WAAWK,cAAc,QAAqC,sBAAsB;AAC7F,SAASL,WAAWM,SAAS,QAAQ,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function safeJoinPath(dest: string, relPath: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export default function safeJoinPath(dest, relPath) {
|
|
3
|
+
const resolvedDest = path.resolve(dest);
|
|
4
|
+
const resolvedFull = path.resolve(dest, relPath);
|
|
5
|
+
if (resolvedFull !== resolvedDest && !resolvedFull.startsWith(resolvedDest + path.sep)) {
|
|
6
|
+
const err = new Error(`Path traversal detected: '${relPath}' escapes destination '${dest}'`);
|
|
7
|
+
err.code = 'ETRAVERSAL';
|
|
8
|
+
throw err;
|
|
9
|
+
}
|
|
10
|
+
return resolvedFull;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/safeJoinPath.ts"],"sourcesContent":["import path from 'path';\n\nexport default function safeJoinPath(dest: string, relPath: string): string {\n const resolvedDest = path.resolve(dest);\n const resolvedFull = path.resolve(dest, relPath);\n if (resolvedFull !== resolvedDest && !resolvedFull.startsWith(resolvedDest + path.sep)) {\n const err = new Error(`Path traversal detected: '${relPath}' escapes destination '${dest}'`) as NodeJS.ErrnoException;\n err.code = 'ETRAVERSAL';\n throw err;\n }\n return resolvedFull;\n}\n"],"names":["path","safeJoinPath","dest","relPath","resolvedDest","resolve","resolvedFull","startsWith","sep","err","Error","code"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,eAAe,SAASC,aAAaC,IAAY,EAAEC,OAAe;IAChE,MAAMC,eAAeJ,KAAKK,OAAO,CAACH;IAClC,MAAMI,eAAeN,KAAKK,OAAO,CAACH,MAAMC;IACxC,IAAIG,iBAAiBF,gBAAgB,CAACE,aAAaC,UAAU,CAACH,eAAeJ,KAAKQ,GAAG,GAAG;QACtF,MAAMC,MAAM,IAAIC,MAAM,CAAC,0BAA0B,EAAEP,QAAQ,uBAAuB,EAAED,KAAK,CAAC,CAAC;QAC3FO,IAAIE,IAAI,GAAG;QACX,MAAMF;IACR;IACA,OAAOH;AACT"}
|