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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Minimum-viable curl reference implementation of the JSO HTTP API client.
|
|
3
|
+
#
|
|
4
|
+
# Use this when the language you need isn't covered by one of the shipped
|
|
5
|
+
# clients (Node / Python / Go / .NET / Ruby / PHP / Rust). The script
|
|
6
|
+
# matches the wire format documented at
|
|
7
|
+
# https://www.javascriptobfuscator.com/Docs/WireFormat.aspx
|
|
8
|
+
#
|
|
9
|
+
# Required: curl, jq.
|
|
10
|
+
#
|
|
11
|
+
# Required env vars:
|
|
12
|
+
# JSO_API_KEY — base64 API key from the JSO dashboard
|
|
13
|
+
# JSO_API_PASSWORD — base64 API password from the JSO dashboard
|
|
14
|
+
#
|
|
15
|
+
# Optional env vars:
|
|
16
|
+
# JSO_PRESET — standard | balanced (default) | maximum
|
|
17
|
+
# JSO_LABEL — release label tagged on the request
|
|
18
|
+
# JSO_ENDPOINT — override the API endpoint URL
|
|
19
|
+
#
|
|
20
|
+
# Usage:
|
|
21
|
+
# ./protect.sh path/to/input.js path/to/output.js [more input/output pairs...]
|
|
22
|
+
|
|
23
|
+
set -euo pipefail
|
|
24
|
+
|
|
25
|
+
if ! command -v jq >/dev/null 2>&1; then
|
|
26
|
+
echo "protect.sh: jq is required (install via your package manager)" >&2
|
|
27
|
+
exit 2
|
|
28
|
+
fi
|
|
29
|
+
if [ -z "${JSO_API_KEY:-}" ] || [ -z "${JSO_API_PASSWORD:-}" ]; then
|
|
30
|
+
echo "protect.sh: JSO_API_KEY and JSO_API_PASSWORD must be set" >&2
|
|
31
|
+
exit 2
|
|
32
|
+
fi
|
|
33
|
+
if [ $# -lt 2 ] || [ $(($# % 2)) -ne 0 ]; then
|
|
34
|
+
echo "Usage: $0 input1.js output1.js [input2.js output2.js ...]" >&2
|
|
35
|
+
exit 2
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
preset="${JSO_PRESET:-balanced}"
|
|
39
|
+
endpoint="${JSO_ENDPOINT:-https://www.javascriptobfuscator.com/HttpApi.ashx}"
|
|
40
|
+
|
|
41
|
+
# Build the Items array from the (input, output) argument pairs.
|
|
42
|
+
items_json="[]"
|
|
43
|
+
pairs=()
|
|
44
|
+
while [ $# -ge 2 ]; do
|
|
45
|
+
in="$1"; out="$2"; shift 2
|
|
46
|
+
if [ ! -f "$in" ]; then echo "protect.sh: input not found: $in" >&2; exit 1; fi
|
|
47
|
+
pairs+=("$in:$out")
|
|
48
|
+
file_name="$(basename "$in")"
|
|
49
|
+
file_code="$(jq -Rs . < "$in")"
|
|
50
|
+
items_json="$(jq --arg n "$file_name" --argjson c "$file_code" \
|
|
51
|
+
'. += [{FileName: $n, FileCode: $c}]' <<< "$items_json")"
|
|
52
|
+
done
|
|
53
|
+
|
|
54
|
+
# Preset option blocks — keep these in sync with the WireFormat.aspx doc.
|
|
55
|
+
case "$preset" in
|
|
56
|
+
standard)
|
|
57
|
+
preset_opts='{"Compress":true,"EncodeStrings":true,"MoveStringsIntoArray":true,"NameMangling":true}' ;;
|
|
58
|
+
balanced)
|
|
59
|
+
preset_opts='{"Compress":true,"EncodeStrings":true,"EncryptStrings":true,"MoveStringsIntoArray":true,"NameMangling":true,"DeepObfuscate":true,"FlatTransform":true,"CodeTransposition":true}' ;;
|
|
60
|
+
maximum)
|
|
61
|
+
preset_opts='{"Compress":true,"EncodeStrings":true,"EncryptStrings":true,"MoveStringsIntoArray":true,"NameMangling":true,"DeepObfuscate":true,"FlatTransform":true,"CodeTransposition":true,"ProtectMembers":true,"RenameGlobals":true,"MoveMembers":true,"DeadCodeInsertion":true}' ;;
|
|
62
|
+
*) echo "protect.sh: unknown preset: $preset" >&2; exit 2 ;;
|
|
63
|
+
esac
|
|
64
|
+
|
|
65
|
+
# Assemble payload.
|
|
66
|
+
payload="$(jq -n \
|
|
67
|
+
--arg key "$JSO_API_KEY" \
|
|
68
|
+
--arg pwd "$JSO_API_PASSWORD" \
|
|
69
|
+
--arg name "${JSO_NAME:-bash-session}" \
|
|
70
|
+
--arg label "${JSO_LABEL:-}" \
|
|
71
|
+
--argjson items "$items_json" \
|
|
72
|
+
--argjson preset "$preset_opts" \
|
|
73
|
+
'{APIKey: $key, APIPwd: $pwd, Name: $name, Items: $items} + $preset
|
|
74
|
+
+ (if $label == "" then {} else {ReleaseLabel: $label} end)')"
|
|
75
|
+
|
|
76
|
+
# POST. -f fails on HTTP 4xx/5xx; -sS keeps quiet but surfaces errors.
|
|
77
|
+
response="$(curl -fsS -X POST \
|
|
78
|
+
-H "Content-Type: text/json" \
|
|
79
|
+
-H "User-Agent: jso-curl/0.1" \
|
|
80
|
+
--data "$payload" \
|
|
81
|
+
"$endpoint")"
|
|
82
|
+
|
|
83
|
+
type="$(jq -r '.Type' <<< "$response")"
|
|
84
|
+
if [ "$type" != "Succeed" ]; then
|
|
85
|
+
msg="$(jq -r '.Message // .ErrorCode // "API request failed"' <<< "$response")"
|
|
86
|
+
echo "protect.sh: $msg" >&2
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
# Write each protected file back to its output path.
|
|
91
|
+
for pair in "${pairs[@]}"; do
|
|
92
|
+
in="${pair%%:*}"; out="${pair#*:}"
|
|
93
|
+
file_name="$(basename "$in")"
|
|
94
|
+
code="$(jq -r --arg n "$file_name" '.Items[] | select(.FileName == $n) | .FileCode' <<< "$response")"
|
|
95
|
+
if [ -z "$code" ]; then
|
|
96
|
+
echo "protect.sh: API response did not include $file_name" >&2
|
|
97
|
+
exit 1
|
|
98
|
+
fi
|
|
99
|
+
mkdir -p "$(dirname "$out")"
|
|
100
|
+
printf '%s' "$code" > "$out"
|
|
101
|
+
echo "protect.sh: wrote $out"
|
|
102
|
+
done
|
|
103
|
+
|
|
104
|
+
build_id="$(jq -r '.Report.BuildId // ""' <<< "$response")"
|
|
105
|
+
fp="$(jq -r '.Report.PolymorphismFingerprint // ""' <<< "$response")"
|
|
106
|
+
echo "protect.sh: BuildId=$build_id Fingerprint=$fp"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const esbuild = require("esbuild");
|
|
2
|
+
const jsoProtector = require("jso-protector/esbuild");
|
|
3
|
+
|
|
4
|
+
esbuild.build({
|
|
5
|
+
entryPoints: ["src/app.js"],
|
|
6
|
+
bundle: true,
|
|
7
|
+
outdir: "dist",
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
plugins: [
|
|
10
|
+
jsoProtector({
|
|
11
|
+
apiKey: process.env.JSO_API_KEY,
|
|
12
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
13
|
+
preset: "balanced",
|
|
14
|
+
exclude: ["vendor.js"],
|
|
15
|
+
manifest: "dist/jso-manifest.json",
|
|
16
|
+
reservedNames: ["^PublicApi$"]
|
|
17
|
+
})
|
|
18
|
+
]
|
|
19
|
+
}).catch(() => process.exit(1));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function configureGrunt(grunt) {
|
|
4
|
+
grunt.initConfig({
|
|
5
|
+
jsoProtector: {
|
|
6
|
+
release: {
|
|
7
|
+
options: {
|
|
8
|
+
apiKey: process.env.JSO_API_KEY,
|
|
9
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
10
|
+
input: "dist",
|
|
11
|
+
output: "dist-protected",
|
|
12
|
+
preset: "balanced",
|
|
13
|
+
exclude: ["**/vendor/**"],
|
|
14
|
+
manifest: "dist-protected/jso-manifest.json",
|
|
15
|
+
maxGrowthRatio: 8
|
|
16
|
+
},
|
|
17
|
+
files: [{
|
|
18
|
+
expand: true,
|
|
19
|
+
cwd: "dist",
|
|
20
|
+
src: ["**/*.js", "!**/*.map"],
|
|
21
|
+
dest: "dist-protected"
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
require("jso-protector/grunt")(grunt);
|
|
28
|
+
grunt.registerTask("protect", ["jsoProtector:release"]);
|
|
29
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { dest, src } = require("gulp");
|
|
4
|
+
const jsoProtector = require("jso-protector/gulp");
|
|
5
|
+
|
|
6
|
+
function protect() {
|
|
7
|
+
return src(["dist/**/*.js", "dist/**/*.{css,html,png,svg}", "!dist/**/*.map"], { base: "dist" })
|
|
8
|
+
.pipe(jsoProtector({
|
|
9
|
+
apiKey: process.env.JSO_API_KEY,
|
|
10
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
11
|
+
preset: "balanced",
|
|
12
|
+
exclude: ["**/vendor/**"],
|
|
13
|
+
manifest: "dist-protected/jso-manifest.json",
|
|
14
|
+
maxGrowthRatio: 8
|
|
15
|
+
}))
|
|
16
|
+
.pipe(dest("dist-protected"));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.protect = protect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
apiVersion: v2
|
|
2
|
+
name: jso-protector
|
|
3
|
+
description: |
|
|
4
|
+
Run jso-protector as a Kubernetes Job. Wraps the npm CLI with secret-backed
|
|
5
|
+
credentials, configurable preset, and a side-car-free artifact pattern.
|
|
6
|
+
|
|
7
|
+
# JSO is not itself a long-running service — this chart deploys a Job, not a
|
|
8
|
+
# Deployment. Re-run by re-invoking `helm upgrade --install` or by templating
|
|
9
|
+
# a CronJob from the same values.
|
|
10
|
+
|
|
11
|
+
type: application
|
|
12
|
+
version: 0.1.0
|
|
13
|
+
appVersion: "0.2.0"
|
|
14
|
+
|
|
15
|
+
home: https://www.javascriptobfuscator.com/
|
|
16
|
+
sources:
|
|
17
|
+
- https://www.javascriptobfuscator.com/Docs/NpmCli.aspx
|
|
18
|
+
maintainers:
|
|
19
|
+
- name: JavaScript Obfuscator
|
|
20
|
+
url: https://www.javascriptobfuscator.com/contactus.aspx
|
|
21
|
+
|
|
22
|
+
keywords:
|
|
23
|
+
- javascript-obfuscator
|
|
24
|
+
- obfuscation
|
|
25
|
+
- protection
|
|
26
|
+
- kubernetes-job
|
|
27
|
+
- ci
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# jso-protector Helm chart
|
|
2
|
+
|
|
3
|
+
Deploy `jso-protector` as a one-shot Kubernetes Job — or, when `cron.schedule` is set, a recurring CronJob. Pairs with the [Tekton template](../../ci/tekton.yaml) for shops that already run Tekton; this chart is for everything else.
|
|
4
|
+
|
|
5
|
+
## Quick install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
helm install nightly-protect ./helm \
|
|
9
|
+
--set repo.url=https://github.com/your-org/your-repo.git \
|
|
10
|
+
--set repo.ref=$(git rev-parse HEAD) \
|
|
11
|
+
--set credentials.apiKey=$JSO_API_KEY \
|
|
12
|
+
--set credentials.apiPassword=$JSO_API_PASSWORD
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or, recommended for production, point at an existing Secret you manage out-of-band:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
kubectl create secret generic jso-credentials \
|
|
19
|
+
--from-literal=JSO_API_KEY=$JSO_API_KEY \
|
|
20
|
+
--from-literal=JSO_API_PASSWORD=$JSO_API_PASSWORD
|
|
21
|
+
|
|
22
|
+
helm install nightly-protect ./helm \
|
|
23
|
+
--set repo.url=https://github.com/your-org/your-repo.git \
|
|
24
|
+
--set repo.ref=$(git rev-parse HEAD) \
|
|
25
|
+
--set credentials.existingSecret=jso-credentials
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Recurring nightly protection
|
|
29
|
+
|
|
30
|
+
Set `cron.schedule` to a standard cron expression to deploy a `CronJob` instead of a one-shot `Job`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
helm install nightly-protect ./helm \
|
|
34
|
+
--set repo.url=... \
|
|
35
|
+
--set credentials.existingSecret=jso-credentials \
|
|
36
|
+
--set cron.schedule="0 2 * * *"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Concurrency policy is `Forbid` — if last night's run is still going, tonight's run is skipped rather than queued.
|
|
40
|
+
|
|
41
|
+
## Values
|
|
42
|
+
|
|
43
|
+
| Key | Default | Notes |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `repo.url` | placeholder | Git repo to clone in the init container. |
|
|
46
|
+
| `repo.ref` | `main` | Branch, tag, or SHA. |
|
|
47
|
+
| `credentials.existingSecret` | `""` | Use an out-of-band Secret if set; otherwise the chart creates one. |
|
|
48
|
+
| `credentials.apiKey` / `credentials.apiPassword` | `""` | Used only when `existingSecret` is empty. |
|
|
49
|
+
| `protect.configPath` | `jso.config.json` | jso-protector config in the repo. |
|
|
50
|
+
| `protect.preset` | `balanced` | `standard` / `balanced` / `maximum`. |
|
|
51
|
+
| `protect.manifestPath` / `protect.reportPath` | `dist-protected/...` | Where the manifest and report land in the workspace. |
|
|
52
|
+
| `images.git` / `images.node` | `alpine/git` / `node:22-alpine` | Override for air-gapped registries. |
|
|
53
|
+
| `cron.schedule` | `""` | When non-empty, deploy a CronJob. |
|
|
54
|
+
| `ttlSecondsAfterFinished` | `86400` | Job auto-cleanup after 1 day. |
|
|
55
|
+
|
|
56
|
+
## What you DON'T get
|
|
57
|
+
|
|
58
|
+
This chart deliberately does NOT include:
|
|
59
|
+
|
|
60
|
+
- **Artifact upload to S3 / GCS / Azure Blob.** Add a second container after the protect step, or pipe the report up via your existing CI artifact step. The chart focuses on running the protection cleanly — what you do with the output is a per-team decision.
|
|
61
|
+
- **Service / Ingress / Deployment.** JSO isn't a long-running service; it's a build step. If you find yourself wanting a Deployment here, you probably want the [hosted JSO API](https://www.javascriptobfuscator.com/) directly instead.
|
|
62
|
+
|
|
63
|
+
## Uninstall
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
helm uninstall nightly-protect
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The created Secret (if any) goes with it. The `ttlSecondsAfterFinished` field handles automatic cleanup of completed Jobs.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{{/*
|
|
2
|
+
Common labels applied to every resource in the chart.
|
|
3
|
+
*/}}
|
|
4
|
+
{{- define "jso-protector.labels" -}}
|
|
5
|
+
app.kubernetes.io/name: {{ .Chart.Name }}
|
|
6
|
+
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
7
|
+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
|
8
|
+
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
|
9
|
+
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
|
10
|
+
{{- end }}
|
|
11
|
+
|
|
12
|
+
{{/*
|
|
13
|
+
Name of the Secret holding JSO_API_KEY / JSO_API_PASSWORD. When the user
|
|
14
|
+
points us at an existing Secret we reuse it; otherwise we create one
|
|
15
|
+
named after the release.
|
|
16
|
+
*/}}
|
|
17
|
+
{{- define "jso-protector.secretName" -}}
|
|
18
|
+
{{- if .Values.credentials.existingSecret -}}
|
|
19
|
+
{{ .Values.credentials.existingSecret }}
|
|
20
|
+
{{- else -}}
|
|
21
|
+
{{ .Release.Name }}-credentials
|
|
22
|
+
{{- end -}}
|
|
23
|
+
{{- end }}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{{/*
|
|
2
|
+
Reusable pod template — referenced by both the Job and the CronJob in job.yaml.
|
|
3
|
+
*/}}
|
|
4
|
+
{{- define "jso-protector.podTemplate" -}}
|
|
5
|
+
metadata:
|
|
6
|
+
labels:
|
|
7
|
+
{{- include "jso-protector.labels" . | nindent 4 }}
|
|
8
|
+
spec:
|
|
9
|
+
restartPolicy: Never
|
|
10
|
+
initContainers:
|
|
11
|
+
- name: checkout
|
|
12
|
+
image: {{ .Values.images.git | quote }}
|
|
13
|
+
env:
|
|
14
|
+
- name: REPO_URL
|
|
15
|
+
value: {{ .Values.repo.url | quote }}
|
|
16
|
+
- name: REPO_REF
|
|
17
|
+
value: {{ .Values.repo.ref | quote }}
|
|
18
|
+
command:
|
|
19
|
+
- sh
|
|
20
|
+
- -c
|
|
21
|
+
- |
|
|
22
|
+
set -eu
|
|
23
|
+
cd /workspace
|
|
24
|
+
git clone --depth 1 --branch "$REPO_REF" "$REPO_URL" .
|
|
25
|
+
echo "Checked out $(git rev-parse HEAD)"
|
|
26
|
+
volumeMounts:
|
|
27
|
+
- name: workspace
|
|
28
|
+
mountPath: /workspace
|
|
29
|
+
containers:
|
|
30
|
+
- name: protect
|
|
31
|
+
image: {{ .Values.images.node | quote }}
|
|
32
|
+
workingDir: /workspace
|
|
33
|
+
envFrom:
|
|
34
|
+
- secretRef:
|
|
35
|
+
name: {{ include "jso-protector.secretName" . }}
|
|
36
|
+
command:
|
|
37
|
+
- sh
|
|
38
|
+
- -c
|
|
39
|
+
- |
|
|
40
|
+
set -eu
|
|
41
|
+
cd /workspace
|
|
42
|
+
SHA="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
|
|
43
|
+
|
|
44
|
+
npm ci --no-audit --no-fund
|
|
45
|
+
npm run build
|
|
46
|
+
npx jso-protector --config {{ .Values.protect.configPath }} --release-check --json
|
|
47
|
+
npx jso-protector --config {{ .Values.protect.configPath }} --competitor-gap-report --json
|
|
48
|
+
npx jso-protector \
|
|
49
|
+
--config {{ .Values.protect.configPath }} \
|
|
50
|
+
--preset {{ .Values.protect.preset }} \
|
|
51
|
+
--label "$SHA" \
|
|
52
|
+
--manifest {{ .Values.protect.manifestPath }} \
|
|
53
|
+
--report {{ .Values.protect.reportPath }}
|
|
54
|
+
|
|
55
|
+
ls -la "$(dirname {{ .Values.protect.manifestPath }})"
|
|
56
|
+
volumeMounts:
|
|
57
|
+
- name: workspace
|
|
58
|
+
mountPath: /workspace
|
|
59
|
+
resources:
|
|
60
|
+
{{- toYaml .Values.resources | nindent 8 }}
|
|
61
|
+
volumes:
|
|
62
|
+
- name: workspace
|
|
63
|
+
emptyDir: {}
|
|
64
|
+
{{- end }}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{{- /*
|
|
2
|
+
Toggle between Job and CronJob based on cron.schedule. The pod spec
|
|
3
|
+
itself is identical in both modes — only the wrapping kind/spec differs.
|
|
4
|
+
*/ -}}
|
|
5
|
+
{{- $podSpec := .Files.Get "templates/_podspec.tpl" -}}
|
|
6
|
+
{{- if .Values.cron.schedule }}
|
|
7
|
+
apiVersion: batch/v1
|
|
8
|
+
kind: CronJob
|
|
9
|
+
metadata:
|
|
10
|
+
name: {{ .Release.Name }}
|
|
11
|
+
labels:
|
|
12
|
+
{{- include "jso-protector.labels" . | nindent 4 }}
|
|
13
|
+
spec:
|
|
14
|
+
schedule: {{ .Values.cron.schedule | quote }}
|
|
15
|
+
successfulJobsHistoryLimit: {{ .Values.cron.successfulJobsHistoryLimit }}
|
|
16
|
+
failedJobsHistoryLimit: {{ .Values.cron.failedJobsHistoryLimit }}
|
|
17
|
+
concurrencyPolicy: Forbid
|
|
18
|
+
jobTemplate:
|
|
19
|
+
metadata:
|
|
20
|
+
labels:
|
|
21
|
+
{{- include "jso-protector.labels" . | nindent 8 }}
|
|
22
|
+
spec:
|
|
23
|
+
backoffLimit: 0
|
|
24
|
+
ttlSecondsAfterFinished: {{ .Values.ttlSecondsAfterFinished }}
|
|
25
|
+
template:
|
|
26
|
+
{{- include "jso-protector.podTemplate" . | nindent 8 }}
|
|
27
|
+
{{- else }}
|
|
28
|
+
apiVersion: batch/v1
|
|
29
|
+
kind: Job
|
|
30
|
+
metadata:
|
|
31
|
+
name: {{ .Release.Name }}
|
|
32
|
+
labels:
|
|
33
|
+
{{- include "jso-protector.labels" . | nindent 4 }}
|
|
34
|
+
spec:
|
|
35
|
+
backoffLimit: 0
|
|
36
|
+
ttlSecondsAfterFinished: {{ .Values.ttlSecondsAfterFinished }}
|
|
37
|
+
template:
|
|
38
|
+
{{- include "jso-protector.podTemplate" . | nindent 4 }}
|
|
39
|
+
{{- end }}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{{- /*
|
|
2
|
+
Only emit a Secret when the user did NOT supply an existingSecret.
|
|
3
|
+
stringData lets the values stay readable in the manifest; Kubernetes
|
|
4
|
+
base64-encodes them on apply.
|
|
5
|
+
*/ -}}
|
|
6
|
+
{{- if not .Values.credentials.existingSecret }}
|
|
7
|
+
apiVersion: v1
|
|
8
|
+
kind: Secret
|
|
9
|
+
metadata:
|
|
10
|
+
name: {{ include "jso-protector.secretName" . }}
|
|
11
|
+
labels:
|
|
12
|
+
{{- include "jso-protector.labels" . | nindent 4 }}
|
|
13
|
+
type: Opaque
|
|
14
|
+
stringData:
|
|
15
|
+
JSO_API_KEY: {{ required "credentials.apiKey is required when credentials.existingSecret is empty" .Values.credentials.apiKey | quote }}
|
|
16
|
+
JSO_API_PASSWORD: {{ required "credentials.apiPassword is required when credentials.existingSecret is empty" .Values.credentials.apiPassword | quote }}
|
|
17
|
+
{{- end }}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Default values for the jso-protector Helm chart.
|
|
2
|
+
#
|
|
3
|
+
# Use:
|
|
4
|
+
# helm install jso-protect ./helm \
|
|
5
|
+
# --set repo.url=https://github.com/your-org/your-repo.git \
|
|
6
|
+
# --set repo.ref=$(git rev-parse HEAD) \
|
|
7
|
+
# --set credentials.apiKey=$JSO_API_KEY \
|
|
8
|
+
# --set credentials.apiPassword=$JSO_API_PASSWORD
|
|
9
|
+
|
|
10
|
+
# Repository to clone in the init container.
|
|
11
|
+
repo:
|
|
12
|
+
url: "https://github.com/your-org/your-repo.git"
|
|
13
|
+
ref: "main"
|
|
14
|
+
|
|
15
|
+
# Where the credentials come from. Two options:
|
|
16
|
+
# 1. Inline (NOT recommended for production): set apiKey / apiPassword
|
|
17
|
+
# directly here. Helm will create the Secret.
|
|
18
|
+
# 2. existingSecret: name of a pre-created Secret with JSO_API_KEY and
|
|
19
|
+
# JSO_API_PASSWORD keys. Leave apiKey / apiPassword empty.
|
|
20
|
+
credentials:
|
|
21
|
+
existingSecret: ""
|
|
22
|
+
apiKey: ""
|
|
23
|
+
apiPassword: ""
|
|
24
|
+
|
|
25
|
+
# jso-protector configuration.
|
|
26
|
+
protect:
|
|
27
|
+
configPath: "jso.config.json"
|
|
28
|
+
preset: "balanced" # standard | balanced | maximum
|
|
29
|
+
manifestPath: "dist-protected/jso-manifest.json"
|
|
30
|
+
reportPath: "dist-protected/jso-report.json"
|
|
31
|
+
|
|
32
|
+
# Container images.
|
|
33
|
+
images:
|
|
34
|
+
git: "alpine/git:2.43.0"
|
|
35
|
+
node: "node:22-alpine"
|
|
36
|
+
|
|
37
|
+
# Resources for the protect container.
|
|
38
|
+
resources:
|
|
39
|
+
requests:
|
|
40
|
+
cpu: "500m"
|
|
41
|
+
memory: "512Mi"
|
|
42
|
+
limits:
|
|
43
|
+
cpu: "2000m"
|
|
44
|
+
memory: "2Gi"
|
|
45
|
+
|
|
46
|
+
# Optional CronJob mode. When `cron.schedule` is set, the chart deploys a
|
|
47
|
+
# CronJob instead of a one-shot Job. Useful for nightly protection runs.
|
|
48
|
+
cron:
|
|
49
|
+
schedule: "" # e.g. "0 2 * * *" for 2am UTC nightly
|
|
50
|
+
successfulJobsHistoryLimit: 3
|
|
51
|
+
failedJobsHistoryLimit: 5
|
|
52
|
+
|
|
53
|
+
# How long the completed Job hangs around before garbage-collected.
|
|
54
|
+
ttlSecondsAfterFinished: 86400
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Standalone Kubernetes Job for jso-protector.
|
|
2
|
+
#
|
|
3
|
+
# Use this when you want a one-shot protection run without bringing in
|
|
4
|
+
# Tekton or Argo. The Job:
|
|
5
|
+
# 1. Clones your repo (init container).
|
|
6
|
+
# 2. Runs jso-protector against the built JavaScript.
|
|
7
|
+
# 3. Uploads the protected dist + jso-report.json to an S3-compatible store.
|
|
8
|
+
#
|
|
9
|
+
# kubectl apply -f job.yaml
|
|
10
|
+
#
|
|
11
|
+
# Prereqs:
|
|
12
|
+
# - Secret `jso-credentials` with keys JSO_API_KEY / JSO_API_PASSWORD.
|
|
13
|
+
# - Secret `git-credentials` with keys username / token (for private repos).
|
|
14
|
+
# - Secret `s3-credentials` with keys AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY.
|
|
15
|
+
#
|
|
16
|
+
# Adjust REPO_URL, COMMIT_SHA, and the S3 bucket placeholders below.
|
|
17
|
+
|
|
18
|
+
apiVersion: batch/v1
|
|
19
|
+
kind: Job
|
|
20
|
+
metadata:
|
|
21
|
+
name: jso-protect
|
|
22
|
+
labels:
|
|
23
|
+
app.kubernetes.io/name: jso-protector
|
|
24
|
+
app.kubernetes.io/component: release-protection
|
|
25
|
+
spec:
|
|
26
|
+
backoffLimit: 0
|
|
27
|
+
ttlSecondsAfterFinished: 86400 # auto-cleanup 1 day after completion
|
|
28
|
+
template:
|
|
29
|
+
metadata:
|
|
30
|
+
labels:
|
|
31
|
+
app.kubernetes.io/name: jso-protector
|
|
32
|
+
spec:
|
|
33
|
+
restartPolicy: Never
|
|
34
|
+
|
|
35
|
+
initContainers:
|
|
36
|
+
- name: checkout
|
|
37
|
+
image: alpine/git:2.43.0
|
|
38
|
+
env:
|
|
39
|
+
- name: REPO_URL
|
|
40
|
+
value: "https://github.com/your-org/your-repo.git"
|
|
41
|
+
- name: COMMIT_SHA
|
|
42
|
+
value: "main"
|
|
43
|
+
command:
|
|
44
|
+
- sh
|
|
45
|
+
- -c
|
|
46
|
+
- |
|
|
47
|
+
set -eu
|
|
48
|
+
cd /workspace
|
|
49
|
+
git clone --depth 1 --branch "$COMMIT_SHA" "$REPO_URL" .
|
|
50
|
+
echo "Checked out $(git rev-parse HEAD)"
|
|
51
|
+
volumeMounts:
|
|
52
|
+
- name: workspace
|
|
53
|
+
mountPath: /workspace
|
|
54
|
+
|
|
55
|
+
containers:
|
|
56
|
+
- name: protect
|
|
57
|
+
image: node:22-alpine
|
|
58
|
+
workingDir: /workspace
|
|
59
|
+
envFrom:
|
|
60
|
+
- secretRef:
|
|
61
|
+
name: jso-credentials
|
|
62
|
+
env:
|
|
63
|
+
- name: CI
|
|
64
|
+
value: "true"
|
|
65
|
+
command:
|
|
66
|
+
- sh
|
|
67
|
+
- -c
|
|
68
|
+
- |
|
|
69
|
+
set -eu
|
|
70
|
+
# Get the actual SHA so --label is precise even when REPO_URL
|
|
71
|
+
# pointed at a branch.
|
|
72
|
+
cd /workspace
|
|
73
|
+
SHA="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
|
|
74
|
+
|
|
75
|
+
echo "==> npm ci"
|
|
76
|
+
npm ci --no-audit --no-fund
|
|
77
|
+
echo "==> npm run build"
|
|
78
|
+
npm run build
|
|
79
|
+
echo "==> jso-protector release-check"
|
|
80
|
+
npx jso-protector --config jso.config.json --release-check --json
|
|
81
|
+
echo "==> jso-protector competitor gap report"
|
|
82
|
+
npx jso-protector --config jso.config.json --competitor-gap-report --json
|
|
83
|
+
echo "==> jso-protector protect"
|
|
84
|
+
npx jso-protector \
|
|
85
|
+
--config jso.config.json \
|
|
86
|
+
--label "$SHA" \
|
|
87
|
+
--manifest dist-protected/jso-manifest.json \
|
|
88
|
+
--report dist-protected/jso-report.json
|
|
89
|
+
|
|
90
|
+
ls -la dist-protected/
|
|
91
|
+
volumeMounts:
|
|
92
|
+
- name: workspace
|
|
93
|
+
mountPath: /workspace
|
|
94
|
+
resources:
|
|
95
|
+
requests:
|
|
96
|
+
cpu: "500m"
|
|
97
|
+
memory: "512Mi"
|
|
98
|
+
limits:
|
|
99
|
+
cpu: "2000m"
|
|
100
|
+
memory: "2Gi"
|
|
101
|
+
|
|
102
|
+
# OPTIONAL: side-car that uploads dist-protected/ to S3 after the
|
|
103
|
+
# protect container exits. If you have your own artifact uploader,
|
|
104
|
+
# remove this whole container.
|
|
105
|
+
# Tip: Job containers run in parallel; use an emptyDir + a wait
|
|
106
|
+
# script if you need strict ordering. The simplest production wiring
|
|
107
|
+
# is to push from the protect container itself (combine the two).
|
|
108
|
+
|
|
109
|
+
volumes:
|
|
110
|
+
- name: workspace
|
|
111
|
+
emptyDir: {}
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
# Companion: the Secret manifest. Apply once per cluster.
|
|
115
|
+
# Replace the placeholders with base64-encoded credentials.
|
|
116
|
+
apiVersion: v1
|
|
117
|
+
kind: Secret
|
|
118
|
+
metadata:
|
|
119
|
+
name: jso-credentials
|
|
120
|
+
type: Opaque
|
|
121
|
+
stringData:
|
|
122
|
+
JSO_API_KEY: "REPLACE-WITH-BASE64-API-KEY-FROM-DASHBOARD"
|
|
123
|
+
JSO_API_PASSWORD: "REPLACE-WITH-BASE64-API-PASSWORD-FROM-DASHBOARD"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
|
|
2
|
+
const { withJsoProtectorMetro } = require("jso-protector/metro");
|
|
3
|
+
|
|
4
|
+
const baseConfig = getDefaultConfig(__dirname);
|
|
5
|
+
|
|
6
|
+
module.exports = withJsoProtectorMetro(mergeConfig(baseConfig, {}), {
|
|
7
|
+
apiKey: process.env.JSO_API_KEY,
|
|
8
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
9
|
+
preset: "balanced",
|
|
10
|
+
include: ["index.android.release.bundle.js", "index.ios.release.bundle.js"]
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const withJsoProtector = require("jso-protector/next");
|
|
2
|
+
|
|
3
|
+
module.exports = withJsoProtector({
|
|
4
|
+
reactStrictMode: true
|
|
5
|
+
}, {
|
|
6
|
+
apiKey: process.env.JSO_API_KEY,
|
|
7
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
8
|
+
preset: "balanced",
|
|
9
|
+
exclude: ["static/chunks/webpack*.js"],
|
|
10
|
+
manifest: ".next/jso-manifest.json"
|
|
11
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { planProtection, protectFiles } = require("jso-protector");
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const options = {
|
|
7
|
+
apiKey: process.env.JSO_API_KEY,
|
|
8
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
9
|
+
input: "dist",
|
|
10
|
+
output: "dist-protected",
|
|
11
|
+
preset: "balanced",
|
|
12
|
+
exclude: ["**/*.map", "**/vendor/**"],
|
|
13
|
+
assetExclude: ["**/*.map"],
|
|
14
|
+
manifest: "dist-protected/jso-manifest.json",
|
|
15
|
+
maxGrowthRatio: 8
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const plan = planProtection(options);
|
|
19
|
+
console.log(`Protecting ${plan.summary.files.length} JavaScript file(s).`);
|
|
20
|
+
|
|
21
|
+
const result = await protectFiles(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
|
+
});
|