@ezs/basics 1.23.0 → 1.23.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,34 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.23.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.1...@ezs/basics@1.23.2) (2023-02-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * 🐛 timeout never closed ([0c8597a](https://github.com/Inist-CNRS/ezs/commit/0c8597a11db0c3689a34888a1fd3e7807cc975db))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.23.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.0...@ezs/basics@1.23.1) (2023-01-28)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * 🐛 improve security in file access ([6942a8e](https://github.com/Inist-CNRS/ezs/commit/6942a8e039a05d820d8643fa0908287a0a6aefda))
23
+ * 🐛 objstandarize lost boolean values ([dca4714](https://github.com/Inist-CNRS/ezs/commit/dca4714c984214f422f9ed8951575de66af0f0ce))
24
+
25
+
26
+ ### Reverts
27
+
28
+ * Revert "chore: 🤖 use lerna exec instead bootstrap" ([56375ee](https://github.com/Inist-CNRS/ezs/commit/56375ee2bd7e9f69f61da3993ab569ca1c16c547))
29
+
30
+
31
+
32
+
33
+
6
34
  # [1.23.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.7...@ezs/basics@1.23.0) (2023-01-20)
7
35
 
8
36
 
package/lib/file-load.js CHANGED
@@ -13,6 +13,10 @@ var _path = require("path");
13
13
 
14
14
  var _os = require("os");
15
15
 
16
+ var _higherPath = _interopRequireDefault(require("higher-path"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
16
20
  /**
17
21
  * Take `Object` containing filename et throw content by chunk
18
22
  *
@@ -52,18 +56,19 @@ async function FILELoad(data, feed) {
52
56
  return;
53
57
  }
54
58
 
55
- const cwd = process.cwd();
56
- const tpd = (0, _os.tmpdir)();
57
59
  const compress = this.getParam('compress', false);
58
- const locations = this.ezs.getPath().concat(cwd, tpd, this.getParam('location'));
59
- const file = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
60
+ const location = (0, _path.normalize)(this.getParam('location', '/'));
61
+ const locations = [(0, _higherPath.default)((0, _os.tmpdir)(), location), (0, _higherPath.default)(process.cwd(), location)];
62
+ const filename = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
60
63
 
61
- if (!file) {
62
- feed.end();
64
+ if (!filename) {
65
+ feed.stop(new Error('File location check failed.'));
63
66
  return;
64
67
  }
65
68
 
66
- const stream = compress ? (0, _fs.createReadStream)(file).pipe((0, _zlib.createGunzip)()) : (0, _fs.createReadStream)(file);
69
+ (0, _fs.accessSync)((0, _path.dirname)(filename), _fs.constants.R_OK | _fs.constants.W_OK);
70
+ (0, _fs.accessSync)(filename, _fs.constants.R_OK | _fs.constants.W_OK);
71
+ const stream = compress ? (0, _fs.createReadStream)(filename).pipe((0, _zlib.createGunzip)()) : (0, _fs.createReadStream)(filename);
67
72
  await feed.flow(stream);
68
73
  return;
69
74
  }
package/lib/file-save.js CHANGED
@@ -68,13 +68,21 @@ const toJSONL = line => JSON.stringify(line).concat(eol);
68
68
  function FILESave(data, feed) {
69
69
  if (this.isFirst()) {
70
70
  const identifier = String(this.getParam('identifier'));
71
- const location = this.getParam('location', (0, _os.tmpdir)());
71
+
72
+ const location = _path.default.normalize(this.getParam('location', (0, _os.tmpdir)()));
73
+
72
74
  const compress = this.getParam('compress', false);
73
75
 
76
+ if (location.indexOf((0, _os.tmpdir)()) !== 0 && location.indexOf(process.cwd()) !== 0) {
77
+ feed.stop(new Error('File location check failed.'));
78
+ return;
79
+ }
80
+
74
81
  if (!_pathExists.default.sync(location)) {
75
82
  _makeDir.default.sync(location);
76
83
  }
77
84
 
85
+ (0, _fs.accessSync)(location, _fs.constants.R_OK | _fs.constants.W_OK);
78
86
  const name = compress ? `${identifier}.gz` : identifier;
79
87
 
80
88
  const filename = _path.default.resolve(location, name);
@@ -21,7 +21,7 @@ function normalize(data, feed) {
21
21
  const struct = this.getEnv();
22
22
  const vv = {};
23
23
  struct.forEach(k => {
24
- if (!data[k]) {
24
+ if (data[k] === undefined || data[k] === null) {
25
25
  vv[k] = '';
26
26
  } else {
27
27
  vv[k] = data[k];
@@ -109,6 +109,7 @@ async function URLConnect(data, feed) {
109
109
  bodyOut.pipe(output);
110
110
  } else {
111
111
  const bodyOutRaw = await (0, _getStream.default)(response.body);
112
+ clearTimeout(timeoutHandle);
112
113
 
113
114
  if (json) {
114
115
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
3
  "description": "Basics statements for EZS",
4
- "version": "1.23.0",
4
+ "version": "1.23.2",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -13,6 +13,7 @@
13
13
  "fetch-with-proxy": "3.0.1",
14
14
  "flat": "5.0.2",
15
15
  "get-stream": "6.0.1",
16
+ "higher-path": "1.0.0",
16
17
  "lodash.escaperegexp": "4.1.2",
17
18
  "lodash.get": "4.4.2",
18
19
  "lodash.mapkeys": "4.6.0",
@@ -37,7 +38,7 @@
37
38
  "directories": {
38
39
  "test": "test"
39
40
  },
40
- "gitHead": "20ec5a02e63dfff4859d64e96cd5e2bb05e48504",
41
+ "gitHead": "78a03050c3106e54a2a10c70ea67091b8b1ee711",
41
42
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
42
43
  "keywords": [
43
44
  "ezs"