jscrambler 8.11.2 → 8.12.0-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # jscrambler
2
2
 
3
+ ## 8.12.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [83c2f6f]: Added suport for new code hardening
8
+
9
+ ## 8.11.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [25054ca]: Ensure protected files are not written outside of project root folder in gulp
14
+
3
15
  ## 8.11.2
4
16
 
5
17
  ### Patch Changes
@@ -198,6 +198,12 @@ try {
198
198
  console.error(err.message);
199
199
  process.exit(1);
200
200
  }
201
+ try {
202
+ config.codeHardening = (0, _utils.validateCodeHardening)(config.codeHardening);
203
+ } catch (err) {
204
+ console.error(err.message);
205
+ process.exit(1);
206
+ }
201
207
  // Merge file config with CLI `--custom-label` flags (CLI wins on duplicate keys)
202
208
  config.customLabels = _objectSpread(_objectSpread({}, config.customLabels), _commander.default.customLabel || {});
203
209
  if (Object.keys(config.customLabels).length === 0) {
@@ -290,6 +296,7 @@ const {
290
296
  debugMode,
291
297
  proxy,
292
298
  codeHardeningThreshold,
299
+ codeHardening,
293
300
  useProfilingData,
294
301
  profilingDataMode,
295
302
  browsers,
@@ -436,6 +443,7 @@ if (_commander.default.balance) {
436
443
  tolerateMinification,
437
444
  debugMode,
438
445
  codeHardeningThreshold,
446
+ codeHardening,
439
447
  useProfilingData,
440
448
  profilingDataMode,
441
449
  browsers,
@@ -19,6 +19,6 @@ function cleanupInputFields(args, fragments) {
19
19
  console.warn("Warning: This API Version does not support the '".concat(field, "' argument."));
20
20
  }
21
21
  }
22
- ['tolerateMinification', 'useProfilingData', 'useAppClassification', 'inputSymbolTable', 'entryPoint', 'ensureCodeAnnotation', 'generateAlias', 'customLabels'].forEach(fieldCleanUp);
22
+ ['tolerateMinification', 'useProfilingData', 'useAppClassification', 'inputSymbolTable', 'entryPoint', 'ensureCodeAnnotation', 'generateAlias', 'customLabels', 'codeHardening'].forEach(fieldCleanUp);
23
23
  return [options, cleanedUpFragments];
24
24
  }
package/dist/constants.js CHANGED
@@ -20,6 +20,7 @@ const CLIENT_IDS = exports.CLIENT_IDS = Object.freeze({
20
20
  WEBPACK: 2,
21
21
  GULP: 3,
22
22
  GRUNT: 4,
23
+ /* @deprecated */
23
24
  EMBER: 5,
24
25
  METRO: 6
25
26
  });
@@ -29,6 +30,7 @@ const CLIENT_PACKAGES = exports.CLIENT_PACKAGES = Object.freeze({
29
30
  [CLIENT_IDS.WEBPACK]: 'jscrambler-webpack-plugin',
30
31
  [CLIENT_IDS.GULP]: 'gulp-jscrambler',
31
32
  [CLIENT_IDS.GRUNT]: 'grunt-jscrambler',
33
+ /* @deprecated */
32
34
  [CLIENT_IDS.EMBER]: 'ember-cli-jscrambler',
33
35
  [CLIENT_IDS.METRO]: 'jscrambler-metro-plugin'
34
36
  });
package/dist/index.js CHANGED
@@ -112,6 +112,7 @@ function buildFinalConfig(configPathOrObject) {
112
112
  var _default = exports.default = {
113
113
  Client: _client.default,
114
114
  config: _config2.default,
115
+ resolveOutputPath: _utils.resolveOutputPath,
115
116
  queries,
116
117
  generateSignedParams: _generateSignedParams.default,
117
118
  /**
@@ -273,6 +274,7 @@ var _default = exports.default = {
273
274
  clientId,
274
275
  tolerateMinification,
275
276
  codeHardeningThreshold,
277
+ codeHardening,
276
278
  useProfilingData,
277
279
  browsers,
278
280
  useAppClassification,
@@ -328,6 +330,7 @@ var _default = exports.default = {
328
330
  if (!filesDest && !destCallback) {
329
331
  throw new Error('Required *filesDest* not provided');
330
332
  }
333
+ const normalizedCodeHardening = (0, _utils.validateCodeHardening)(codeHardening);
331
334
  let source;
332
335
  if (!skipSources) {
333
336
  const appProfiling = await this.getApplicationProfiling(client, applicationId).catch(e => {
@@ -367,6 +370,9 @@ var _default = exports.default = {
367
370
  tolerateMinification,
368
371
  codeHardeningThreshold
369
372
  };
373
+ if (typeof normalizedCodeHardening !== 'undefined') {
374
+ updateData.codeHardening = normalizedCodeHardening;
375
+ }
370
376
  if (params && Object.keys(params).length) {
371
377
  updateData.parameters = normalizeParameters(params);
372
378
  updateData.areSubscribersOrdered = Array.isArray(params);
package/dist/utils.js CHANGED
@@ -7,6 +7,8 @@ exports.PREPEND_JS_TYPE = exports.APPEND_JS_TYPE = void 0;
7
7
  exports.concatenate = concatenate;
8
8
  exports.getMatchedFiles = getMatchedFiles;
9
9
  exports.isJavascriptFile = isJavascriptFile;
10
+ exports.resolveOutputPath = resolveOutputPath;
11
+ exports.validateCodeHardening = validateCodeHardening;
10
12
  exports.validateCustomLabels = validateCustomLabels;
11
13
  exports.validateNProtections = validateNProtections;
12
14
  exports.validateThresholdFn = void 0;
@@ -16,6 +18,11 @@ var _fs = _interopRequireDefault(require("fs"));
16
18
  var _path = require("path");
17
19
  var _filesizeParser = _interopRequireDefault(require("filesize-parser"));
18
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
25
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
26
  /**
20
27
  * Return the list of matched files for minimatch patterns.
21
28
  * @param {string} pattern
@@ -70,6 +77,22 @@ function validateCustomLabels(customLabels) {
70
77
  }
71
78
  return out;
72
79
  }
80
+
81
+ /**
82
+ * Validate protection `codeHardening` is a plain object; API validates contents.
83
+ * @param {*} codeHardening From config or programmatic options.
84
+ * @returns {object|undefined} A shallow copy when valid; `undefined` when omitted.
85
+ * @throws {Error} If `codeHardening` is present but not a plain object.
86
+ */
87
+ function validateCodeHardening(codeHardening) {
88
+ if (typeof codeHardening === 'undefined') {
89
+ return undefined;
90
+ }
91
+ if (codeHardening === null || typeof codeHardening !== 'object' || Array.isArray(codeHardening)) {
92
+ throw new Error('Invalid *codeHardening*: expected a plain object.');
93
+ }
94
+ return _objectSpread({}, codeHardening);
95
+ }
73
96
  const APPEND_JS_TYPE = exports.APPEND_JS_TYPE = 'append-js';
74
97
  const PREPEND_JS_TYPE = exports.PREPEND_JS_TYPE = 'prepend-js';
75
98
 
@@ -128,4 +151,13 @@ const validateThresholdFn = optionName => val => {
128
151
  }
129
152
  return inBytes;
130
153
  };
131
- exports.validateThresholdFn = validateThresholdFn;
154
+ exports.validateThresholdFn = validateThresholdFn;
155
+ function resolveOutputPath(outputPath, filename) {
156
+ const outputRoot = (0, _path.resolve)(outputPath);
157
+ const finalPath = (0, _path.resolve)(outputRoot, filename);
158
+ const relativePath = (0, _path.relative)(outputRoot, finalPath);
159
+ if (relativePath === '..' || relativePath.indexOf("..".concat(_path.sep)) === 0 || (0, _path.isAbsolute)(relativePath)) {
160
+ throw new Error("Refusing to write file outside output directory: ".concat(filename));
161
+ }
162
+ return finalPath;
163
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jscrambler",
3
3
  "description": "Jscrambler Code Integrity API client.",
4
- "version": "8.11.2",
4
+ "version": "8.12.0-next.0",
5
5
  "homepage": "https://github.com/jscrambler/jscrambler",
6
6
  "author": "Jscrambler <support@jscrambler.com>",
7
7
  "repository": {
@@ -61,6 +61,7 @@
61
61
  "clean": "rm -rf ./dist",
62
62
  "build": "babel src --out-dir dist",
63
63
  "watch": "babel -w src --out-dir dist",
64
+ "test": "pnpm run build && node test/output-path.js",
64
65
  "prepublish": "npm run build",
65
66
  "eslint": "eslint src/",
66
67
  "eslint:fix": "eslint src/ --fix"