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.
Files changed (119) hide show
  1. package/CHANGELOG.md +960 -0
  2. package/LICENSE +90 -0
  3. package/MIGRATION.md +207 -0
  4. package/README.md +1477 -0
  5. package/RELEASE.md +82 -0
  6. package/SECURITY.md +71 -0
  7. package/ai-cli.js +392 -0
  8. package/ai.js +176 -0
  9. package/bin/jso-protector.js +12066 -0
  10. package/browserify.d.ts +10 -0
  11. package/browserify.js +88 -0
  12. package/bun.d.ts +10 -0
  13. package/bun.js +41 -0
  14. package/ci/Jenkinsfile +82 -0
  15. package/ci/argo-workflows.yaml +121 -0
  16. package/ci/azure-pipelines.yml +56 -0
  17. package/ci/bitbucket-pipelines.yml +43 -0
  18. package/ci/buildkite.yml +50 -0
  19. package/ci/circleci.yml +60 -0
  20. package/ci/drone.yml +67 -0
  21. package/ci/github-actions.yml +51 -0
  22. package/ci/gitlab-ci.yml +39 -0
  23. package/ci/gocd.yaml +79 -0
  24. package/ci/teamcity.kts +79 -0
  25. package/ci/tekton.yaml +106 -0
  26. package/ci/verify-package.js +748 -0
  27. package/ci/verify-publish-metadata.js +147 -0
  28. package/ci/verify-templates.js +195 -0
  29. package/ci/woodpecker.yml +53 -0
  30. package/compliance/cli.js +204 -0
  31. package/compliance/evidence-forwarder.js +209 -0
  32. package/compliance/pci-dss-v4/controls.json +75 -0
  33. package/compliance/pci-dss-v4/index.js +2613 -0
  34. package/config/named-sets.js +185 -0
  35. package/esbuild.d.ts +16 -0
  36. package/esbuild.js +190 -0
  37. package/examples/README.md +78 -0
  38. package/examples/browserify/build.js +20 -0
  39. package/examples/bun/package.json +13 -0
  40. package/examples/bun/scripts/protect-release.js +28 -0
  41. package/examples/cli-basic/jso.config.cjs +23 -0
  42. package/examples/cli-basic/jso.config.json +15 -0
  43. package/examples/cli-basic/package.json +14 -0
  44. package/examples/cli-basic/scripts/build.js +10 -0
  45. package/examples/curl/README.md +55 -0
  46. package/examples/curl/protect.sh +106 -0
  47. package/examples/esbuild/build.js +19 -0
  48. package/examples/grunt/Gruntfile.js +29 -0
  49. package/examples/gulp/gulpfile.js +19 -0
  50. package/examples/helm/Chart.yaml +27 -0
  51. package/examples/helm/README.md +69 -0
  52. package/examples/helm/templates/_helpers.tpl +23 -0
  53. package/examples/helm/templates/_podtemplate.tpl +64 -0
  54. package/examples/helm/templates/job.yaml +39 -0
  55. package/examples/helm/templates/secret.yaml +17 -0
  56. package/examples/helm/values.yaml +54 -0
  57. package/examples/kubernetes/job.yaml +123 -0
  58. package/examples/metro.config.js +11 -0
  59. package/examples/nextjs/next.config.js +11 -0
  60. package/examples/node-api/protect-release.js +28 -0
  61. package/examples/node-api/release-summary.js +59 -0
  62. package/examples/parcel/package.json +13 -0
  63. package/examples/parcel/scripts/protect-release.js +28 -0
  64. package/examples/payment-page-script-inventory.json +62 -0
  65. package/examples/payment-page-security-headers.json +46 -0
  66. package/examples/pre-commit/.pre-commit-config.yaml +33 -0
  67. package/examples/pre-commit/README.md +45 -0
  68. package/examples/react-native/README.md +208 -0
  69. package/examples/react-native/metro.config.js +11 -0
  70. package/examples/rollup/rollup.config.js +20 -0
  71. package/examples/rspack/rspack.config.js +28 -0
  72. package/examples/turbopack/package.json +13 -0
  73. package/examples/turbopack/scripts/protect-release.js +28 -0
  74. package/examples/vite/vite.config.js +18 -0
  75. package/examples/webpack/webpack.config.js +21 -0
  76. package/examples/webpack-loader/webpack.config.js +22 -0
  77. package/governance/index.d.ts +18 -0
  78. package/governance/index.js +309 -0
  79. package/grunt.d.ts +4 -0
  80. package/grunt.js +111 -0
  81. package/gulp.d.ts +10 -0
  82. package/gulp.js +106 -0
  83. package/index.d.ts +879 -0
  84. package/index.js +607 -0
  85. package/jso.config.example.json +29 -0
  86. package/jso.config.schema.json +548 -0
  87. package/metro.d.ts +43 -0
  88. package/metro.js +117 -0
  89. package/next.d.ts +24 -0
  90. package/next.js +64 -0
  91. package/package.json +241 -0
  92. package/parcel.d.ts +10 -0
  93. package/parcel.js +40 -0
  94. package/react-native.d.ts +2 -0
  95. package/react-native.js +3 -0
  96. package/release-signer.js +245 -0
  97. package/rollup.d.ts +13 -0
  98. package/rollup.js +71 -0
  99. package/rspack-loader.d.ts +13 -0
  100. package/rspack-loader.js +11 -0
  101. package/rspack.d.ts +11 -0
  102. package/rspack.js +9 -0
  103. package/runtime/ai-script-governance.js +379 -0
  104. package/runtime/countermeasures.js +0 -0
  105. package/runtime/data-exfiltration-guard.d.ts +7 -0
  106. package/runtime/data-exfiltration-guard.js +161 -0
  107. package/runtime/environment-integrity.js +389 -0
  108. package/runtime/managed-integrity.d.ts +4 -0
  109. package/runtime/managed-integrity.js +108 -0
  110. package/runtime/third-party-inventory.js +437 -0
  111. package/turbopack.d.ts +10 -0
  112. package/turbopack.js +41 -0
  113. package/vite.d.ts +16 -0
  114. package/vite.js +78 -0
  115. package/watermark.js +126 -0
  116. package/webpack-loader.d.ts +15 -0
  117. package/webpack-loader.js +97 -0
  118. package/webpack.d.ts +13 -0
  119. package/webpack.js +143 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ // Named configuration sets - apply a different protection profile to
