jso-protector 0.4.14 → 0.4.16
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 +25 -0
- package/README.md +2 -1
- package/bin/jso-protector.js +30 -11
- package/ci/verify-examples.js +83 -83
- package/ci/verify-package.js +1 -0
- package/examples/README.md +86 -84
- package/index.js +2 -2
- package/package.json +319 -313
- package/vm-status.js +60 -0
- package/webpack.js +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.16 - 2026-12-04
|
|
4
|
+
|
|
5
|
+
- Show VM protection confirmation and virtualized function counts in CLI summaries and JSON output, including named-set builds.
|
|
6
|
+
- Describe missing report evidence as unconfirmed and suggest rerunning to refresh older reports. Count skipped-function warnings without printing their contents.
|
|
7
|
+
- Keep `--stdout` output limited to protected code.
|
|
8
|
+
- Run webpack protection after minimization and source-map generation so minifiers preserve the protected output.
|
|
9
|
+
|
|
10
|
+
## 0.4.15 - 2026-09-24
|
|
11
|
+
|
|
12
|
+
**`--preset standard` works on the Basic and Corporate plans.** It was refused
|
|
13
|
+
for everyone below Enterprise.
|
|
14
|
+
|
|
15
|
+
- `standard`, `balanced` and `maximum` asked for compression ratio `Best`,
|
|
16
|
+
which is an Enterprise feature, so any compressing preset was refused on
|
|
17
|
+
Basic and Corporate with "'compression ratio best' requires Enterprise
|
|
18
|
+
membership" -- before a single file was protected. The presets now ask for
|
|
19
|
+
`Auto`, which gives each plan its own strongest ratio: Basic Medium,
|
|
20
|
+
Corporate High, Enterprise Best. Enterprise output is unchanged.
|
|
21
|
+
- The same fix applies to the defaults this package picks when it translates
|
|
22
|
+
another tool's `compact`, `minify` or `stringCompression` settings.
|
|
23
|
+
- An explicit `--option CompressionRatio=Best` is still sent exactly as written.
|
|
24
|
+
- `balanced` and `maximum` include Enterprise-only transforms (string
|
|
25
|
+
encryption, control-flow flattening), so they still need Enterprise; the
|
|
26
|
+
README and docs now say so instead of "a paid plan".
|
|
27
|
+
|
|
3
28
|
## 0.4.14 - 2026-09-23
|
|
4
29
|
|
|
5
30
|
**`--preset maximum` works.** Every run of it was refused before a single file
|
package/README.md
CHANGED
|
@@ -67,7 +67,8 @@ and missing parity against common JavaScript obfuscators.
|
|
|
67
67
|
`--source-map-evidence`, `--vm-proof-pack`, `--deployment-hygiene-evidence`,
|
|
68
68
|
and `--runtime-incident-evidence` turn a build into a written report.
|
|
69
69
|
- **Presets instead of forty switches.** `--preset free` runs with no account;
|
|
70
|
-
`standard
|
|
70
|
+
`standard` needs Basic or higher; `balanced|maximum` include Enterprise-only
|
|
71
|
+
transforms (EncryptStrings, FlatTransform) and need Enterprise,
|
|
71
72
|
or import a preset exported from the online tool with `--web-preset`.
|
|
72
73
|
- **Different profiles in one build.** `namedSets` maps file globs to their own
|
|
73
74
|
preset and options, so a checkout flow can ship maximum protection while
|
package/bin/jso-protector.js
CHANGED
|
@@ -13,6 +13,7 @@ const packageJson = require("../package.json");
|
|
|
13
13
|
const watermark = require("../watermark.js");
|
|
14
14
|
const releaseSigner = require("../release-signer.js");
|
|
15
15
|
const pciCompliance = require("../compliance/pci-dss-v4/index.js");
|
|
16
|
+
const { summarizeVmProtection, formatVmProtection } = require("../vm-status.js");
|
|
16
17
|
|
|
17
18
|
const DEFAULT_CONFIG_FILE = "jso.config.json";
|
|
18
19
|
const DEFAULT_CONFIG_FILES = ["jso.config.json", "jso.config.cjs", "jso.config.mjs", "jso.config.js"];
|
|
@@ -28,6 +29,15 @@ const HTML_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
|
28
29
|
const SOURCE_MAP_COMMENT_LINE_PATTERN = /^[ \t]*\/\/[#@]\s*sourceMappingURL=.*(?:\r?\n)?/gm;
|
|
29
30
|
const SOURCE_MAP_COMMENT_BLOCK_PATTERN = /[ \t]*\/\*[#@]\s*sourceMappingURL=[\s\S]*?\*\/[ \t]*(?:\r?\n)?/g;
|
|
30
31
|
|
|
32
|
+
// CompressionRatio "Auto", NOT "Best", in every preset and translated default.
|
|
33
|
+
// Plans.cs gates each explicit ratio by plan (Medium = Basic, High = Corporate,
|
|
34
|
+
// Best = Enterprise), and "Best" was hardcoded here -- so standard, balanced and
|
|
35
|
+
// maximum were refused for every Basic and Corporate customer ("'compression
|
|
36
|
+
// ratio best' requires Enterprise membership"), while the docs said these
|
|
37
|
+
// presets "need a paid plan". "Auto" makes the engine pick the plan's own best
|
|
38
|
+
// ratio (ProtectorV2.CalcCompressorRatio): Enterprise still gets Best, and
|
|
39
|
+
// nothing a customer paid for is lost. Found 2026-09-24. An explicit
|
|
40
|
+
// --option CompressionRatio=Best is still sent as written.
|
|
31
41
|
const PRESET_OPTIONS = {
|
|
32
42
|
// Free tier. Exactly the transforms that are ungated server-side - anything
|
|
33
43
|
// else (compression, MoveStrings, DeepObfuscate, renaming, VM ...) requires a
|
|
@@ -43,7 +53,7 @@ const PRESET_OPTIONS = {
|
|
|
43
53
|
MoveStrings: true,
|
|
44
54
|
ReplaceNames: true,
|
|
45
55
|
SelfCompression: true,
|
|
46
|
-
CompressionRatio: "
|
|
56
|
+
CompressionRatio: "Auto"
|
|
47
57
|
},
|
|
48
58
|
balanced: {
|
|
49
59
|
IdentityStyle: "v2abcd",
|
|
@@ -52,7 +62,7 @@ const PRESET_OPTIONS = {
|
|
|
52
62
|
ReplaceNames: true,
|
|
53
63
|
SelfCompression: true,
|
|
54
64
|
SelfCompressionMinSize: 0,
|
|
55
|
-
CompressionRatio: "
|
|
65
|
+
CompressionRatio: "Auto",
|
|
56
66
|
DeepObfuscate: true,
|
|
57
67
|
ReorderCode: true,
|
|
58
68
|
EncryptStrings: true,
|
|
@@ -71,7 +81,7 @@ const PRESET_OPTIONS = {
|
|
|
71
81
|
MoveMembers: true,
|
|
72
82
|
SelfCompression: true,
|
|
73
83
|
SelfCompressionMinSize: 0,
|
|
74
|
-
CompressionRatio: "
|
|
84
|
+
CompressionRatio: "Auto",
|
|
75
85
|
DeepObfuscate: true,
|
|
76
86
|
ReorderCode: true,
|
|
77
87
|
AddDeadCode: true,
|
|
@@ -83,7 +93,7 @@ const PRESET_OPTIONS = {
|
|
|
83
93
|
|
|
84
94
|
const WEB_FEATURE_OPTIONS = {
|
|
85
95
|
"Short Local Name": { IdentityStyle: "v2abcd" },
|
|
86
|
-
"Compressor": { SelfCompression: true, SelfCompressionMinSize: 0, CompressionRatio: "
|
|
96
|
+
"Compressor": { SelfCompression: true, SelfCompressionMinSize: 0, CompressionRatio: "Auto" },
|
|
87
97
|
"Deep Obfuscation": { DeepObfuscate: true },
|
|
88
98
|
"Code Transposition": { ReorderCode: true },
|
|
89
99
|
"Dead Code Insertion": { AddDeadCode: true, DeadcodeLevel: "Low" },
|
|
@@ -1632,7 +1642,7 @@ function parseArgs(argv) {
|
|
|
1632
1642
|
const value = readOptionalBoolean(argv, i + 1);
|
|
1633
1643
|
if (value) {
|
|
1634
1644
|
args.options.push("SelfCompression=true");
|
|
1635
|
-
args.options.push("CompressionRatio=
|
|
1645
|
+
args.options.push("CompressionRatio=Auto");
|
|
1636
1646
|
} else {
|
|
1637
1647
|
args.options.push("SelfCompression=false");
|
|
1638
1648
|
args.options.push("WriteFormats=true");
|
|
@@ -2021,7 +2031,7 @@ function translateJavascriptObfuscatorConfigOptions(source = {}) {
|
|
|
2021
2031
|
|
|
2022
2032
|
if (source.compact === true) {
|
|
2023
2033
|
translated.options.SelfCompression = true;
|
|
2024
|
-
translated.options.CompressionRatio = "
|
|
2034
|
+
translated.options.CompressionRatio = "Auto";
|
|
2025
2035
|
} else if (source.compact === false) {
|
|
2026
2036
|
translated.options.SelfCompression = false;
|
|
2027
2037
|
translated.options.WriteFormats = true;
|
|
@@ -2086,7 +2096,7 @@ function translateJsConfuserConfigOptions(source = {}) {
|
|
|
2086
2096
|
|
|
2087
2097
|
if (source.stringCompression === true || source.minify === true || source.compact === true) {
|
|
2088
2098
|
translated.options.SelfCompression = true;
|
|
2089
|
-
translated.options.CompressionRatio = "
|
|
2099
|
+
translated.options.CompressionRatio = "Auto";
|
|
2090
2100
|
} else if (source.minify === false || source.compact === false) {
|
|
2091
2101
|
translated.options.WriteFormats = true;
|
|
2092
2102
|
}
|
|
@@ -2845,7 +2855,7 @@ function migrateJavascriptObfuscatorConfig(sourcePath, args = {}) {
|
|
|
2845
2855
|
|
|
2846
2856
|
if (sourceConfig.compact === true) {
|
|
2847
2857
|
config.options.SelfCompression = true;
|
|
2848
|
-
config.options.CompressionRatio = "
|
|
2858
|
+
config.options.CompressionRatio = "Auto";
|
|
2849
2859
|
mapped.push({ from: "compact", to: "SelfCompression", note: "Compact output maps to self-compression." });
|
|
2850
2860
|
} else if (sourceConfig.compact === false) {
|
|
2851
2861
|
config.options.WriteFormats = true;
|
|
@@ -3022,7 +3032,7 @@ function migrateJsConfuserConfig(sourcePath, args = {}) {
|
|
|
3022
3032
|
|
|
3023
3033
|
if (sourceConfig.stringCompression === true || sourceConfig.minify === true || sourceConfig.compact === true) {
|
|
3024
3034
|
config.options.SelfCompression = true;
|
|
3025
|
-
config.options.CompressionRatio = "
|
|
3035
|
+
config.options.CompressionRatio = "Auto";
|
|
3026
3036
|
mapped.push({ from: sourceConfig.stringCompression === true ? "stringCompression" : sourceConfig.minify === true ? "minify" : "compact", to: "SelfCompression", note: "Compression/minify maps to self-compression." });
|
|
3027
3037
|
} else if (sourceConfig.minify === false || sourceConfig.compact === false) {
|
|
3028
3038
|
config.options.WriteFormats = true;
|
|
@@ -3653,6 +3663,7 @@ async function protectGroupedFiles(config, files) {
|
|
|
3653
3663
|
set: group.setName,
|
|
3654
3664
|
files: group.files.map((file) => file.relative),
|
|
3655
3665
|
preset: groupConfig.preset,
|
|
3666
|
+
vmRequested: boolishTrue(groupConfig.options.UseVMProtection),
|
|
3656
3667
|
options: Object.keys(groupConfig.options).filter((key) => key !== "reservedNames").sort()
|
|
3657
3668
|
});
|
|
3658
3669
|
}
|
|
@@ -12289,6 +12300,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
12289
12300
|
|
|
12290
12301
|
const protectedEntry = await protectCodeDetailed(config, code, fileName);
|
|
12291
12302
|
const protectedCode = protectedEntry.code;
|
|
12303
|
+
const vmStatus = summarizeVmProtection(protectedEntry.result, config.options);
|
|
12292
12304
|
const manifestPath = config.manifest || null;
|
|
12293
12305
|
if (args.stdout) {
|
|
12294
12306
|
process.stdout.write(protectedCode);
|
|
@@ -12296,8 +12308,11 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
12296
12308
|
const target = path.join(config.output, fileName);
|
|
12297
12309
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
12298
12310
|
fs.writeFileSync(target, protectedCode, "utf8");
|
|
12299
|
-
if (args.json) process.stdout.write(`${JSON.stringify({ ...summary, type: "Succeed", written: [target], manifest: manifestPath, processing: protectedEntry.processing }, null, 2)}\n`);
|
|
12300
|
-
else
|
|
12311
|
+
if (args.json) process.stdout.write(`${JSON.stringify({ ...summary, type: "Succeed", written: [target], manifest: manifestPath, processing: protectedEntry.processing, ...(vmStatus ? { vmProtection: vmStatus } : {}) }, null, 2)}\n`);
|
|
12312
|
+
else {
|
|
12313
|
+
process.stdout.write(`Protected stdin into ${target}\n`);
|
|
12314
|
+
if (vmStatus) process.stdout.write(formatVmProtection(vmStatus) + "\n");
|
|
12315
|
+
}
|
|
12301
12316
|
}
|
|
12302
12317
|
const manifest = buildStdinManifest(config, fileName, code, protectedCode, args.stdout ? "stdout" : path.join(config.output, fileName), protectedEntry.processing);
|
|
12303
12318
|
assertSizeBudgets(manifest, config);
|
|
@@ -12474,9 +12489,13 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
12474
12489
|
done.buildIds = result.Reports.map((report) => report.BuildId || null);
|
|
12475
12490
|
}
|
|
12476
12491
|
}
|
|
12492
|
+
const vmStatus = summarizeVmProtection(result, config.options,
|
|
12493
|
+
overrideGroups ? overrideGroups.filter(group => group.vmRequested).length : undefined);
|
|
12494
|
+
if (vmStatus) done.vmProtection = vmStatus;
|
|
12477
12495
|
if (args.json) process.stdout.write(`${JSON.stringify(done, null, 2)}\n`);
|
|
12478
12496
|
else if (overrideGroups) process.stdout.write(`Protected ${files.length} file(s) in ${overrideGroups.length} named-set group(s) and copied ${assets.length} asset(s) into ${config.output}\n`);
|
|
12479
12497
|
else process.stdout.write(`Protected ${files.length} file(s) and copied ${assets.length} asset(s) into ${config.output}\n`);
|
|
12498
|
+
if (!args.json && vmStatus) process.stdout.write(formatVmProtection(vmStatus) + "\n");
|
|
12480
12499
|
}
|
|
12481
12500
|
|
|
12482
12501
|
// --scan-watermarks helpers. Walks a directory tree, looks for .js
|
package/ci/verify-examples.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
const childProcess = require("node:child_process");
|
|
6
|
-
const fs = require("node:fs");
|
|
7
|
-
const os = require("node:os");
|
|
8
|
-
const path = require("node:path");
|
|
9
|
-
|
|
10
|
-
const root = path.resolve(__dirname, "..");
|
|
11
|
-
const examplesRoot = path.join(root, "examples");
|
|
12
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
13
|
-
const expectedVersion = packageJson.version;
|
|
14
|
-
|
|
15
|
-
function fail(message) {
|
|
16
|
-
process.stderr.write(`verify-examples: FAIL: ${message}\n`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function walk(folder) {
|
|
21
|
-
return fs.readdirSync(folder, { withFileTypes: true }).flatMap((entry) => {
|
|
22
|
-
const full = path.join(folder, entry.name);
|
|
23
|
-
return entry.isDirectory() ? walk(full) : [full];
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function runNode(args, options = {}) {
|
|
28
|
-
const result = childProcess.spawnSync(process.execPath, args, { encoding: "utf8", ...options });
|
|
29
|
-
if (result.status !== 0) fail(`${args.join(" ")} failed: ${(result.stderr || result.stdout || result.error || "unknown error").toString().trim()}`);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const files = walk(examplesRoot);
|
|
34
|
-
const scripts = files.filter((file) => /\.(?:js|cjs)$/.test(file));
|
|
35
|
-
const jsonFiles = files.filter((file) => path.extname(file) === ".json");
|
|
36
|
-
|
|
37
|
-
for (const file of scripts) runNode(["--check", file]);
|
|
38
|
-
for (const file of jsonFiles) {
|
|
39
|
-
try { JSON.parse(fs.readFileSync(file, "utf8")); }
|
|
40
|
-
catch (error) { fail(`${path.relative(root, file)} is invalid JSON: ${error.message}`); }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const readme = fs.readFileSync(path.join(examplesRoot, "README.md"), "utf8");
|
|
44
|
-
// The package is published as `javascriptobfuscator-com` since 2026-08-30;
|
|
45
|
-
// `jso-protector` is the deprecated former name. Assert the CANONICAL name so
|
|
46
|
-
// this gate cannot go on enforcing a name we no longer tell customers to install.
|
|
47
|
-
if (!readme.includes(`npm install --save-dev
|
|
48
|
-
if (readme.includes("intentionally not published to npm")) fail("examples README still says the public package is unpublished");
|
|
49
|
-
|
|
50
|
-
const reactNativeReadme = fs.readFileSync(path.join(examplesRoot, "react-native", "README.md"), "utf8");
|
|
51
|
-
for (const stale of ["jso-protector/metro.js", "npx jso ai compat-scan"]) {
|
|
52
|
-
if (reactNativeReadme.includes(stale)) fail(`React Native guide contains stale command ${JSON.stringify(stale)}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const exportKeys = new Set(Object.keys(packageJson.exports));
|
|
56
|
-
for (const file of files.filter((candidate) => /\.(?:js|cjs|md)$/.test(candidate))) {
|
|
57
|
-
const source = fs.readFileSync(file, "utf8");
|
|
58
|
-
for (const match of source.matchAll(/(?:require\(|from\s+)["']jso-protector(\/[a-z0-9-]+)?["']/gi)) {
|
|
59
|
-
const key = match[1] ? `.${match[1]}` : ".";
|
|
60
|
-
if (!exportKeys.has(key)) fail(`${path.relative(root, file)} references undeclared package export ${key}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const configPath = path.join(examplesRoot, "cli-basic", "jso.config.json");
|
|
65
|
-
if (!fs.existsSync(configPath)) fail("cli-basic/jso.config.json is missing");
|
|
66
|
-
|
|
67
|
-
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "jso-example-"));
|
|
68
|
-
const copied = path.join(temp, "cli-basic");
|
|
69
|
-
fs.cpSync(path.join(examplesRoot, "cli-basic"), copied, { recursive: true });
|
|
70
|
-
runNode([path.join(copied, "scripts", "build.js")], { cwd: copied });
|
|
71
|
-
for (const relative of ["dist/app.js", "dist/index.html"]) {
|
|
72
|
-
if (!fs.existsSync(path.join(copied, relative))) fail(`cli-basic build did not produce ${relative}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const planScript = [
|
|
76
|
-
`const { planProtection } = require(${JSON.stringify(root)});`,
|
|
77
|
-
`const plan = planProtection({ input: "dist", output: "dist-protected", extensions: [".js"], copyAssets: true });`,
|
|
78
|
-
`if (plan.summary.files.length !== 1) throw new Error("expected one JS input");`,
|
|
79
|
-
`if (!plan.summary.assets.some((item) => item.endsWith("index.html"))) throw new Error("expected copied HTML asset");`
|
|
80
|
-
].join("\n");
|
|
81
|
-
runNode(["-e", planScript], { cwd: copied });
|
|
82
|
-
|
|
83
|
-
process.stdout.write(`verify-examples: PASS (${scripts.length} scripts, ${jsonFiles.length} JSON files, CLI build and offline plan)\n`);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const childProcess = require("node:child_process");
|
|
6
|
+
const fs = require("node:fs");
|
|
7
|
+
const os = require("node:os");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
|
|
10
|
+
const root = path.resolve(__dirname, "..");
|
|
11
|
+
const examplesRoot = path.join(root, "examples");
|
|
12
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
13
|
+
const expectedVersion = packageJson.version;
|
|
14
|
+
|
|
15
|
+
function fail(message) {
|
|
16
|
+
process.stderr.write(`verify-examples: FAIL: ${message}\n`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function walk(folder) {
|
|
21
|
+
return fs.readdirSync(folder, { withFileTypes: true }).flatMap((entry) => {
|
|
22
|
+
const full = path.join(folder, entry.name);
|
|
23
|
+
return entry.isDirectory() ? walk(full) : [full];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function runNode(args, options = {}) {
|
|
28
|
+
const result = childProcess.spawnSync(process.execPath, args, { encoding: "utf8", ...options });
|
|
29
|
+
if (result.status !== 0) fail(`${args.join(" ")} failed: ${(result.stderr || result.stdout || result.error || "unknown error").toString().trim()}`);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const files = walk(examplesRoot);
|
|
34
|
+
const scripts = files.filter((file) => /\.(?:js|cjs)$/.test(file));
|
|
35
|
+
const jsonFiles = files.filter((file) => path.extname(file) === ".json");
|
|
36
|
+
|
|
37
|
+
for (const file of scripts) runNode(["--check", file]);
|
|
38
|
+
for (const file of jsonFiles) {
|
|
39
|
+
try { JSON.parse(fs.readFileSync(file, "utf8")); }
|
|
40
|
+
catch (error) { fail(`${path.relative(root, file)} is invalid JSON: ${error.message}`); }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const readme = fs.readFileSync(path.join(examplesRoot, "README.md"), "utf8");
|
|
44
|
+
// The package is published as `javascriptobfuscator-com` since 2026-08-30;
|
|
45
|
+
// `jso-protector` is the deprecated former name. Assert the CANONICAL name so
|
|
46
|
+
// this gate cannot go on enforcing a name we no longer tell customers to install.
|
|
47
|
+
if (!readme.includes(`npm install --save-dev jso-protector@${expectedVersion}`)) fail("examples README does not install the current public version under this package name");
|
|
48
|
+
if (readme.includes("intentionally not published to npm")) fail("examples README still says the public package is unpublished");
|
|
49
|
+
|
|
50
|
+
const reactNativeReadme = fs.readFileSync(path.join(examplesRoot, "react-native", "README.md"), "utf8");
|
|
51
|
+
for (const stale of ["jso-protector/metro.js", "npx jso ai compat-scan"]) {
|
|
52
|
+
if (reactNativeReadme.includes(stale)) fail(`React Native guide contains stale command ${JSON.stringify(stale)}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const exportKeys = new Set(Object.keys(packageJson.exports));
|
|
56
|
+
for (const file of files.filter((candidate) => /\.(?:js|cjs|md)$/.test(candidate))) {
|
|
57
|
+
const source = fs.readFileSync(file, "utf8");
|
|
58
|
+
for (const match of source.matchAll(/(?:require\(|from\s+)["']jso-protector(\/[a-z0-9-]+)?["']/gi)) {
|
|
59
|
+
const key = match[1] ? `.${match[1]}` : ".";
|
|
60
|
+
if (!exportKeys.has(key)) fail(`${path.relative(root, file)} references undeclared package export ${key}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const configPath = path.join(examplesRoot, "cli-basic", "jso.config.json");
|
|
65
|
+
if (!fs.existsSync(configPath)) fail("cli-basic/jso.config.json is missing");
|
|
66
|
+
|
|
67
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "jso-example-"));
|
|
68
|
+
const copied = path.join(temp, "cli-basic");
|
|
69
|
+
fs.cpSync(path.join(examplesRoot, "cli-basic"), copied, { recursive: true });
|
|
70
|
+
runNode([path.join(copied, "scripts", "build.js")], { cwd: copied });
|
|
71
|
+
for (const relative of ["dist/app.js", "dist/index.html"]) {
|
|
72
|
+
if (!fs.existsSync(path.join(copied, relative))) fail(`cli-basic build did not produce ${relative}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const planScript = [
|
|
76
|
+
`const { planProtection } = require(${JSON.stringify(root)});`,
|
|
77
|
+
`const plan = planProtection({ input: "dist", output: "dist-protected", extensions: [".js"], copyAssets: true });`,
|
|
78
|
+
`if (plan.summary.files.length !== 1) throw new Error("expected one JS input");`,
|
|
79
|
+
`if (!plan.summary.assets.some((item) => item.endsWith("index.html"))) throw new Error("expected copied HTML asset");`
|
|
80
|
+
].join("\n");
|
|
81
|
+
runNode(["-e", planScript], { cwd: copied });
|
|
82
|
+
|
|
83
|
+
process.stdout.write(`verify-examples: PASS (${scripts.length} scripts, ${jsonFiles.length} JSON files, CLI build and offline plan)\n`);
|
package/ci/verify-package.js
CHANGED
package/examples/README.md
CHANGED
|
@@ -1,84 +1,86 @@
|
|
|
1
|
-
# jso-protector Examples
|
|
2
|
-
|
|
3
|
-
These examples show the common release patterns:
|
|
4
|
-
|
|
5
|
-
- `cli-basic`: protect a generated `dist/` folder after any build tool, with JSON and CommonJS config examples.
|
|
6
|
-
- `node-api`: protect a generated `dist/` folder from custom Node.js release scripts, including a typed release-summary script.
|
|
7
|
-
- `electron-app` scaffold: run `jso-protector --init --init-template electron-app` when an Electron packager writes a release folder that mixes Node-oriented JavaScript with copied app assets.
|
|
8
|
-
- `parcel`: run Parcel normally, then protect the generated `dist/` folder as a post-build release step.
|
|
9
|
-
- `bun`: run `bun build`, then protect the generated output folder through the Node API.
|
|
10
|
-
- `turbopack`: run `next build --turbopack`, then protect selected `.next/static/` chunks as a post-build release step.
|
|
11
|
-
- `browserify`: protect selected Browserify modules through a transform.
|
|
12
|
-
- `metro.config.js`: wrap Metro or Expo serializer output so React Native release bundles are protected.
|
|
13
|
-
- `react-native/metro.config.js`: use the React Native alias entrypoint when project docs or templates expect a dedicated React Native package path.
|
|
14
|
-
- `nextjs`: wrap `next.config.js` so production client bundles are protected automatically.
|
|
15
|
-
- `rspack`: protect emitted Rspack assets or selected modules through the Rspack loader alias.
|
|
16
|
-
- `vite`: protect emitted Vite chunks.
|
|
17
|
-
- `rollup`: protect emitted Rollup chunks.
|
|
18
|
-
- `esbuild`: protect esbuild output.
|
|
19
|
-
- `webpack`: protect emitted Webpack assets.
|
|
20
|
-
- `webpack-loader`: protect selected Webpack modules through a loader.
|
|
21
|
-
- `gulp`: protect files in a legacy Gulp release task.
|
|
22
|
-
- `grunt`: protect file mappings in a legacy Grunt release task.
|
|
23
|
-
- `payment-page-script-inventory.json`: starter source-free attachment for
|
|
24
|
-
`jso-protector compliance pci-dss-v4 --script-inventory`. You can also
|
|
25
|
-
generate a review starter from observed checkout scripts with
|
|
26
|
-
`jso-protector --script-inventory-from-snapshot reports/runtime-inventory.json --script-inventory-output reports/payment-script-inventory.json`.
|
|
27
|
-
In GitHub Actions, set the JSO action's `payment-script-inventory` and
|
|
28
|
-
`runtime-inventory-snapshot` inputs to run the same drift audit as a
|
|
29
|
-
source-free preflight gate.
|
|
30
|
-
- `payment-page-security-headers.json`: starter source-free attachment for
|
|
31
|
-
`jso-protector compliance pci-dss-v4 --payment-page-headers`. Generate a
|
|
32
|
-
current snapshot from a browser or synthetic-monitor HAR with
|
|
33
|
-
`jso-protector --payment-page-headers-from-har reports/checkout.har --payment-page-headers-baseline reports/payment-page-headers.baseline.json --payment-page-headers-output reports/payment-page-headers.json`.
|
|
34
|
-
`matchesBaseline` uses `match`, `mismatch`, or `missing` so reviewers can
|
|
35
|
-
see whether a checkout page or frame changed from the approved baseline.
|
|
36
|
-
|
|
37
|
-
Install the published package before running examples. The package is now
|
|
38
|
-
published as `javascriptobfuscator-com`; `jso-protector` is the former name and
|
|
39
|
-
is deprecated but still updated:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npm install --save-dev javascriptobfuscator-com@0.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
the
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Run `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log("
|
|
83
|
-
// javascript-obfuscator:
|
|
84
|
-
|
|
1
|
+
# jso-protector Examples
|
|
2
|
+
|
|
3
|
+
These examples show the common release patterns:
|
|
4
|
+
|
|
5
|
+
- `cli-basic`: protect a generated `dist/` folder after any build tool, with JSON and CommonJS config examples.
|
|
6
|
+
- `node-api`: protect a generated `dist/` folder from custom Node.js release scripts, including a typed release-summary script.
|
|
7
|
+
- `electron-app` scaffold: run `jso-protector --init --init-template electron-app` when an Electron packager writes a release folder that mixes Node-oriented JavaScript with copied app assets.
|
|
8
|
+
- `parcel`: run Parcel normally, then protect the generated `dist/` folder as a post-build release step.
|
|
9
|
+
- `bun`: run `bun build`, then protect the generated output folder through the Node API.
|
|
10
|
+
- `turbopack`: run `next build --turbopack`, then protect selected `.next/static/` chunks as a post-build release step.
|
|
11
|
+
- `browserify`: protect selected Browserify modules through a transform.
|
|
12
|
+
- `metro.config.js`: wrap Metro or Expo serializer output so React Native release bundles are protected.
|
|
13
|
+
- `react-native/metro.config.js`: use the React Native alias entrypoint when project docs or templates expect a dedicated React Native package path.
|
|
14
|
+
- `nextjs`: wrap `next.config.js` so production client bundles are protected automatically.
|
|
15
|
+
- `rspack`: protect emitted Rspack assets or selected modules through the Rspack loader alias.
|
|
16
|
+
- `vite`: protect emitted Vite chunks.
|
|
17
|
+
- `rollup`: protect emitted Rollup chunks.
|
|
18
|
+
- `esbuild`: protect esbuild output.
|
|
19
|
+
- `webpack`: protect emitted Webpack assets.
|
|
20
|
+
- `webpack-loader`: protect selected Webpack modules through a loader.
|
|
21
|
+
- `gulp`: protect files in a legacy Gulp release task.
|
|
22
|
+
- `grunt`: protect file mappings in a legacy Grunt release task.
|
|
23
|
+
- `payment-page-script-inventory.json`: starter source-free attachment for
|
|
24
|
+
`jso-protector compliance pci-dss-v4 --script-inventory`. You can also
|
|
25
|
+
generate a review starter from observed checkout scripts with
|
|
26
|
+
`jso-protector --script-inventory-from-snapshot reports/runtime-inventory.json --script-inventory-output reports/payment-script-inventory.json`.
|
|
27
|
+
In GitHub Actions, set the JSO action's `payment-script-inventory` and
|
|
28
|
+
`runtime-inventory-snapshot` inputs to run the same drift audit as a
|
|
29
|
+
source-free preflight gate.
|
|
30
|
+
- `payment-page-security-headers.json`: starter source-free attachment for
|
|
31
|
+
`jso-protector compliance pci-dss-v4 --payment-page-headers`. Generate a
|
|
32
|
+
current snapshot from a browser or synthetic-monitor HAR with
|
|
33
|
+
`jso-protector --payment-page-headers-from-har reports/checkout.har --payment-page-headers-baseline reports/payment-page-headers.baseline.json --payment-page-headers-output reports/payment-page-headers.json`.
|
|
34
|
+
`matchesBaseline` uses `match`, `mismatch`, or `missing` so reviewers can
|
|
35
|
+
see whether a checkout page or frame changed from the approved baseline.
|
|
36
|
+
|
|
37
|
+
Install the published package before running examples. The package is now
|
|
38
|
+
published as `javascriptobfuscator-com`; `jso-protector` is the former name and
|
|
39
|
+
is deprecated but still updated:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install --save-dev javascriptobfuscator-com@0.5.1
|
|
43
|
+
# Or install this package name:
|
|
44
|
+
npm install --save-dev jso-protector@0.4.16
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Repository contributors can instead use the existing `file:../..` development
|
|
48
|
+
dependency in the self-contained example projects. Customer projects should use
|
|
49
|
+
the pinned registry version above.
|
|
50
|
+
|
|
51
|
+
All examples expect API credentials in environment variables:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
set JSO_API_KEY=base64-api-key-from-dashboard
|
|
55
|
+
set JSO_API_PASSWORD=base64-api-password-from-dashboard
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Use CI secrets for shared pipelines.
|
|
59
|
+
|
|
60
|
+
Run `npm run preflight` in `examples/cli-basic` before protection when you want one offline release check that validates config, confirms matched files/assets, and runs doctor checks without sending source code to the API.
|
|
61
|
+
|
|
62
|
+
Run `jso-protector --config jso.config.json --competitor-gap-report --json` after migrating from another obfuscator when you need a source-free report of runtime-defense, source-map, lock, and release-forensics parity gaps.
|
|
63
|
+
|
|
64
|
+
Use `jso.config.json` for schema-friendly static config. Use `jso.config.cjs` when CI needs environment-aware inputs, outputs, presets, or release domain settings. JavaScript config files execute as Node.js code, so only load them from trusted repositories.
|
|
65
|
+
|
|
66
|
+
For Parcel, Bun, and Turbopack, the examples intentionally use the generic Node API after the framework build completes. That keeps the package aligned with the current hosted-API workflow while still giving modern toolchains a copy-paste release recipe.
|
|
67
|
+
|
|
68
|
+
## Protected regions
|
|
69
|
+
|
|
70
|
+
Projects migrating from `javascript-obfuscator` can preserve source regions marked with conditional comments by setting `honorConditionalComments: true` in CLI, Node API, or build-plugin config. The protector sends only enabled regions to the hosted API and recomposes the original file afterward.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
jsoProtector({
|
|
74
|
+
apiKey: process.env.JSO_API_KEY,
|
|
75
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
76
|
+
preset: "balanced",
|
|
77
|
+
honorConditionalComments: true
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
console.log("protect this");
|
|
83
|
+
// javascript-obfuscator:disable
|
|
84
|
+
console.log("leave this exact code alone");
|
|
85
|
+
// javascript-obfuscator:enable
|
|
86
|
+
```
|
package/index.js
CHANGED
|
@@ -231,7 +231,7 @@ function translateJavascriptObfuscatorOptions(sourceOptions = {}, overrides = {}
|
|
|
231
231
|
|
|
232
232
|
if (source.compact === true) {
|
|
233
233
|
translated.options.SelfCompression = true;
|
|
234
|
-
translated.options.CompressionRatio = "Best"
|
|
234
|
+
translated.options.CompressionRatio = "Auto"; // not "Best": Best is Enterprise-only (see bin/jso-protector.js PRESET_OPTIONS note)
|
|
235
235
|
} else if (source.compact === false) {
|
|
236
236
|
translated.options.WriteFormats = true;
|
|
237
237
|
}
|
|
@@ -315,7 +315,7 @@ function translateJsConfuserOptions(sourceOptions = {}, overrides = {}) {
|
|
|
315
315
|
|
|
316
316
|
if (source.stringCompression === true || source.minify === true || source.compact === true) {
|
|
317
317
|
translated.options.SelfCompression = true;
|
|
318
|
-
translated.options.CompressionRatio = "Best"
|
|
318
|
+
translated.options.CompressionRatio = "Auto"; // not "Best": Best is Enterprise-only (see bin/jso-protector.js PRESET_OPTIONS note)
|
|
319
319
|
} else if (source.minify === false || source.compact === false) {
|
|
320
320
|
translated.options.WriteFormats = true;
|
|
321
321
|
}
|