jso-protector 0.2.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 +960 -0
- package/LICENSE +90 -0
- package/MIGRATION.md +207 -0
- package/README.md +1477 -0
- package/RELEASE.md +82 -0
- package/SECURITY.md +71 -0
- package/ai-cli.js +392 -0
- package/ai.js +176 -0
- package/bin/jso-protector.js +12066 -0
- package/browserify.d.ts +10 -0
- package/browserify.js +88 -0
- package/bun.d.ts +10 -0
- package/bun.js +41 -0
- package/ci/Jenkinsfile +82 -0
- package/ci/argo-workflows.yaml +121 -0
- package/ci/azure-pipelines.yml +56 -0
- package/ci/bitbucket-pipelines.yml +43 -0
- package/ci/buildkite.yml +50 -0
- package/ci/circleci.yml +60 -0
- package/ci/drone.yml +67 -0
- package/ci/github-actions.yml +51 -0
- package/ci/gitlab-ci.yml +39 -0
- package/ci/gocd.yaml +79 -0
- package/ci/teamcity.kts +79 -0
- package/ci/tekton.yaml +106 -0
- package/ci/verify-package.js +748 -0
- package/ci/verify-publish-metadata.js +147 -0
- package/ci/verify-templates.js +195 -0
- package/ci/woodpecker.yml +53 -0
- package/compliance/cli.js +204 -0
- package/compliance/evidence-forwarder.js +209 -0
- package/compliance/pci-dss-v4/controls.json +75 -0
- package/compliance/pci-dss-v4/index.js +2613 -0
- package/config/named-sets.js +185 -0
- package/esbuild.d.ts +16 -0
- package/esbuild.js +190 -0
- package/examples/README.md +78 -0
- package/examples/browserify/build.js +20 -0
- package/examples/bun/package.json +13 -0
- package/examples/bun/scripts/protect-release.js +28 -0
- package/examples/cli-basic/jso.config.cjs +23 -0
- package/examples/cli-basic/jso.config.json +15 -0
- package/examples/cli-basic/package.json +14 -0
- package/examples/cli-basic/scripts/build.js +10 -0
- package/examples/curl/README.md +55 -0
- package/examples/curl/protect.sh +106 -0
- package/examples/esbuild/build.js +19 -0
- package/examples/grunt/Gruntfile.js +29 -0
- package/examples/gulp/gulpfile.js +19 -0
- package/examples/helm/Chart.yaml +27 -0
- package/examples/helm/README.md +69 -0
- package/examples/helm/templates/_helpers.tpl +23 -0
- package/examples/helm/templates/_podtemplate.tpl +64 -0
- package/examples/helm/templates/job.yaml +39 -0
- package/examples/helm/templates/secret.yaml +17 -0
- package/examples/helm/values.yaml +54 -0
- package/examples/kubernetes/job.yaml +123 -0
- package/examples/metro.config.js +11 -0
- package/examples/nextjs/next.config.js +11 -0
- package/examples/node-api/protect-release.js +28 -0
- package/examples/node-api/release-summary.js +59 -0
- package/examples/parcel/package.json +13 -0
- package/examples/parcel/scripts/protect-release.js +28 -0
- package/examples/payment-page-script-inventory.json +62 -0
- package/examples/payment-page-security-headers.json +46 -0
- package/examples/pre-commit/.pre-commit-config.yaml +33 -0
- package/examples/pre-commit/README.md +45 -0
- package/examples/react-native/README.md +208 -0
- package/examples/react-native/metro.config.js +11 -0
- package/examples/rollup/rollup.config.js +20 -0
- package/examples/rspack/rspack.config.js +28 -0
- package/examples/turbopack/package.json +13 -0
- package/examples/turbopack/scripts/protect-release.js +28 -0
- package/examples/vite/vite.config.js +18 -0
- package/examples/webpack/webpack.config.js +21 -0
- package/examples/webpack-loader/webpack.config.js +22 -0
- package/governance/index.d.ts +18 -0
- package/governance/index.js +309 -0
- package/grunt.d.ts +4 -0
- package/grunt.js +111 -0
- package/gulp.d.ts +10 -0
- package/gulp.js +106 -0
- package/index.d.ts +879 -0
- package/index.js +607 -0
- package/jso.config.example.json +29 -0
- package/jso.config.schema.json +548 -0
- package/metro.d.ts +43 -0
- package/metro.js +117 -0
- package/next.d.ts +24 -0
- package/next.js +64 -0
- package/package.json +241 -0
- package/parcel.d.ts +10 -0
- package/parcel.js +40 -0
- package/react-native.d.ts +2 -0
- package/react-native.js +3 -0
- package/release-signer.js +245 -0
- package/rollup.d.ts +13 -0
- package/rollup.js +71 -0
- package/rspack-loader.d.ts +13 -0
- package/rspack-loader.js +11 -0
- package/rspack.d.ts +11 -0
- package/rspack.js +9 -0
- package/runtime/ai-script-governance.js +379 -0
- package/runtime/countermeasures.js +0 -0
- package/runtime/data-exfiltration-guard.d.ts +7 -0
- package/runtime/data-exfiltration-guard.js +161 -0
- package/runtime/environment-integrity.js +389 -0
- package/runtime/managed-integrity.d.ts +4 -0
- package/runtime/managed-integrity.js +108 -0
- package/runtime/third-party-inventory.js +437 -0
- package/turbopack.d.ts +10 -0
- package/turbopack.js +41 -0
- package/vite.d.ts +16 -0
- package/vite.js +78 -0
- package/watermark.js +126 -0
- package/webpack-loader.d.ts +15 -0
- package/webpack-loader.js +97 -0
- package/webpack.d.ts +13 -0
- package/webpack.js +143 -0
package/index.js
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const core = require("./bin/jso-protector.js");
|
|
5
|
+
const ai = require("./ai.js");
|
|
6
|
+
|
|
7
|
+
const JAVASCRIPT_OBFUSCATOR_OPTION_KEYS = [
|
|
8
|
+
"compact",
|
|
9
|
+
"controlFlowFlattening",
|
|
10
|
+
"deadCodeInjection",
|
|
11
|
+
"deadCodeInjectionThreshold",
|
|
12
|
+
"domainLock",
|
|
13
|
+
"identifierNamesGenerator",
|
|
14
|
+
"optionsPreset",
|
|
15
|
+
"parseHtml",
|
|
16
|
+
"renameGlobals",
|
|
17
|
+
"renameProperties",
|
|
18
|
+
"reservedNames",
|
|
19
|
+
"strictMode",
|
|
20
|
+
"stringArray",
|
|
21
|
+
"stringArrayEncoding",
|
|
22
|
+
"stringArrayThreshold",
|
|
23
|
+
"target",
|
|
24
|
+
"unicodeEscapeSequence"
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const JS_CONFUSER_OPTION_KEYS = [
|
|
28
|
+
"compact",
|
|
29
|
+
"controlFlowFlattening",
|
|
30
|
+
"deadCode",
|
|
31
|
+
"duplicateLiteralsRemoval",
|
|
32
|
+
"globalConcealing",
|
|
33
|
+
"identifierGenerator",
|
|
34
|
+
"lock",
|
|
35
|
+
"minify",
|
|
36
|
+
"preset",
|
|
37
|
+
"renameGlobals",
|
|
38
|
+
"renameVariables",
|
|
39
|
+
"stringCompression",
|
|
40
|
+
"stringConcealing",
|
|
41
|
+
"stringEncoding",
|
|
42
|
+
"target"
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const JS_CONFUSER_DETECT_KEYS = [
|
|
46
|
+
"astScrambler",
|
|
47
|
+
"calculator",
|
|
48
|
+
"deadCode",
|
|
49
|
+
"dispatcher",
|
|
50
|
+
"duplicateLiteralsRemoval",
|
|
51
|
+
"flatten",
|
|
52
|
+
"globalConcealing",
|
|
53
|
+
"hexadecimalNumbers",
|
|
54
|
+
"identifierGenerator",
|
|
55
|
+
"lock",
|
|
56
|
+
"minify",
|
|
57
|
+
"movedDeclarations",
|
|
58
|
+
"objectExtraction",
|
|
59
|
+
"opaquePredicates",
|
|
60
|
+
"pack",
|
|
61
|
+
"preserveFunctionLength",
|
|
62
|
+
"renameLabels",
|
|
63
|
+
"renameVariables",
|
|
64
|
+
"rgf",
|
|
65
|
+
"shuffle",
|
|
66
|
+
"stringCompression",
|
|
67
|
+
"stringConcealing",
|
|
68
|
+
"stringEncoding",
|
|
69
|
+
"variableMasking"
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
function createProtectionConfig(options = {}) {
|
|
73
|
+
const normalizedOptions = normalizeCompatibilityOptions(options);
|
|
74
|
+
const configPath = normalizedOptions.config || normalizedOptions.configFile;
|
|
75
|
+
const fileConfig = configPath ? core.readConfig(configPath, { mode: options.mode }) : {};
|
|
76
|
+
const overrides = { ...normalizedOptions };
|
|
77
|
+
delete overrides.config;
|
|
78
|
+
delete overrides.configFile;
|
|
79
|
+
|
|
80
|
+
const mergedConfig = {
|
|
81
|
+
...fileConfig,
|
|
82
|
+
...overrides,
|
|
83
|
+
options: {
|
|
84
|
+
...(fileConfig.options || {}),
|
|
85
|
+
...(overrides.options || {})
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const config = core.mergeConfig(mergedConfig, {});
|
|
90
|
+
Object.defineProperty(config, "__jsoMergedConfig", {
|
|
91
|
+
value: true,
|
|
92
|
+
enumerable: false
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(config, "__rawConfig", {
|
|
95
|
+
value: mergedConfig,
|
|
96
|
+
enumerable: false
|
|
97
|
+
});
|
|
98
|
+
return config;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeCompatibilityOptions(options) {
|
|
102
|
+
if (!options || typeof options !== "object") return options;
|
|
103
|
+
|
|
104
|
+
const normalized = {
|
|
105
|
+
...options
|
|
106
|
+
};
|
|
107
|
+
const javascriptObfuscatorOptions = {
|
|
108
|
+
...(options.javascriptObfuscatorOptions || {})
|
|
109
|
+
};
|
|
110
|
+
for (const key of JAVASCRIPT_OBFUSCATOR_OPTION_KEYS) {
|
|
111
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
112
|
+
javascriptObfuscatorOptions[key] = options[key];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const jsConfuserOptions = {
|
|
117
|
+
...(options.jsConfuserOptions || {})
|
|
118
|
+
};
|
|
119
|
+
if (!Object.keys(jsConfuserOptions).length && hasTopLevelJsConfuserOptions(options)) {
|
|
120
|
+
for (const key of JS_CONFUSER_OPTION_KEYS) {
|
|
121
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
122
|
+
jsConfuserOptions[key] = options[key];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!Object.keys(javascriptObfuscatorOptions).length && !Object.keys(jsConfuserOptions).length) {
|
|
128
|
+
return options;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const translatedJavascriptObfuscator = Object.keys(javascriptObfuscatorOptions).length
|
|
132
|
+
? translateJavascriptObfuscatorOptions(javascriptObfuscatorOptions)
|
|
133
|
+
: {};
|
|
134
|
+
const translatedJsConfuser = Object.keys(jsConfuserOptions).length
|
|
135
|
+
? translateJsConfuserOptions(jsConfuserOptions)
|
|
136
|
+
: {};
|
|
137
|
+
|
|
138
|
+
delete normalized.javascriptObfuscatorOptions;
|
|
139
|
+
delete normalized.jsConfuserOptions;
|
|
140
|
+
|
|
141
|
+
if (!options.javascriptObfuscatorOptions) {
|
|
142
|
+
for (const key of JAVASCRIPT_OBFUSCATOR_OPTION_KEYS) {
|
|
143
|
+
delete normalized[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!options.jsConfuserOptions && hasTopLevelJsConfuserOptions(options)) {
|
|
148
|
+
for (const key of JS_CONFUSER_OPTION_KEYS) {
|
|
149
|
+
delete normalized[key];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
Object.assign(normalized, translatedJavascriptObfuscator, translatedJsConfuser);
|
|
154
|
+
normalized.options = {
|
|
155
|
+
...(translatedJavascriptObfuscator.options || {}),
|
|
156
|
+
...(translatedJsConfuser.options || {}),
|
|
157
|
+
...(options.options || {})
|
|
158
|
+
};
|
|
159
|
+
return normalized;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function translateJavascriptObfuscatorOptions(sourceOptions = {}, overrides = {}) {
|
|
163
|
+
const source = sourceOptions || {};
|
|
164
|
+
const translated = {
|
|
165
|
+
preset: "balanced",
|
|
166
|
+
options: {
|
|
167
|
+
OptimizationMode: "Web"
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (source.optionsPreset !== undefined) {
|
|
172
|
+
translated.preset = core.presetFromJavascriptObfuscatorPreset(source.optionsPreset);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
mapBooleanOption(source, "stringArray", translated.options, "MoveStrings");
|
|
176
|
+
mapBooleanOption(source, "unicodeEscapeSequence", translated.options, "EncodeStrings");
|
|
177
|
+
mapBooleanOption(source, "controlFlowFlattening", translated.options, "DeepObfuscate");
|
|
178
|
+
mapBooleanOption(source, "controlFlowFlattening", translated.options, "FlatTransform");
|
|
179
|
+
mapBooleanOption(source, "deadCodeInjection", translated.options, "AddDeadCode");
|
|
180
|
+
mapBooleanOption(source, "renameGlobals", translated.options, "RenameGlobals");
|
|
181
|
+
mapBooleanOption(source, "renameProperties", translated.options, "RenameMembers");
|
|
182
|
+
|
|
183
|
+
if (source.stringArrayEncoding !== undefined) {
|
|
184
|
+
const encodings = Array.isArray(source.stringArrayEncoding) ? source.stringArrayEncoding : [source.stringArrayEncoding];
|
|
185
|
+
if (encodings.some((encoding) => String(encoding).toLowerCase() === "rc4")) {
|
|
186
|
+
translated.options.EncryptStrings = true;
|
|
187
|
+
} else if (encodings.length) {
|
|
188
|
+
translated.options.EncodeStrings = true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (source.stringArrayThreshold !== undefined && Number(source.stringArrayThreshold) > 0) {
|
|
193
|
+
translated.options.MoveStrings = true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (source.deadCodeInjectionThreshold !== undefined) {
|
|
197
|
+
const threshold = Number(source.deadCodeInjectionThreshold);
|
|
198
|
+
translated.options.DeadcodeLevel = threshold >= 0.66 ? "High" : threshold >= 0.33 ? "Medium" : "Low";
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (source.identifierNamesGenerator !== undefined) {
|
|
202
|
+
const generator = String(source.identifierNamesGenerator).toLowerCase();
|
|
203
|
+
translated.options.IdentityStyle = generator.includes("hex") ? "v1hex" : "v2abcd";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (source.compact === true) {
|
|
207
|
+
translated.options.SelfCompression = true;
|
|
208
|
+
translated.options.CompressionRatio = "Best";
|
|
209
|
+
} else if (source.compact === false) {
|
|
210
|
+
translated.options.WriteFormats = true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (source.target !== undefined) {
|
|
214
|
+
const target = String(source.target).toLowerCase();
|
|
215
|
+
translated.options.OptimizationMode = target.includes("node") ? "NodeJS" : "Web";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (source.parseHtml !== undefined) {
|
|
219
|
+
translated.parseHtml = source.parseHtml === true;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (source.strictMode !== undefined) {
|
|
223
|
+
translated.strictMode = source.strictMode;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (Array.isArray(source.reservedNames) && source.reservedNames.length) {
|
|
227
|
+
translated.reservedNames = source.reservedNames.map((value) => String(value));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (source.domainLock !== undefined) {
|
|
231
|
+
const domains = core.normalizeDomainLockList(source.domainLock);
|
|
232
|
+
if (domains.length) {
|
|
233
|
+
translated.options.LockDomain = true;
|
|
234
|
+
translated.options.LockDomainList = domains.join("\n");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
...translated,
|
|
240
|
+
...overrides,
|
|
241
|
+
options: {
|
|
242
|
+
...translated.options,
|
|
243
|
+
...(overrides.options || {})
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function presetFromJsConfuserPreset(value) {
|
|
249
|
+
const normalized = String(value || "").trim().toLowerCase();
|
|
250
|
+
if (!normalized || normalized === "low") return "standard";
|
|
251
|
+
if (normalized === "medium") return "balanced";
|
|
252
|
+
if (normalized === "high") return "maximum";
|
|
253
|
+
throw new Error(`Unknown JS-Confuser preset "${value}". Use low, medium, or high.`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function hasTopLevelJsConfuserOptions(options) {
|
|
257
|
+
if (!options || typeof options !== "object") return false;
|
|
258
|
+
if (JS_CONFUSER_DETECT_KEYS.some((key) => Object.prototype.hasOwnProperty.call(options, key))) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
const preset = String(options.preset || "").trim().toLowerCase();
|
|
262
|
+
return preset === "low" || preset === "medium" || preset === "high";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function translateJsConfuserOptions(sourceOptions = {}, overrides = {}) {
|
|
266
|
+
const source = sourceOptions || {};
|
|
267
|
+
const translated = {
|
|
268
|
+
preset: "balanced",
|
|
269
|
+
options: {
|
|
270
|
+
OptimizationMode: "Web"
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (source.preset !== undefined) {
|
|
275
|
+
translated.preset = presetFromJsConfuserPreset(source.preset);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
mapBooleanOption(source, "renameVariables", translated.options, "ReplaceNames");
|
|
279
|
+
mapBooleanOption(source, "renameGlobals", translated.options, "RenameGlobals");
|
|
280
|
+
mapBooleanOption(source, "stringEncoding", translated.options, "EncodeStrings");
|
|
281
|
+
mapBooleanOption(source, "stringConcealing", translated.options, "EncryptStrings");
|
|
282
|
+
mapBooleanOption(source, "duplicateLiteralsRemoval", translated.options, "MoveStrings");
|
|
283
|
+
mapBooleanOption(source, "controlFlowFlattening", translated.options, "DeepObfuscate");
|
|
284
|
+
mapBooleanOption(source, "controlFlowFlattening", translated.options, "FlatTransform");
|
|
285
|
+
mapBooleanOption(source, "deadCode", translated.options, "AddDeadCode");
|
|
286
|
+
mapBooleanOption(source, "globalConcealing", translated.options, "RenameGlobals");
|
|
287
|
+
|
|
288
|
+
if (source.stringCompression === true || source.minify === true || source.compact === true) {
|
|
289
|
+
translated.options.SelfCompression = true;
|
|
290
|
+
translated.options.CompressionRatio = "Best";
|
|
291
|
+
} else if (source.minify === false || source.compact === false) {
|
|
292
|
+
translated.options.WriteFormats = true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (source.identifierGenerator !== undefined) {
|
|
296
|
+
const generator = String(source.identifierGenerator).toLowerCase();
|
|
297
|
+
translated.options.IdentityStyle = generator.includes("hex") ? "v1hex" : "v2abcd";
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (source.target !== undefined) {
|
|
301
|
+
const target = String(source.target).toLowerCase();
|
|
302
|
+
translated.options.OptimizationMode = target.includes("node") ? "NodeJS" : "Web";
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const lock = source.lock && typeof source.lock === "object" && !Array.isArray(source.lock)
|
|
306
|
+
? source.lock
|
|
307
|
+
: null;
|
|
308
|
+
if (lock && lock.domainLock !== undefined) {
|
|
309
|
+
const domains = core.normalizeDomainLockList(lock.domainLock);
|
|
310
|
+
if (domains.length) {
|
|
311
|
+
translated.options.LockDomain = true;
|
|
312
|
+
translated.options.LockDomainList = domains.join("\n");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (lock && lock.endDate !== undefined) {
|
|
316
|
+
translated.options.LockDate = true;
|
|
317
|
+
translated.options.LockDateValue = formatLockDateValue(lock.endDate);
|
|
318
|
+
}
|
|
319
|
+
if (lock && lock.antiDebug !== undefined) {
|
|
320
|
+
translated.jsConfuserLockAntiDebug = lock.antiDebug;
|
|
321
|
+
}
|
|
322
|
+
if (lock && lock.integrity !== undefined) {
|
|
323
|
+
translated.jsConfuserLockIntegrity = lock.integrity;
|
|
324
|
+
}
|
|
325
|
+
if (lock && lock.selfDefending !== undefined) {
|
|
326
|
+
translated.jsConfuserLockSelfDefending = lock.selfDefending;
|
|
327
|
+
}
|
|
328
|
+
if (lock && lock.startDate !== undefined) {
|
|
329
|
+
translated.jsConfuserLockStartDate = formatLockDateValue(lock.startDate);
|
|
330
|
+
}
|
|
331
|
+
if (lock && lock.countermeasures !== undefined) {
|
|
332
|
+
translated.jsConfuserLockCountermeasures = formatReviewString(lock.countermeasures);
|
|
333
|
+
}
|
|
334
|
+
if (lock && lock.tamperProtection !== undefined) {
|
|
335
|
+
translated.jsConfuserLockTamperProtection = lock.tamperProtection;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
...translated,
|
|
340
|
+
...overrides,
|
|
341
|
+
options: {
|
|
342
|
+
...translated.options,
|
|
343
|
+
...(overrides.options || {})
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function formatLockDateValue(value) {
|
|
349
|
+
const text = String(value || "").trim();
|
|
350
|
+
if (/^\d{8}$/.test(text)) return text;
|
|
351
|
+
const date = new Date(text);
|
|
352
|
+
if (!Number.isFinite(date.getTime())) return text;
|
|
353
|
+
const year = String(date.getUTCFullYear()).padStart(4, "0");
|
|
354
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
355
|
+
const day = String(date.getUTCDate()).padStart(2, "0");
|
|
356
|
+
return `${year}${month}${day}`;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function formatReviewString(value) {
|
|
360
|
+
if (typeof value === "function") {
|
|
361
|
+
return value.name ? `[Function ${value.name}]` : "[Function]";
|
|
362
|
+
}
|
|
363
|
+
return String(value);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function mapBooleanOption(source, sourceKey, target, targetKey) {
|
|
367
|
+
if (source[sourceKey] === true) target[targetKey] = true;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function ensureProtectionConfig(options) {
|
|
371
|
+
if (options && options.__jsoMergedConfig) return options;
|
|
372
|
+
return createProtectionConfig(options || {});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function protectItems(options, items) {
|
|
376
|
+
return core.protectItems(ensureProtectionConfig(options), items);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function protectCode(options, code, fileName = "bundle.js") {
|
|
380
|
+
return core.protectCode(ensureProtectionConfig(options), code, fileName);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function createObfuscationResult(code, fileName, result) {
|
|
384
|
+
return {
|
|
385
|
+
code,
|
|
386
|
+
fileName,
|
|
387
|
+
result,
|
|
388
|
+
getObfuscatedCode() {
|
|
389
|
+
return code;
|
|
390
|
+
},
|
|
391
|
+
toString() {
|
|
392
|
+
return code;
|
|
393
|
+
},
|
|
394
|
+
getSourceMap() {
|
|
395
|
+
return null;
|
|
396
|
+
},
|
|
397
|
+
getIdentifierNamesCache() {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
async function obfuscate(code, options = {}, fileName = "bundle.js") {
|
|
404
|
+
const config = ensureProtectionConfig(options);
|
|
405
|
+
const protectedEntry = await protectSourceEntry(config, String(code), fileName);
|
|
406
|
+
return createObfuscationResult(protectedEntry.code, fileName, protectedEntry.result);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async function obfuscateCode(code, options = {}, fileName = "bundle.js") {
|
|
410
|
+
return obfuscate(code, options, fileName);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async function obfuscateMultiple(sourceCodesObject, options = {}) {
|
|
414
|
+
if (!sourceCodesObject || typeof sourceCodesObject !== "object" || Array.isArray(sourceCodesObject)) {
|
|
415
|
+
throw new Error("obfuscateMultiple requires an object map of file names to source code.");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const entries = Object.entries(sourceCodesObject);
|
|
419
|
+
const config = ensureProtectionConfig(options);
|
|
420
|
+
const items = [];
|
|
421
|
+
const plans = new Map();
|
|
422
|
+
|
|
423
|
+
for (const [fileName, code] of entries) {
|
|
424
|
+
const plan = buildSourceEntryProtectionPlan(config, fileName, String(code));
|
|
425
|
+
items.push(...plan.items);
|
|
426
|
+
plans.set(normalizeName(fileName), plan);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const result = await core.protectItems(config, items);
|
|
430
|
+
const byName = new Map((result.Items || []).map((item) => [
|
|
431
|
+
normalizeName(item.FileName),
|
|
432
|
+
item
|
|
433
|
+
]));
|
|
434
|
+
const output = {};
|
|
435
|
+
|
|
436
|
+
for (const [fileName] of entries) {
|
|
437
|
+
const normalizedName = normalizeName(fileName);
|
|
438
|
+
const plan = plans.get(normalizedName);
|
|
439
|
+
const code = composeSourceEntryOutput(fileName, plan, byName, config);
|
|
440
|
+
if (code === null) {
|
|
441
|
+
throw new Error(`API response did not include output for ${fileName}`);
|
|
442
|
+
}
|
|
443
|
+
output[fileName] = createObfuscationResult(code, fileName, result);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return output;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async function protectSourceEntry(config, code, fileName) {
|
|
450
|
+
const plan = buildSourceEntryProtectionPlan(config, fileName, code);
|
|
451
|
+
const result = await core.protectItems(config, plan.items);
|
|
452
|
+
const byName = new Map((result.Items || []).map((item) => [
|
|
453
|
+
normalizeName(item.FileName),
|
|
454
|
+
item
|
|
455
|
+
]));
|
|
456
|
+
const output = composeSourceEntryOutput(fileName, plan, byName, config);
|
|
457
|
+
if (output === null) {
|
|
458
|
+
throw new Error(`API response did not include output for ${fileName}`);
|
|
459
|
+
}
|
|
460
|
+
return { code: output, result };
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function composeSourceEntryOutput(fileName, plan, byName, config) {
|
|
464
|
+
const normalizedName = normalizeName(fileName);
|
|
465
|
+
if (plan && plan.transform) {
|
|
466
|
+
return core.finalizeProtectedCode(core.composeProtectionOutput(plan.transform, byName), config);
|
|
467
|
+
}
|
|
468
|
+
const item = byName.get(normalizedName);
|
|
469
|
+
if (!item) return null;
|
|
470
|
+
return core.finalizeProtectedCode(item.FileCode || "", config);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function buildSourceEntryProtectionPlan(config, fileName, code) {
|
|
474
|
+
const ext = path.extname(fileName).toLowerCase();
|
|
475
|
+
if (config.parseHtml && config.markupExtensions.includes(ext)) {
|
|
476
|
+
return core.buildHtmlProtectionPlan(config, fileName, code);
|
|
477
|
+
}
|
|
478
|
+
return core.buildCodeProtectionPlan(config, fileName, code);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function normalizeName(name) {
|
|
482
|
+
return String(name || "").replace(/\\/g, "/");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function getOptionsByPreset(optionsPreset = "standard") {
|
|
486
|
+
const preset = String(optionsPreset || "standard").toLowerCase();
|
|
487
|
+
if (!Object.prototype.hasOwnProperty.call(core.PRESET_OPTIONS, preset)) {
|
|
488
|
+
throw new Error(`Unknown preset "${optionsPreset}". Use standard, balanced, or maximum.`);
|
|
489
|
+
}
|
|
490
|
+
return { ...core.PRESET_OPTIONS[preset] };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function summarizePlan(config, files, assets, protection = null) {
|
|
494
|
+
const summary = {
|
|
495
|
+
endpoint: config.endpoint,
|
|
496
|
+
projectName: config.projectName,
|
|
497
|
+
preset: config.preset,
|
|
498
|
+
input: config.input,
|
|
499
|
+
output: config.output,
|
|
500
|
+
files: files.map((file) => file.relative),
|
|
501
|
+
assets: assets.map((file) => file.relative),
|
|
502
|
+
options: Object.keys(config.options).filter((key) => key !== "reservedNames")
|
|
503
|
+
};
|
|
504
|
+
return protection ? core.addProtectionSummary(summary, protection) : summary;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function planProtection(options = {}) {
|
|
508
|
+
const config = ensureProtectionConfig(options);
|
|
509
|
+
const files = core.collectFiles(config.input, config.output, config.extensions, config.exclude, config.include, config.markupExtensions);
|
|
510
|
+
const assets = config.copyAssets ? core.collectAssets(config.input, config.output, files, config.assetExclude) : [];
|
|
511
|
+
const protection = core.buildProtectionItems(config, files);
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
config,
|
|
515
|
+
files,
|
|
516
|
+
assets,
|
|
517
|
+
protection,
|
|
518
|
+
summary: summarizePlan(config, files, assets, protection)
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function protectFiles(options = {}) {
|
|
523
|
+
const plan = planProtection(options);
|
|
524
|
+
if (!plan.files.length) {
|
|
525
|
+
throw new Error("No matching input files found.");
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const request = core.buildRequestFromItems(plan.config, plan.protection.items);
|
|
529
|
+
const result = await core.protectItems(plan.config, request.Items);
|
|
530
|
+
|
|
531
|
+
core.writeResults(plan.files, result, plan.protection.transforms, plan.config);
|
|
532
|
+
core.copyAssets(plan.assets);
|
|
533
|
+
|
|
534
|
+
const manifest = core.buildProtectionManifest(plan.config, plan.files, plan.assets, result, plan.protection.transforms);
|
|
535
|
+
core.assertSizeBudgets(manifest, plan.config);
|
|
536
|
+
core.writeManifest(plan.config.manifest, manifest);
|
|
537
|
+
|
|
538
|
+
return {
|
|
539
|
+
...plan.summary,
|
|
540
|
+
type: result.Type,
|
|
541
|
+
written: plan.files.map((file) => file.target),
|
|
542
|
+
copied: plan.assets.map((file) => file.target),
|
|
543
|
+
manifestPath: plan.config.manifest,
|
|
544
|
+
manifest,
|
|
545
|
+
result
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
async function protectDirectory(options = {}) {
|
|
550
|
+
return protectFiles(options);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
async function obfuscateFiles(options = {}) {
|
|
554
|
+
return protectFiles(options);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
async function obfuscateDirectory(options = {}) {
|
|
558
|
+
return protectDirectory(options);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
async function protectFile(options = {}, sourcePath, outputPath) {
|
|
562
|
+
const fileOptions = { ...options };
|
|
563
|
+
if (sourcePath) fileOptions.input = sourcePath;
|
|
564
|
+
if (outputPath) {
|
|
565
|
+
fileOptions.output = outputPath;
|
|
566
|
+
} else if (sourcePath && !options.output) {
|
|
567
|
+
const parsed = path.parse(sourcePath);
|
|
568
|
+
fileOptions.output = path.join(parsed.dir, `${parsed.name}.protected${parsed.ext || ".js"}`);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const result = await protectFiles({
|
|
572
|
+
...fileOptions,
|
|
573
|
+
copyAssets: false
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
if (result.written.length !== 1) {
|
|
577
|
+
throw new Error(`Expected one protected file, wrote ${result.written.length}.`);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return result;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
async function obfuscateFile(options = {}, sourcePath, outputPath) {
|
|
584
|
+
return protectFile(options, sourcePath, outputPath);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
module.exports = {
|
|
588
|
+
...core,
|
|
589
|
+
createProtectionConfig,
|
|
590
|
+
ensureProtectionConfig,
|
|
591
|
+
obfuscate,
|
|
592
|
+
obfuscateCode,
|
|
593
|
+
obfuscateDirectory,
|
|
594
|
+
obfuscateFile,
|
|
595
|
+
obfuscateFiles,
|
|
596
|
+
obfuscateMultiple,
|
|
597
|
+
getOptionsByPreset,
|
|
598
|
+
protectCode,
|
|
599
|
+
protectDirectory,
|
|
600
|
+
protectFile,
|
|
601
|
+
protectFiles,
|
|
602
|
+
planProtection,
|
|
603
|
+
protectItems,
|
|
604
|
+
translateJsConfuserOptions,
|
|
605
|
+
translateJavascriptObfuscatorOptions,
|
|
606
|
+
ai,
|
|
607
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./jso.config.schema.json",
|
|
3
|
+
"endpoint": "https://www.javascriptobfuscator.com/HttpApi.ashx",
|
|
4
|
+
"apiKey": "$JSO_API_KEY",
|
|
5
|
+
"apiPassword": "$JSO_API_PASSWORD",
|
|
6
|
+
"projectName": "browser-release",
|
|
7
|
+
"input": "dist",
|
|
8
|
+
"output": "dist-protected",
|
|
9
|
+
"preset": "balanced",
|
|
10
|
+
"extensions": [".js", ".jsx"],
|
|
11
|
+
"exclude": ["**/*.map", "**/vendor/**", "**/*-obfuscated.js"],
|
|
12
|
+
"copyAssets": true,
|
|
13
|
+
"assetExclude": ["**/*.map"],
|
|
14
|
+
"mixedServer": false,
|
|
15
|
+
"parseHtml": false,
|
|
16
|
+
"honorConditionalComments": false,
|
|
17
|
+
"keepHeaderComment": true,
|
|
18
|
+
"protectObjectDeclaration": false,
|
|
19
|
+
"moveNestedFunction": false,
|
|
20
|
+
"formattedOutput": false,
|
|
21
|
+
"keepIndent": false,
|
|
22
|
+
"lineNumbers": false,
|
|
23
|
+
"reservedNames": ["^PublicApi$", "^keep_"],
|
|
24
|
+
"options": {
|
|
25
|
+
"OptimizationMode": "Web",
|
|
26
|
+
"LockDomain": false,
|
|
27
|
+
"LockDate": false
|
|
28
|
+
}
|
|
29
|
+
}
|