4
+ // different parts of one app in a single build.
5
+ //
6
+ // Inspired by JSDefender v2's named sets: e.g. a checkout flow gets
7
+ // maximum-mode + RASP countermeasures, marketing pages get standard
8
+ // preset + simple beacon. Both ship from one CI run.
9
+ //
10
+ // The config schema accepts:
11
+ //
12
+ // {
13
+ // "preset": "balanced", // baseline applied to ALL files
14
+ // "options": { ... }, // baseline options
15
+ // "namedSets": {
16
+ // "checkout": {
17
+ // "match": ["src/checkout/**", "src/wallet/**"],
18
+ // "preset": "maximum",
19
+ // "options": { "AddDeadCode": true, "DeadcodeLevel": "High" },
20
+ // "countermeasures": { "onTamper": ["break", "deleteCookies"] }
21
+ // },
22
+ // "marketing": {
23
+ // "match": ["src/marketing/**"],
24
+ // "preset": "standard"
25
+ // }
26
+ // }
27
+ // }
28
+ //
29
+ // The resolver takes a list of file paths + the config and returns,
30
+ // per file, the *effective* preset + options + countermeasures. A
31
+ // file matched by multiple sets gets the FIRST listed set (config
32
+ // authors get deterministic precedence by writing sets in priority
33
+ // order, like CSS / route tables).
34
+ //
35
+ // Pure data-shaping: no I/O, no API calls. Easy to unit-test.
36
+
37
+ function resolveForFiles(config, files) {
38
+ const namedSets = (config && config.namedSets) || {};
39
+ const baselinePreset = (config && config.preset) || null;
40
+ const baselineOptions = (config && config.options) || {};
41
+ const setNames = Object.keys(namedSets);
42
+
43
+ const out = {};
44
+ for (const file of files) {
45
+ let chosen = null;
46
+ for (const name of setNames) {
47
+ const set = namedSets[name];
48
+ if (!set || !Array.isArray(set.match)) continue;
49
+ for (const pattern of set.match) {
50
+ if (matchGlob(pattern, file)) { chosen = { name: name, set: set }; break; }
51
+ }
52
+ if (chosen) break;
53
+ }
54
+ if (chosen) {
55
+ out[file] = {
56
+ set: chosen.name,
57
+ preset: chosen.set.preset || baselinePreset,
58
+ options: Object.assign({}, baselineOptions, chosen.set.options || {}),
59
+ countermeasures: chosen.set.countermeasures || (config && config.countermeasures) || null,
60
+ };
61
+ } else {
62
+ out[file] = {
63
+ set: null,
64
+ preset: baselinePreset,
65
+ options: Object.assign({}, baselineOptions),
66
+ countermeasures: (config && config.countermeasures) || null,
67
+ };
68
+ }
69
+ }
70
+ return out;
71
+ }
72
+
73
+ function resolveForFile(config, file) {
74
+ return resolveForFiles(config, [file])[file];
75
+ }
76
+
77
+ // Minimal glob matcher: supports **, *, ?, character classes [a-z],
78
+ // and brace expansion {a,b}. POSIX-style forward slashes only (we
79
+ // normalise backslashes on input). No `picomatch` / `minimatch`
80
+ // runtime dependency.
81
+ function matchGlob(pattern, input) {
82
+ const p = String(pattern).replace(/\\/g, "/");
83
+ const s = String(input).replace(/\\/g, "/");
84
+ // Expand braces first (one level).
85
+ const expanded = expandBraces(p);
86
+ for (const variant of expanded) {
87
+ const re = globToRegExp(variant);
88
+ if (re.test(s)) return true;
89
+ }
90
+ return false;
91
+ }
92
+
93
+ // Hard cap on total variants to prevent a malicious jso.config.json
94
+ // (e.g. 20 nested {a,b} groups = 1M variants) from DoS-ing the build.
95
+ const MAX_BRACE_VARIANTS = 256;
96
+
97
+ function expandBraces(pattern) {
98
+ const m = pattern.match(/^([^{]*)\{([^{}]+)\}(.*)$/);
99
+ if (!m) return [pattern];
100
+ const prefix = m[1], parts = m[2].split(","), suffix = m[3];
101
+ const out = [];
102
+ for (const p of parts) {
103
+ for (const tail of expandBraces(suffix)) {
104
+ if (out.length >= MAX_BRACE_VARIANTS) {
105
+ throw new Error(
106
+ "named-sets: glob brace expansion exceeded " + MAX_BRACE_VARIANTS +
107
+ " variants; simplify the pattern (got '" + pattern + "')"
108
+ );
109
+ }
110
+ out.push(prefix + p + tail);
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+
116
+ function globToRegExp(glob) {
117
+ // Build a regex incrementally so escaping is exact.
118
+ let re = "^";
119
+ let i = 0;
120
+ while (i < glob.length) {
121
+ const c = glob[i];
122
+ // /** at end of pattern: matches the leading dir plus
123
+ // ANY number of trailing segments (including zero, so
124
+ // `src/**` matches both `src` and `src/x/y/z`).
125
+ if (c === "/" && glob[i + 1] === "*" && glob[i + 2] === "*" && i + 3 === glob.length) {
126
+ re += "(?:/.*)?";
127
+ i += 3;
128
+ continue;
129
+ }
130
+ // /**/ in the middle: matches zero or more intermediate
131
+ // segments. `src/**/x.js` matches `src/x.js` AND
132
+ // `src/a/b/c/x.js`.
133
+ if (c === "/" && glob[i + 1] === "*" && glob[i + 2] === "*" && glob[i + 3] === "/") {
134
+ re += "(?:/.*)?/";
135
+ i += 4;
136
+ continue;
137
+ }
138
+ if (c === "*" && glob[i + 1] === "*") {
139
+ // Bare ** at start or alone: matches anything including slashes.
140
+ re += ".*";
141
+ i += 2;
142
+ if (glob[i] === "/") i++;
143
+ continue;
144
+ }
145
+ if (c === "*") {
146
+ // * matches anything except a slash
147
+ re += "[^/]*";
148
+ i++;
149
+ continue;
150
+ }
151
+ if (c === "?") {
152
+ re += "[^/]";
153
+ i++;
154
+ continue;
155
+ }
156
+ if (c === "[") {
157
+ // pass through character class verbatim
158
+ const close = glob.indexOf("]", i);
159
+ if (close < 0) { re += "\\["; i++; continue; }
160
+ re += glob.slice(i, close + 1);
161
+ i = close + 1;
162
+ continue;
163
+ }
164
+ // Escape regex specials. {} are included so a stray unmatched
165
+ // brace (left over after expandBraces) can't be reinterpreted
166
+ // as a quantifier-open by stricter regex engines.
167
+ if (/[.+^$()|\\{}]/.test(c)) {
168
+ re += "\\" + c;
169
+ i++;
170
+ continue;
171
+ }
172
+ re += c;
173
+ i++;
174
+ }
175
+ re += "$";
176
+ return new RegExp(re);
177
+ }
178
+
179
+ module.exports = {
180
+ resolveForFile: resolveForFile,
181
+ resolveForFiles: resolveForFiles,
182
+ matchGlob: matchGlob,
183
+ _globToRegExp: globToRegExp,
184
+ _expandBraces: expandBraces,
185
+ };
package/esbuild.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { ProtectionOptions } from "./index";
2
+
3
+ export interface JsoProtectorPluginOptions extends ProtectionOptions {
4
+ removeSourceMaps?: boolean;
5
+ }
6
+
7
+ declare function jsoProtector(options?: JsoProtectorPluginOptions): {
8
+ name: "jso-protector";
9
+ setup(build: {
10
+ initialOptions?: Record<string, unknown>;
11
+ onEnd(callback: (result: { outputFiles?: unknown[] }) => void | Promise<void>): void;
12
+ }): void;
13
+ };
14
+
15
+ export { jsoProtector };
16
+ export default jsoProtector;
package/esbuild.js ADDED
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { assertSizeBudgets, buildItemsManifest, buildProtectionItemsFromInputItems, composeProtectionItemOutput, createProtectionConfig, isExcluded, protectItems, writeManifest } = require("./index.js");
6
+
7
+ function jsoProtector(options = {}) {
8
+ const removeSourceMaps = options.removeSourceMaps !== false;
9
+
10
+ return {
11
+ name: "jso-protector",
12
+ setup(build) {
13
+ build.onEnd(async (result) => {
14
+ const initialOptions = build.initialOptions || {};
15
+ const outputRoot = getOutputRoot(initialOptions);
16
+ const config = createProtectionConfig({
17
+ input: outputRoot,
18
+ output: outputRoot,
19
+ ...options
20
+ });
21
+
22
+ if (Array.isArray(result.outputFiles)) {
23
+ await protectOutputFiles(result.outputFiles, config, options, removeSourceMaps, outputRoot);
24
+ return;
25
+ }
26
+
27
+ await protectWrittenFiles(initialOptions, config, options, removeSourceMaps, outputRoot);
28
+ });
29
+ }
30
+ };
31
+ }
32
+
33
+ async function protectOutputFiles(outputFiles, config, options, removeSourceMaps, outputRoot) {
34
+ const files = outputFiles.filter((file) => (
35
+ file &&
36
+ file.path &&
37
+ hasProtectedExtension(file.path, config.extensions) &&
38
+ shouldProtectAsset(toAssetName(outputRoot, file.path), config, options)
39
+ ));
40
+
41
+ if (!files.length) return;
42
+
43
+ const inputItems = files.map((file) => ({
44
+ FileName: toAssetName(outputRoot, file.path),
45
+ FileCode: outputFileText(file),
46
+ SourcePath: file.path,
47
+ OutputPath: file.path
48
+ }));
49
+ const protection = buildProtectionItemsFromInputItems(config, inputItems);
50
+ const result = await protectItems(config, protection.items);
51
+ const manifest = buildItemsManifest(config, inputItems, result, (fileName) => fileName, protection.transforms);
52
+ assertSizeBudgets(manifest, config);
53
+
54
+ for (const file of files) {
55
+ const assetName = toAssetName(outputRoot, file.path);
56
+ const code = composeProtectionItemOutput(assetName, result, protection.transforms, config);
57
+ file.contents = Buffer.from(code, "utf8");
58
+ if (Object.prototype.hasOwnProperty.call(file, "text")) {
59
+ try {
60
+ file.text = code;
61
+ } catch (_error) {
62
+ // esbuild exposes text as a getter; tests may use a writable field.
63
+ }
64
+ }
65
+ }
66
+
67
+ if (removeSourceMaps) {
68
+ for (let i = outputFiles.length - 1; i >= 0; i -= 1) {
69
+ const assetName = toAssetName(outputRoot, outputFiles[i].path || "");
70
+ if (isProtectedSourceMap(assetName, config.extensions)) outputFiles.splice(i, 1);
71
+ }
72
+ }
73
+
74
+ if (config.manifest) {
75
+ writeManifest(config.manifest, manifest);
76
+ }
77
+ }
78
+
79
+ async function protectWrittenFiles(initialOptions, config, options, removeSourceMaps, outputRoot) {
80
+ const targets = collectWrittenJavaScript(initialOptions, outputRoot, config.extensions)
81
+ .filter((file) => shouldProtectAsset(file.relative, config, options));
82
+
83
+ if (!targets.length) return;
84
+
85
+ const inputItems = targets.map((file) => ({
86
+ FileName: file.relative,
87
+ FileCode: fs.readFileSync(file.path, "utf8"),
88
+ SourcePath: file.path,
89
+ OutputPath: file.path
90
+ }));
91
+ const protection = buildProtectionItemsFromInputItems(config, inputItems);
92
+ const result = await protectItems(config, protection.items);
93
+ const manifest = buildItemsManifest(config, inputItems, result, (fileName) => {
94
+ const found = targets.find((target) => normalizeName(target.relative) === normalizeName(fileName));
95
+ return found ? found.path : fileName;
96
+ }, protection.transforms);
97
+ assertSizeBudgets(manifest, config);
98
+
99
+ for (const file of targets) {
100
+ fs.writeFileSync(file.path, composeProtectionItemOutput(file.relative, result, protection.transforms, config), "utf8");
101
+ if (removeSourceMaps) {
102
+ const mapPath = `${file.path}.map`;
103
+ if (fs.existsSync(mapPath)) fs.unlinkSync(mapPath);
104
+ }
105
+ }
106
+
107
+ if (config.manifest) {
108
+ writeManifest(config.manifest, manifest);
109
+ }
110
+ }
111
+
112
+ function collectWrittenJavaScript(initialOptions, outputRoot, extensions) {
113
+ if (initialOptions.outfile) {
114
+ if (!hasProtectedExtension(initialOptions.outfile, extensions) || !fs.existsSync(initialOptions.outfile)) return [];
115
+ return [{
116
+ path: initialOptions.outfile,
117
+ relative: path.basename(initialOptions.outfile)
118
+ }];
119
+ }
120
+
121
+ if (!outputRoot || !fs.existsSync(outputRoot)) return [];
122
+
123
+ const files = [];
124
+ walk(outputRoot, (filePath) => {
125
+ if (!hasProtectedExtension(filePath, extensions)) return;
126
+ files.push({
127
+ path: filePath,
128
+ relative: normalizeName(path.relative(outputRoot, filePath))
129
+ });
130
+ });
131
+ return files;
132
+ }
133
+
134
+ function walk(dir, visit) {
135
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
136
+ const entryPath = path.join(dir, entry.name);
137
+ if (entry.isDirectory()) walk(entryPath, visit);
138
+ else if (entry.isFile()) visit(entryPath);
139
+ }
140
+ }
141
+
142
+ function getOutputRoot(initialOptions) {
143
+ if (initialOptions.outdir) return initialOptions.outdir;
144
+ if (initialOptions.outfile) return path.dirname(initialOptions.outfile);
145
+ return "dist";
146
+ }
147
+
148
+ function outputFileText(file) {
149
+ if (typeof file.text === "string") return file.text;
150
+ if (file.contents) return Buffer.from(file.contents).toString("utf8");
151
+ return "";
152
+ }
153
+
154
+ function toAssetName(outputRoot, filePath) {
155
+ if (!filePath) return "";
156
+ const normalizedPath = normalizeName(filePath);
157
+ const normalizedRoot = normalizeName(path.resolve(outputRoot || "."));
158
+ const resolvedPath = normalizeName(path.resolve(filePath));
159
+ if (resolvedPath.startsWith(`${normalizedRoot}/`)) {
160
+ return resolvedPath.slice(normalizedRoot.length + 1);
161
+ }
162
+ return path.basename(normalizedPath);
163
+ }
164
+
165
+ function shouldProtectAsset(fileName, config, options) {
166
+ const normalized = normalizeName(fileName);
167
+ const include = Array.isArray(config.include) && config.include.length ? config.include : options.include;
168
+ if (Array.isArray(include) && include.length && !isExcluded(normalized, include)) {
169
+ return false;
170
+ }
171
+ return !isExcluded(normalized, config.exclude || []);
172
+ }
173
+
174
+ function normalizeName(name) {
175
+ return String(name || "").replace(/\\/g, "/");
176
+ }
177
+
178
+ function hasProtectedExtension(filePath, extensions) {
179
+ const normalizedExtensions = Array.isArray(extensions) && extensions.length ? extensions : [".js"];
180
+ return normalizedExtensions.some((extension) => String(filePath || "").endsWith(extension));
181
+ }
182
+
183
+ function isProtectedSourceMap(filePath, extensions) {
184
+ const normalizedExtensions = Array.isArray(extensions) && extensions.length ? extensions : [".js"];
185
+ return normalizedExtensions.some((extension) => String(filePath || "").endsWith(`${extension}.map`));
186
+ }
187
+
188
+ module.exports = jsoProtector;
189
+ module.exports.jsoProtector = jsoProtector;
190
+ module.exports.default = jsoProtector;
@@ -0,0 +1,78 @@
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 this package from the local workspace path or an internal tarball before running examples. It is intentionally not published to npm:
38
+
39
+ ```bash
40
+ npm install --save-dev ../packages/jso-protector
41
+ ```
42
+
43
+ All examples expect API credentials in environment variables:
44
+
45
+ ```bash
46
+ set JSO_API_KEY=base64-api-key-from-dashboard
47
+ set JSO_API_PASSWORD=base64-api-password-from-dashboard
48
+ ```
49
+
50
+ Use CI secrets for shared pipelines.
51
+
52
+ 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.
53
+
54
+ 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.
55
+
56
+ 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.
57
+
58
+ 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.
59
+
60
+ ## Protected regions
61
+
62
+ 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.
63
+
64
+ ```js
65
+ jsoProtector({
66
+ apiKey: process.env.JSO_API_KEY,
67
+ apiPassword: process.env.JSO_API_PASSWORD,
68
+ preset: "balanced",
69
+ honorConditionalComments: true
70
+ });
71
+ ```
72
+
73
+ ```js
74
+ console.log("protect this");
75
+ // javascript-obfuscator:disable
76
+ console.log("leave this exact code alone");
77
+ // javascript-obfuscator:enable
78
+ ```
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ const browserify = require("browserify");
4
+ const fs = require("fs");
5
+ const jsoProtector = require("jso-protector/browserify");
6
+
7
+ browserify("src/app.js", {
8
+ transform: [[jsoProtector, {
9
+ apiKey: process.env.JSO_API_KEY,
10
+ apiPassword: process.env.JSO_API_PASSWORD,
11
+ input: "src",
12
+ preset: "balanced",
13
+ include: ["**/*.js"],
14
+ reservedNames: ["^PublicApi$"],
15
+ manifest: "dist/jso-manifest.json",
16
+ maxGrowthRatio: 8
17
+ }]]
18
+ })
19
+ .bundle()
20
+ .pipe(fs.createWriteStream("dist/app.js"));
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "jso-protector-bun-example",
3
+ "private": true,
4
+ "scripts": {
5
+ "build": "bun build ./src/index.ts --outdir ./dist --target browser",
6
+ "preflight": "node ./scripts/protect-release.js --plan",
7
+ "protect": "node ./scripts/protect-release.js",
8
+ "release": "bun run build && node ./scripts/protect-release.js --plan && node ./scripts/protect-release.js"
9
+ },
10
+ "devDependencies": {
11
+ "jso-protector": "file:../.."
12
+ }
13
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ const protectBunBuild = require("jso-protector/bun");
4
+
5
+ const options = {
6
+ apiKey: process.env.JSO_API_KEY,
7
+ apiPassword: process.env.JSO_API_PASSWORD
8
+ };
9
+
10
+ async function main() {
11
+ const planOnly = process.argv.includes("--plan");
12
+ const plan = protectBunBuild.planBunBuild(options);
13
+
14
+ console.log(`Protecting ${plan.summary.files.length} Bun output file(s).`);
15
+
16
+ if (planOnly) {
17
+ console.log(`Copying ${plan.summary.assets.length} Bun asset(s).`);
18
+ return;
19
+ }
20
+
21
+ const result = await protectBunBuild(options);
22
+ console.log(`Wrote ${result.written.length} protected file(s) and copied ${result.copied.length} asset(s).`);
23
+ }
24
+
25
+ main().catch((error) => {
26
+ console.error(error.message);
27
+ process.exitCode = 1;
28
+ });
@@ -0,0 +1,23 @@
1
+ module.exports = ({ env }) => ({
2
+ endpoint: env.JSO_ENDPOINT || "https://www.javascriptobfuscator.com/HttpApi.ashx",
3
+ apiKey: "$JSO_API_KEY",
4
+ apiPassword: "$JSO_API_PASSWORD",
5
+ projectName: env.CI ? "browser-release-ci" : "browser-release-local",
6
+ input: env.JSO_INPUT || "dist",
7
+ output: env.JSO_OUTPUT || "dist-protected",
8
+ preset: env.JSO_PRESET || "balanced",
9
+ extensions: [".js", ".jsx"],
10
+ exclude: ["**/*.map", "**/vendor/**", "**/*-obfuscated.js"],
11
+ copyAssets: true,
12
+ assetExclude: ["**/*.map"],
13
+ parseHtml: false,
14
+ honorConditionalComments: false,
15
+ reservedNames: ["^PublicApi$", "^keep_"],
16
+ manifest: "dist-protected/jso-manifest.json",
17
+ maxGrowthRatio: 8,
18
+ options: {
19
+ OptimizationMode: "Web",
20
+ LockDomain: Boolean(env.RELEASE_DOMAIN),
21
+ LockDomainList: env.RELEASE_DOMAIN || ""
22
+ }
23
+ });
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "../../jso.config.schema.json",
3
+ "apiKey": "$JSO_API_KEY",
4
+ "apiPassword": "$JSO_API_PASSWORD",
5
+ "projectName": "cli-example",
6
+ "input": "dist",
7
+ "output": "dist-protected",
8
+ "preset": "balanced",
9
+ "exclude": ["**/*.map", "**/vendor/**", "**/*-obfuscated.js"],
10
+ "copyAssets": true,
11
+ "assetExclude": ["**/*.map"],
12
+ "parseHtml": false,
13
+ "honorConditionalComments": false,
14
+ "reservedNames": ["^PublicApi$", "^renderWidget$"]
15
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "jso-protector-cli-example",
3
+ "private": true,
4
+ "scripts": {
5
+ "build": "node ./scripts/build.js",
6
+ "preflight": "jso-protector --config jso.config.json --release-check --json",
7
+ "doctor": "jso-protector --config jso.config.json --doctor --json",
8
+ "protect": "jso-protector --config jso.config.json",
9
+ "release": "npm run build && npm run preflight && npm run protect"
10
+ },
11
+ "devDependencies": {
12
+ "jso-protector": "file:../.."
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const dist = path.join(__dirname, "..", "dist");
7
+ fs.mkdirSync(dist, { recursive: true });
8
+ fs.writeFileSync(path.join(dist, "app.js"), "window.PublicApi = { renderWidget(){ console.log('release'); } };\n", "utf8");
9
+ fs.writeFileSync(path.join(dist, "index.html"), "<script src=\"app.js\"></script>\n", "utf8");
10
+ console.log("built dist/");
@@ -0,0 +1,55 @@
1
+ # curl / bash reference implementation
2
+
3
+ The smallest possible compliant client of the [JSO HTTP API](https://www.javascriptobfuscator.com/Docs/WireFormat.aspx). Use this when:
4
+
5
+ - You need to add JSO protection to a build pipeline written in a language we don't ship a client for.
6
+ - You want a copy-paste reference for what the wire format actually looks like on the network.
7
+ - You're debugging an API call and want to bypass any client-side magic.
8
+
9
+ ## Requirements
10
+
11
+ - `bash` (any modern version)
12
+ - `curl`
13
+ - `jq`
14
+
15
+ ## Usage
16
+
17
+ ```bash
18
+ export JSO_API_KEY="<base64-from-dashboard>"
19
+ export JSO_API_PASSWORD="<base64-from-dashboard>"
20
+
21
+ # Protect a single file (input/output pair):
22
+ ./protect.sh dist/app.js dist-protected/app.js
23
+
24
+ # Or several pairs at once:
25
+ ./protect.sh \
26
+ dist/app.js dist-protected/app.js \
27
+ dist/vendor.js dist-protected/vendor.js
28
+
29
+ # Pick a preset:
30
+ JSO_PRESET=maximum ./protect.sh dist/app.js dist-protected/app.js
31
+
32
+ # Tag the release:
33
+ JSO_LABEL="$(git rev-parse HEAD)" ./protect.sh dist/app.js dist-protected/app.js
34
+ ```
35
+
36
+ ## Limitations
37
+
38
+ This is a 100-line shell script. It deliberately doesn't implement:
39
+
40
+ - The `--dry-run` / `--release-check` validation modes (use the npm CLI for those).
41
+ - Identifier-map persistence as a separate `jso-report.json` file (parse `Report.GlobalIdentifierMap` / `Report.MemberIdentifierMap` from the response yourself).
42
+ - The bundler-plugin integration surface (`vite`, `webpack`, `rollup`, ...).
43
+ - Retry logic, exponential backoff, or rate-limit handling.
44
+
45
+ For a production CI integration, use one of the [shipped language clients](https://www.javascriptobfuscator.com/Docs/Clients.aspx) instead. The shell script is a reference, not a target.
46
+
47
+ ## Verify the response shape
48
+
49
+ ```bash
50
+ JSO_API_KEY=... JSO_API_PASSWORD=... ./protect.sh dist/app.js dist-protected/app.js
51
+ # protect.sh: wrote dist-protected/app.js
52
+ # protect.sh: BuildId=rel-abcdef123 Fingerprint=1234567890abcdef
53
+ ```
54
+
55
+ If you see "BuildId=" with an empty value, the server response didn't carry the field — check that your account is on Basic+ and the API key is current.