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
package/ai.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ // JSO AI client. Wraps the four /v1/ai/* endpoints documented at
4
+ // https://www.javascriptobfuscator.com/Docs/AIApi.aspx
5
+ //
6
+ // Same auth model as the protect API: { apiKey, apiPassword } (base64
7
+ // values from the dashboard). Reads JSO_API_KEY / JSO_API_PASSWORD from
8
+ // the environment if not passed explicitly, matching the CLI's behavior.
9
+ //
10
+ // Zero dependencies. Node 18+ recommended (uses global fetch); falls
11
+ // back to node:https on older runtimes.
12
+
13
+ const http = require("node:http");
14
+ const https = require("node:https");
15
+
16
+ const DEFAULT_ENDPOINT = "https://www.javascriptobfuscator.com";
17
+
18
+ function resolveCredentials(opts = {}) {
19
+ const apiKey = opts.apiKey || process.env.JSO_API_KEY;
20
+ const apiPassword = opts.apiPassword || process.env.JSO_API_PASSWORD;
21
+ if (!apiKey || !apiPassword) {
22
+ const err = new Error(
23
+ "JSO AI: APIKey / APIPwd required. Pass {apiKey, apiPassword} or set " +
24
+ "JSO_API_KEY / JSO_API_PASSWORD environment variables.");
25
+ err.code = "auth_missing";
26
+ throw err;
27
+ }
28
+ return { apiKey, apiPassword };
29
+ }
30
+
31
+ function resolveEndpoint(opts = {}) {
32
+ return (opts.endpoint || process.env.JSO_BASE_URL || DEFAULT_ENDPOINT)
33
+ .replace(/\/+$/, "");
34
+ }
35
+
36
+ // Post JSON to the given path. Resolves with the parsed envelope.
37
+ // Rejects with an Error carrying .status + .body for HTTP-level failures
38
+ // (405, 429, 5xx). Business-logic errors (ok:false) come back as a normal
39
+ // resolved value with body.ok === false; callers branch on that.
40
+ function postJson(url, body, timeoutMs) {
41
+ return new Promise((resolve, reject) => {
42
+ const u = new URL(url);
43
+ const client = u.protocol === "http:" ? http : https;
44
+ const payload = JSON.stringify(body);
45
+ const req = client.request({
46
+ method: "POST",
47
+ hostname: u.hostname,
48
+ port: u.port || (u.protocol === "http:" ? 80 : 443),
49
+ path: u.pathname + (u.search || ""),
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ "Content-Length": Buffer.byteLength(payload),
53
+ "User-Agent": "jso-protector-node/ai",
54
+ },
55
+ timeout: timeoutMs || 30000,
56
+ }, (res) => {
57
+ const chunks = [];
58
+ res.on("data", c => chunks.push(c));
59
+ res.on("end", () => {
60
+ const text = Buffer.concat(chunks).toString("utf8");
61
+ let parsed = null;
62
+ try { parsed = JSON.parse(text); } catch { /* leave null */ }
63
+ if (res.statusCode < 200 || res.statusCode >= 300) {
64
+ const err = new Error("HTTP " + res.statusCode + " from " + u.pathname);
65
+ err.status = res.statusCode;
66
+ err.body = parsed || text;
67
+ return reject(err);
68
+ }
69
+ if (parsed === null) {
70
+ return reject(new Error("Non-JSON response from " + u.pathname));
71
+ }
72
+ resolve(parsed);
73
+ });
74
+ });
75
+ req.on("timeout", () => req.destroy(new Error("Request timed out after " + (timeoutMs || 30000) + "ms")));
76
+ req.on("error", reject);
77
+ req.write(payload);
78
+ req.end();
79
+ });
80
+ }
81
+
82
+ function buildBody(creds, extra) {
83
+ return Object.assign({ APIKey: creds.apiKey, APIPwd: creds.apiPassword }, extra || {});
84
+ }
85
+
86
+ /**
87
+ * Ask the preset assistant to suggest a `jso.config.json` from a natural-
88
+ * language description.
89
+ *
90
+ * const { suggestion } = await ai.presetSuggest({
91
+ * description: "React SaaS frontend, balanced performance, lock to example.com"
92
+ * });
93
+ * fs.writeFileSync("jso.config.json", JSON.stringify(suggestion.config, null, 2));
94
+ */
95
+ async function presetSuggest(opts = {}) {
96
+ const creds = resolveCredentials(opts);
97
+ const endpoint = resolveEndpoint(opts);
98
+ if (!opts.description) {
99
+ const err = new Error("ai.presetSuggest: 'description' is required");
100
+ err.code = "input_invalid";
101
+ throw err;
102
+ }
103
+ return postJson(endpoint + "/v1/ai/preset-suggest.ashx",
104
+ buildBody(creds, { description: opts.description }),
105
+ opts.timeoutMs);
106
+ }
107
+
108
+ /**
109
+ * Scan a JS source string for patterns that won't survive obfuscation
110
+ * (eval, debugger, document.write, source maps, etc.). Returns a structured
111
+ * findings report.
112
+ *
113
+ * const { report } = await ai.compatCheck({
114
+ * source: fs.readFileSync("src/app.js", "utf8"),
115
+ * framework: "react"
116
+ * });
117
+ * if (report.summary.errors > 0) process.exit(1);
118
+ */
119
+ async function compatCheck(opts = {}) {
120
+ const creds = resolveCredentials(opts);
121
+ const endpoint = resolveEndpoint(opts);
122
+ if (!opts.source) {
123
+ const err = new Error("ai.compatCheck: 'source' is required");
124
+ err.code = "input_invalid";
125
+ throw err;
126
+ }
127
+ const body = { source: opts.source };
128
+ if (opts.framework) body.framework = opts.framework;
129
+ return postJson(endpoint + "/v1/ai/compat-check.ashx",
130
+ buildBody(creds, body),
131
+ opts.timeoutMs);
132
+ }
133
+
134
+ /**
135
+ * Diagnose a protected-output runtime error. Returns the likely JSO
136
+ * transform that caused it + a recommended fix.
137
+ *
138
+ * const { explanation } = await ai.explainError({
139
+ * error: "Uncaught TypeError: api.charge is not a function"
140
+ * });
141
+ * console.log(explanation.transform, "->", explanation.fix);
142
+ */
143
+ async function explainError(opts = {}) {
144
+ const creds = resolveCredentials(opts);
145
+ const endpoint = resolveEndpoint(opts);
146
+ if (!opts.error) {
147
+ const err = new Error("ai.explainError: 'error' is required");
148
+ err.code = "input_invalid";
149
+ throw err;
150
+ }
151
+ const body = { error: opts.error };
152
+ if (opts.config) body.config = opts.config;
153
+ return postJson(endpoint + "/v1/ai/explain-error.ashx",
154
+ buildBody(creds, body),
155
+ opts.timeoutMs);
156
+ }
157
+
158
+ /**
159
+ * Read the current-month AI quota counters for this account.
160
+ * Free to poll (this endpoint does not count against actionsCap).
161
+ *
162
+ * const u = await ai.usage();
163
+ * if (u.actionsRemaining < 5) console.warn("AI quota almost exhausted");
164
+ * if (u.providerKey && u.providerKey.status !== "ready") {
165
+ * console.warn("AI key health:", u.providerKey.label);
166
+ * }
167
+ */
168
+ async function usage(opts = {}) {
169
+ const creds = resolveCredentials(opts);
170
+ const endpoint = resolveEndpoint(opts);
171
+ return postJson(endpoint + "/v1/ai/usage.ashx",
172
+ buildBody(creds, {}),
173
+ opts.timeoutMs);
174
+ }
175
+
176
+ module.exports = { presetSuggest, compatCheck, explainError, usage };