@contentstack/cli-utilities 1.8.3 → 1.9.0

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/lib/helpers.d.ts CHANGED
@@ -18,3 +18,10 @@ export declare const validateUids: (uid: any) => boolean;
18
18
  export declare const validateFileName: (fileName: any) => boolean;
19
19
  export declare const validateRegex: (str: unknown) => import("recheck").Diagnostics;
20
20
  export declare const formatError: (error: any) => any;
21
+ /**
22
+ * The function redactObject takes an object as input and replaces any sensitive keys with the string
23
+ * '[REDACTED]'.
24
+ * @param {any} obj - The `obj` parameter is an object that you want to redact sensitive information
25
+ * from.
26
+ */
27
+ export declare const redactObject: (obj: any) => any;
package/lib/helpers.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
3
+ exports.redactObject = exports.formatError = exports.validateRegex = exports.validateFileName = exports.validateUids = exports.sanitizePath = exports.escapeRegExp = exports.validatePath = exports.createDeveloperHubUrl = exports.isManagementTokenValid = exports.doesBranchExist = exports.isAuthenticated = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const recheck_1 = require("recheck");
6
+ const traverse_1 = tslib_1.__importDefault(require("traverse"));
6
7
  const auth_handler_1 = tslib_1.__importDefault(require("./auth-handler"));
7
8
  const _1 = require(".");
8
9
  const isAuthenticated = () => auth_handler_1.default.isAuthenticated();
@@ -62,7 +63,12 @@ exports.validatePath = validatePath;
62
63
  const escapeRegExp = (str) => str === null || str === void 0 ? void 0 : str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
63
64
  exports.escapeRegExp = escapeRegExp;
64
65
  // To remove the relative path
65
- const sanitizePath = (str) => str === null || str === void 0 ? void 0 : str.replace(/^(\.\.(\/|\\|$))+/, '');
66
+ const sanitizePath = (str) => {
67
+ if (typeof str !== 'string')
68
+ return;
69
+ const decodedStr = decodeURIComponent(str);
70
+ return decodedStr === null || decodedStr === void 0 ? void 0 : decodedStr.replace(/^([\/\\]){2,}/, "./").replace(/[\/\\]+/g, "/").replace(/(\.\.(\/|\\|$))+/g, ""); // Remove directory traversal (../ or ..\)
71
+ };
66
72
  exports.sanitizePath = sanitizePath;
67
73
  // To validate the UIDs of assets
68
74
  const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid);
@@ -137,3 +143,45 @@ const formatError = function (error) {
137
143
  return message;
138
144
  };
139
145
  exports.formatError = formatError;
146
+ /**
147
+ * The function checks if a given key string matches any of the sensitive keys defined in an array.
148
+ * @param {string} keyStr - The parameter `keyStr` is a string that represents a key.
149
+ * @returns a boolean value. It returns true if the keyStr matches any of the regular expressions in
150
+ * the sensitiveKeys array, and false otherwise.
151
+ */
152
+ const isSensitiveKey = function (keyStr) {
153
+ if (keyStr && typeof keyStr === 'string') {
154
+ return sensitiveKeys.some((regex) => regex.test(keyStr));
155
+ }
156
+ };
157
+ /**
158
+ * The function redactObject takes an object as input and replaces any sensitive keys with the string
159
+ * '[REDACTED]'.
160
+ * @param {any} obj - The `obj` parameter is an object that you want to redact sensitive information
161
+ * from.
162
+ */
163
+ const redactObject = function (obj) {
164
+ (0, traverse_1.default)(obj).forEach(function redactor() {
165
+ // Check if the current key is sensitive
166
+ if (isSensitiveKey(this.key)) {
167
+ // Update the current value with '[REDACTED]'
168
+ this.update('[REDACTED]');
169
+ }
170
+ });
171
+ return obj;
172
+ };
173
+ exports.redactObject = redactObject;
174
+ /* The `sensitiveKeys` array is used to store regular expressions that match sensitive keys. These
175
+ keys are used to redact sensitive information from log messages. When logging an object, any keys
176
+ that match the regular expressions in the `sensitiveKeys` array will be replaced with the string
177
+ '[REDACTED]'. This helps to prevent sensitive information from being logged or displayed. */
178
+ const sensitiveKeys = [
179
+ /authtoken/i,
180
+ /^email$/,
181
+ /^password$/i,
182
+ /secret/i,
183
+ /token/i,
184
+ /api[-._]?key/i,
185
+ /management[-._]?token/i,
186
+ /delivery[-._]?token/i,
187
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.8.3",
3
+ "version": "1.9.0",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "@contentstack/management": "~1.18.4",
36
36
  "@contentstack/marketplace-sdk": "^1.2.5",
37
37
  "@oclif/core": "^3.27.0",
38
- "axios": "^1.7.9",
38
+ "axios": "^1.8.2",
39
39
  "chalk": "^4.1.2",
40
40
  "cli-cursor": "^3.1.0",
41
41
  "cli-table": "^0.3.11",