jscrambler
Advanced tools
Comparing version 8.7.1-next.3 to 8.7.1
# jscrambler | ||
## 8.7.1-next.3 | ||
## 8.7.1 | ||
### Patch Changes | ||
- []: Only parse js files | ||
- [3ef818f]: Update readme.md | ||
## 8.7.1-next.2 | ||
### Patch Changes | ||
- []: Add filename on webpack-ignore-vendors | ||
## 8.7.1-next.1 | ||
### Patch Changes | ||
- [ecba0c7]: new beforeProtection type: webpack-ignore-vendors | ||
## 8.7.0 | ||
@@ -22,0 +10,0 @@ |
@@ -13,3 +13,2 @@ #!/usr/bin/env node | ||
var _utils = require("../utils"); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
@@ -71,79 +70,49 @@ 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; } | ||
} | ||
const mandatoryKeys = ['type', 'target', 'source']; | ||
const usedTargets = new Set(); | ||
const usedSources = new Set(); | ||
beforeProtectionArray.filter(element => { | ||
// Check if every array element has a type, a target and a source | ||
const validateMandatoryKeys = mandatoryKeys.every(key => key in element); | ||
if (!validateMandatoryKeys) { | ||
console.error('Invalid structure on beforeProtection: each element must have the following structure { type: "type", target: "/path/to/target", source: "/path/to/script"}'); | ||
process.exit(1); | ||
} | ||
const { | ||
target, | ||
source, | ||
type | ||
} = element; | ||
switch (type) { | ||
case _utils.APPEND_JS_TYPE: | ||
case _utils.PREPEND_JS_TYPE: | ||
const mandatoryKeys = ['type', 'target', 'source']; | ||
const usedTargets = new Set(); | ||
const usedSources = new Set(); | ||
// Check if every array element has a type, a target and a source | ||
const validateMandatoryKeys = mandatoryKeys.every(key => key in element); | ||
if (!validateMandatoryKeys) { | ||
console.error('Invalid structure on beforeProtection: each element must have the following structure { type: "type", target: "/path/to/target", source: "/path/to/script"}'); | ||
process.exit(1); | ||
} | ||
const { | ||
target, | ||
source | ||
} = element; | ||
// Check if only valid types are being used | ||
if (type !== _utils.APPEND_JS_TYPE && type !== _utils.PREPEND_JS_TYPE) { | ||
console.error("Invalid type on beforeProtection: only \"".concat(_utils.APPEND_JS_TYPE, "\" or \"").concat(_utils.PREPEND_JS_TYPE, "\" are allowed.")); | ||
process.exit(1); | ||
} | ||
// Check if the provided files are js, mjs or cjs files | ||
if (!(0, _utils.isJavascriptFile)(target) || !(0, _utils.isJavascriptFile)(source)) { | ||
console.error("Invalid extension for beforeProtection (".concat(type, ") target or source files: only *js, mjs and cjs* files can be used to append or prepend.")); | ||
process.exit(1); | ||
} | ||
// Check if the provided files are js, mjs or cjs files | ||
if (!(0, _utils.isJavascriptFile)(target) || !(0, _utils.isJavascriptFile)(source)) { | ||
console.error('Invalid extension for beforeProtection target or source files: only *js, mjs and cjs* files can be used to append or prepend.'); | ||
process.exit(1); | ||
} | ||
// Check if the target has already been used as a source | ||
if (usedTargets.has(source)) { | ||
console.error("Error on beforeProtection (".concat(type, "): file \"").concat(source, "\" has already been used as target and can't be used as source.")); | ||
process.exit(1); | ||
} | ||
if (usedSources.has(target)) { | ||
console.error("Error on beforeProtection (".concat(type, "): file \"").concat(target, "\" has already been used as source and can't be used as target.")); | ||
process.exit(1); | ||
} | ||
// Check if the target has already been used as a source | ||
if (usedTargets.has(source)) { | ||
console.error("Error on beforeProtection: file \"".concat(source, "\" has already been used as target and can't be used as source.")); | ||
process.exit(1); | ||
} | ||
if (usedSources.has(target)) { | ||
console.error("Error on beforeProtection: file \"".concat(target, "\" has already been used as source and can't be used as target.")); | ||
process.exit(1); | ||
} | ||
// Check if the target and source are the same | ||
if (target === source) { | ||
console.error("Error on beforeProtection (".concat(type, "): File \"").concat(target, "\" can't be used as both a target and a source.")); | ||
process.exit(1); | ||
} | ||
// Check if the target and source are the same | ||
if (target === source) { | ||
console.error("Error on beforeProtection: File \"".concat(target, "\" can't be used as both a target and a source.")); | ||
process.exit(1); | ||
} | ||
// Add the target and the source to the corresponding sets | ||
usedTargets.add(target); | ||
usedSources.add(source); | ||
break; | ||
case _utils.WEBPACK_IGNORE_VENDORS: | ||
if (!("report" in element)) { | ||
console.error("Invalid structure on beforeProtection (".concat(type, "): \"report\" property is mandatory for this type")); | ||
process.exit(1); | ||
} | ||
if (!_fs.default.existsSync(element.report)) { | ||
console.error("Error on beforeProtection (".concat(type, "): source webpack report does not exist.")); | ||
process.exit(1); | ||
} | ||
const content = _fs.default.readFileSync(element.report, 'utf8'); | ||
let report; | ||
try { | ||
report = JSON.parse(content); | ||
} catch (e) { | ||
console.error("Error on beforeProtection (".concat(type, "): invalid source webpack report. Reason: ").concat(e.message)); | ||
process.exit(1); | ||
} | ||
element.excludeModules = new Map(); | ||
for (let module of report.modules) { | ||
if (module.name && module.name.includes('/node_modules/')) { | ||
element.excludeModules.set(module.id, module.name); | ||
} | ||
} | ||
console.log("beforeProtection (".concat(type, "): Webpack report \"").concat(_path.default.basename(element.report), "\" was loaded")); | ||
break; | ||
default: | ||
console.error("Invalid type on beforeProtection (".concat(type, "): only \"").concat(_utils.APPEND_JS_TYPE, "\", \"").concat(_utils.PREPEND_JS_TYPE, "\" or \"").concat(_utils.WEBPACK_IGNORE_VENDORS, "\" are allowed.")); | ||
process.exit(1); | ||
} | ||
// Add the target and the source to the corresponding sets | ||
usedTargets.add(target); | ||
usedSources.add(source); | ||
}); | ||
@@ -150,0 +119,0 @@ return beforeProtectionArray; |
@@ -153,3 +153,3 @@ "use strict"; | ||
runBeforeProtection.map(element => { | ||
if ((element.type === _utils.PREPEND_JS_TYPE || element.type === _utils.APPEND_JS_TYPE) && !_filesSrc.includes(element.target)) { | ||
if (!_filesSrc.includes(element.target)) { | ||
console.error('Error on beforeProtection: Target files need to be in the files to protect list (or filesSrc).'); | ||
@@ -156,0 +156,0 @@ process.exit(1); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.WEBPACK_IGNORE_VENDORS = exports.PREPEND_JS_TYPE = exports.APPEND_JS_TYPE = void 0; | ||
exports.PREPEND_JS_TYPE = exports.APPEND_JS_TYPE = void 0; | ||
exports.concatenate = concatenate; | ||
@@ -12,13 +12,6 @@ exports.getMatchedFiles = getMatchedFiles; | ||
exports.validateNProtections = validateNProtections; | ||
exports.webpackAttachDisableAnnotations = webpackAttachDisableAnnotations; | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
var _glob = require("glob"); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _path = require("path"); | ||
var _acorn = _interopRequireDefault(require("acorn")); | ||
var _acornWalk = _interopRequireDefault(require("acorn-walk")); | ||
var _magicString = _interopRequireDefault(require("magic-string")); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
const debug = !!process.env.DEBUG; | ||
/** | ||
@@ -53,74 +46,5 @@ * Return the list of matched files for minimatch patterns. | ||
const PREPEND_JS_TYPE = exports.PREPEND_JS_TYPE = 'prepend-js'; | ||
const WEBPACK_IGNORE_VENDORS = exports.WEBPACK_IGNORE_VENDORS = 'webpack-ignore-vendors'; | ||
/** | ||
* | ||
* @param {source: string} beforeProtection | ||
* @param {string} cwd current working directory, passed by argument | ||
* @param {string} path file path (file being parsed) | ||
* @param {Buffer} buffer file contents | ||
* @param {string} fileName file name | ||
*/ | ||
function webpackAttachDisableAnnotations(beforeProtection, cwd, path, buffer, fileName) { | ||
if (!isJavascriptFile(fileName)) { | ||
return buffer; | ||
} | ||
const { | ||
excludeModules | ||
} = beforeProtection; | ||
const sourceCode = buffer.toString('utf-8'); | ||
let tree; | ||
try { | ||
tree = _acorn.default.parse(sourceCode, { | ||
ecmaVersion: 'latest', | ||
range: true | ||
}); | ||
} catch (e) { | ||
console.log("Error on beforeProtection (".concat(WEBPACK_IGNORE_VENDORS, "): \"").concat(fileName, "\" could not be parsed.")); | ||
process.exit(1); | ||
} | ||
const appendDisableAnnotationAt = []; | ||
_acornWalk.default.recursive(tree, null, { | ||
Property(node) { | ||
if (node.computed === false && node.shorthand === false) { | ||
let moduleId; | ||
if (node.key.type === 'Literal') { | ||
moduleId = node.key.value; | ||
} else if (node.key.type === 'Identifier') { | ||
moduleId = node.key.name; | ||
} | ||
if (moduleId && excludeModules.has(moduleId)) { | ||
appendDisableAnnotationAt.push(node.value.start); | ||
if (debug) { | ||
console.debug("beforeProtection (".concat(WEBPACK_IGNORE_VENDORS, "): ignoring ").concat(excludeModules.get(moduleId), " module on \"").concat(fileName, "\"")); | ||
} | ||
return null; | ||
} | ||
} | ||
} | ||
}); | ||
if (appendDisableAnnotationAt.length > 0) { | ||
const s = new _magicString.default(sourceCode); | ||
for (const appendIndex of appendDisableAnnotationAt) { | ||
s.appendLeft(appendIndex, '/* @jscrambler disable * */'); | ||
} | ||
const sourceCodeWithDisableAnnotations = s.toString(); | ||
try { | ||
// syntax check | ||
_acorn.default.parse(sourceCodeWithDisableAnnotations, { | ||
ecmaVersion: 'latest', | ||
range: true | ||
}); | ||
} catch (e) { | ||
console.log("Error on beforeProtection (".concat(WEBPACK_IGNORE_VENDORS, "): unsupported structure on \"").concat(fileName, "\".")); | ||
process.exit(1); | ||
} | ||
buffer = Buffer.from(s.toString(), 'utf8'); | ||
} | ||
console.log("beforeProtection (".concat(WEBPACK_IGNORE_VENDORS, "): ").concat(appendDisableAnnotationAt.length, " module(s) ignored for \"").concat(fileName, "\"")); | ||
return buffer; | ||
} | ||
/** | ||
* | ||
* @param {*} firstFile if prepending: script file; if appending: target file. | ||
@@ -127,0 +51,0 @@ * @param {*} secondFile if prepending: target file; if appending: script file. |
@@ -69,13 +69,5 @@ "use strict"; | ||
} | ||
buffer = await fs.readFile(sPath); | ||
buffer = fs.readFile(sPath); | ||
runBeforeProtection.map(element => { | ||
switch (element.type) { | ||
case _utils.APPEND_JS_TYPE: | ||
case _utils.PREPEND_JS_TYPE: | ||
buffer = (0, _utils.concatenate)(element, cwd, sPath, buffer, name); | ||
break; | ||
case _utils.WEBPACK_IGNORE_VENDORS: | ||
buffer = (0, _utils.webpackAttachDisableAnnotations)(element, cwd, sPath, buffer, name); | ||
break; | ||
} | ||
buffer = (0, _utils.concatenate)(element, cwd, sPath, buffer); | ||
}); | ||
@@ -82,0 +74,0 @@ } else { |
{ | ||
"name": "jscrambler", | ||
"description": "Jscrambler API client.", | ||
"version": "8.7.1-next.3", | ||
"description": "Jscrambler Code Integrity API client.", | ||
"version": "8.7.1", | ||
"homepage": "https://github.com/jscrambler/jscrambler", | ||
@@ -20,10 +20,2 @@ "author": "Jscrambler <support@jscrambler.com>", | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf ./dist", | ||
"build": "babel src --out-dir dist", | ||
"watch": "babel -w src --out-dir dist", | ||
"prepublish": "npm run build", | ||
"eslint": "eslint src/", | ||
"eslint:fix": "eslint src/ --fix" | ||
}, | ||
"engines": { | ||
@@ -33,5 +25,2 @@ "node": ">= 12.17.0" | ||
"dependencies": { | ||
"acorn": "8.14.0", | ||
"acorn-walk": "8.3.4", | ||
"magic-string": "0.30.15", | ||
"axios": "^1.7.7", | ||
@@ -72,3 +61,11 @@ "commander": "^2.8.1", | ||
"javascript" | ||
] | ||
} | ||
], | ||
"scripts": { | ||
"clean": "rm -rf ./dist", | ||
"build": "babel src --out-dir dist", | ||
"watch": "babel -w src --out-dir dist", | ||
"prepublish": "npm run build", | ||
"eslint": "eslint src/", | ||
"eslint:fix": "eslint src/ --fix" | ||
} | ||
} |
# [![Jscrambler](https://media.jscrambler.com/images/logo_500px.png)](https://jscrambler.com/?utm_source=github.com&utm_medium=referral) | ||
Jscrambler Client for Browser and Node.js | ||
Jscrambler Code Integrity Client | ||
-------------------- | ||
Jscrambler [Code Integrity](https://jscrambler.com/code-integrity) is a JavaScript protection technology for Web and Mobile Applications. Its main purpose is to enable JavaScript applications to become self-defensive and resilient to tampering and reverse engineering. | ||
If you're looking to gain control over third-party tags and achieve PCI DSS compliance please refer to Jscrambler [Webpage Integrity](https://jscrambler.com/webpage-integrity). | ||
- [Jscrambler](https://jscrambler.com/?utm_source=github.com&utm_medium=referral) | ||
@@ -357,6 +363,2 @@ - [Version Compatibility](#version-compatibility) | ||
"source": "/path/to/script/file.js" | ||
}, | ||
{ | ||
"type": "webpack-ignore-vendors", | ||
"report": "/path/to/webpack/stats.json" | ||
} | ||
@@ -363,0 +365,0 @@ ] |
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
14
0
100
0
439
13
135957
17
2736
- Removedacorn@8.14.0
- Removedacorn-walk@8.3.4
- Removedmagic-string@0.30.15
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedmagic-string@0.30.15(transitive)