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,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
createProtectionConfig,
|
|
5
|
+
getRedactedConfig,
|
|
6
|
+
planProtection,
|
|
7
|
+
protectFiles,
|
|
8
|
+
validateProtectionConfig
|
|
9
|
+
} = require("jso-protector");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @type {import("jso-protector").ProtectionOptions}
|
|
13
|
+
*/
|
|
14
|
+
const options = {
|
|
15
|
+
apiKey: process.env.JSO_API_KEY,
|
|
16
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
17
|
+
input: "dist",
|
|
18
|
+
output: "dist-protected",
|
|
19
|
+
preset: "balanced",
|
|
20
|
+
exclude: ["**/*.map", "**/vendor/**", "**/polyfills-*.js"],
|
|
21
|
+
assetExclude: ["**/*.map"],
|
|
22
|
+
reservedNames: ["^PublicApi$", "^renderWidget$"],
|
|
23
|
+
manifest: "dist-protected/jso-manifest.json",
|
|
24
|
+
maxOutputBytes: 250000,
|
|
25
|
+
maxGrowthRatio: 8
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
async function main() {
|
|
29
|
+
const validation = validateProtectionConfig(options);
|
|
30
|
+
if (!validation.ok) {
|
|
31
|
+
console.error(JSON.stringify(validation, null, 2));
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const config = createProtectionConfig(options);
|
|
37
|
+
const plan = planProtection(config);
|
|
38
|
+
const redacted = getRedactedConfig(config);
|
|
39
|
+
|
|
40
|
+
console.log(`Project: ${redacted.projectName}`);
|
|
41
|
+
console.log(`Preset: ${redacted.preset}`);
|
|
42
|
+
console.log(`Endpoint: ${redacted.endpoint}`);
|
|
43
|
+
console.log(`Protecting ${plan.files.length} JavaScript file(s).`);
|
|
44
|
+
console.log(`Copying ${plan.assets.length} release asset(s).`);
|
|
45
|
+
|
|
46
|
+
if (!plan.files.length) {
|
|
47
|
+
throw new Error("No JavaScript files matched the release plan.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const result = await protectFiles(config);
|
|
51
|
+
console.log(`Wrote ${result.written.length} protected file(s).`);
|
|
52
|
+
console.log(`Copied ${result.copied.length} asset(s).`);
|
|
53
|
+
console.log(`Manifest: ${result.manifestPath || "not written"}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
main().catch((error) => {
|
|
57
|
+
console.error(error.message);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jso-protector-parcel-example",
|
|
3
|
+
"private": true,
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "parcel build src/index.html --dist-dir dist",
|
|
6
|
+
"preflight": "node ./scripts/protect-release.js --plan",
|
|
7
|
+
"protect": "node ./scripts/protect-release.js",
|
|
8
|
+
"release": "npm run build && npm run preflight && npm run protect"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"jso-protector": "file:../.."
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const protectParcelBuild = require("jso-protector/parcel");
|
|
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 = protectParcelBuild.planParcelBuild(options);
|
|
13
|
+
|
|
14
|
+
console.log(`Protecting ${plan.summary.files.length} Parcel JavaScript file(s).`);
|
|
15
|
+
|
|
16
|
+
if (planOnly) {
|
|
17
|
+
console.log(`Copying ${plan.summary.assets.length} Parcel asset(s).`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const result = await protectParcelBuild(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,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "jso-payment-script-inventory",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"sourceFree": true,
|
|
5
|
+
"generatedUtc": "2026-06-06T12:00:00Z",
|
|
6
|
+
"scripts": [
|
|
7
|
+
{
|
|
8
|
+
"source": "https://js.stripe.com/v3/",
|
|
9
|
+
"authorized": true,
|
|
10
|
+
"justification": "Payment tokenization provider used by checkout.",
|
|
11
|
+
"owner": "Payments",
|
|
12
|
+
"category": "payment-provider",
|
|
13
|
+
"integrity": "provider-managed",
|
|
14
|
+
"lastReviewedUtc": "2026-06-01T00:00:00Z",
|
|
15
|
+
"checkoutSurface": "hosted-checkout",
|
|
16
|
+
"frameContext": "psp-iframe",
|
|
17
|
+
"frameOwner": "Payments",
|
|
18
|
+
"parentPageHref": "https://shop.example/checkout",
|
|
19
|
+
"frameHref": "https://checkout.stripe.example/frame",
|
|
20
|
+
"frameOrigin": "https://checkout.stripe.example",
|
|
21
|
+
"risk": "medium",
|
|
22
|
+
"dataAccess": "payment-tokenization",
|
|
23
|
+
"approvalTicket": "CHG-1001"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"source": "/assets/checkout.js",
|
|
27
|
+
"authorized": true,
|
|
28
|
+
"justification": "First-party checkout orchestration protected by JSO.",
|
|
29
|
+
"owner": "Payments",
|
|
30
|
+
"category": "first-party",
|
|
31
|
+
"integrity": "manifest-sha256",
|
|
32
|
+
"lastReviewedUtc": "2026-06-01T00:00:00Z",
|
|
33
|
+
"checkoutSurface": "parent-checkout",
|
|
34
|
+
"frameContext": "parent-page",
|
|
35
|
+
"frameOwner": "Web Platform",
|
|
36
|
+
"parentPageHref": "https://shop.example/checkout",
|
|
37
|
+
"frameHref": "",
|
|
38
|
+
"frameOrigin": "",
|
|
39
|
+
"risk": "low",
|
|
40
|
+
"dataAccess": "checkout-state",
|
|
41
|
+
"approvalTicket": "CHG-1002"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"source": "inline:sha256-ZXhhbXBsZS1oYXNo",
|
|
45
|
+
"authorized": true,
|
|
46
|
+
"justification": "Inline bootstrap approved for checkout template.",
|
|
47
|
+
"owner": "Web Platform",
|
|
48
|
+
"category": "inline-bootstrap",
|
|
49
|
+
"integrity": "sha256-ZXhhbXBsZS1oYXNo",
|
|
50
|
+
"lastReviewedUtc": "2026-06-01T00:00:00Z",
|
|
51
|
+
"checkoutSurface": "parent-checkout",
|
|
52
|
+
"frameContext": "parent-page",
|
|
53
|
+
"frameOwner": "Web Platform",
|
|
54
|
+
"parentPageHref": "https://shop.example/checkout",
|
|
55
|
+
"frameHref": "",
|
|
56
|
+
"frameOrigin": "",
|
|
57
|
+
"risk": "low",
|
|
58
|
+
"dataAccess": "page-bootstrap",
|
|
59
|
+
"approvalTicket": "CHG-1003"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": "jso-payment-page-security-headers",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"sourceFree": true,
|
|
5
|
+
"generatedUtc": "2026-06-08T00:00:00Z",
|
|
6
|
+
"pages": [
|
|
7
|
+
{
|
|
8
|
+
"pageUrl": "https://shop.example/checkout",
|
|
9
|
+
"statusCode": 200,
|
|
10
|
+
"observedUtc": "2026-06-08T00:00:00Z",
|
|
11
|
+
"checkoutSurface": "parent-checkout",
|
|
12
|
+
"frameContext": "parent-page",
|
|
13
|
+
"frameOwner": "Web Platform",
|
|
14
|
+
"headers": {
|
|
15
|
+
"content-security-policy": "default-src 'self'; script-src 'self' https://js.stripe.com; frame-src https://js.stripe.com; connect-src 'self' https://api.example.test; report-uri https://csp.example.test/report",
|
|
16
|
+
"strict-transport-security": "max-age=31536000; includeSubDomains",
|
|
17
|
+
"x-frame-options": "DENY",
|
|
18
|
+
"referrer-policy": "strict-origin-when-cross-origin",
|
|
19
|
+
"permissions-policy": "payment=(self)"
|
|
20
|
+
},
|
|
21
|
+
"headerSha256": "replace-with-sha256-over-canonical-header-snapshot",
|
|
22
|
+
"baselineSha256": "replace-with-approved-baseline-sha256",
|
|
23
|
+
"matchesBaseline": "match",
|
|
24
|
+
"monitor": "checkout-header-smoke",
|
|
25
|
+
"alertRoute": "security-response"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"pageUrl": "https://shop.example/checkout/embedded-card-frame",
|
|
29
|
+
"statusCode": 200,
|
|
30
|
+
"observedUtc": "2026-06-08T00:00:10Z",
|
|
31
|
+
"checkoutSurface": "psp-iframe",
|
|
32
|
+
"frameContext": "psp-iframe",
|
|
33
|
+
"frameOwner": "Payments",
|
|
34
|
+
"headers": {
|
|
35
|
+
"content-security-policy": "default-src 'none'; script-src https://js.stripe.com; report-to csp-endpoint",
|
|
36
|
+
"content-security-policy-report-only": "default-src 'none'; report-to csp-endpoint",
|
|
37
|
+
"reporting-endpoints": "csp-endpoint=\"https://csp.example.test/report\""
|
|
38
|
+
},
|
|
39
|
+
"headerSha256": "replace-with-sha256-over-canonical-header-snapshot",
|
|
40
|
+
"baselineSha256": "replace-with-approved-baseline-sha256",
|
|
41
|
+
"matchesBaseline": "match",
|
|
42
|
+
"monitor": "checkout-header-smoke",
|
|
43
|
+
"alertRoute": "security-response"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Example `.pre-commit-config.yaml` for jso-protector consumers.
|
|
2
|
+
#
|
|
3
|
+
# Drop this at the root of your repo and run:
|
|
4
|
+
# pre-commit install
|
|
5
|
+
#
|
|
6
|
+
# After that every `git commit` runs jso-protector --release-check against
|
|
7
|
+
# the staged JS. The check catches config drift (missing required option,
|
|
8
|
+
# bad path, expired credential) before it lands in CI.
|
|
9
|
+
#
|
|
10
|
+
# It deliberately does NOT POST source to the JSO API on every commit.
|
|
11
|
+
# Pre-commit is the wrong place for that; full protection belongs in CI.
|
|
12
|
+
|
|
13
|
+
repos:
|
|
14
|
+
- repo: https://www.javascriptobfuscator.com/jso-protector-pre-commit
|
|
15
|
+
rev: "v0.2.0" # Pin to a jso-protector release tag.
|
|
16
|
+
hooks:
|
|
17
|
+
- id: jso-release-check
|
|
18
|
+
# Recommended for any repo that touches the JSO API — catches
|
|
19
|
+
# accidentally-committed API tokens before they enter history:
|
|
20
|
+
- id: jso-credential-leak
|
|
21
|
+
# Uncomment for an additional dry-run on every push:
|
|
22
|
+
# - id: jso-dry-run
|
|
23
|
+
|
|
24
|
+
# Companion: catch ".jso.config.json contains JSO_API_KEY=..." style mistakes
|
|
25
|
+
# before they reach git. Reuses upstream check-added-large-files / detect-private-key.
|
|
26
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
27
|
+
rev: v4.6.0
|
|
28
|
+
hooks:
|
|
29
|
+
- id: detect-private-key
|
|
30
|
+
- id: check-yaml
|
|
31
|
+
- id: check-json
|
|
32
|
+
- id: end-of-file-fixer
|
|
33
|
+
- id: trailing-whitespace
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Pre-commit hook example for jso-protector
|
|
2
|
+
|
|
3
|
+
[`pre-commit`](https://pre-commit.com/) is a popular framework for managing git hooks. This example wires `jso-protector --release-check` and `--dry-run` into your local commit cycle so misconfiguration is caught at the developer's machine instead of in CI.
|
|
4
|
+
|
|
5
|
+
## Why this is a release-check, not a full protect
|
|
6
|
+
|
|
7
|
+
A pre-commit hook runs on every `git commit` — potentially dozens of times a day per developer. POSTing source to the JSO API on every commit would:
|
|
8
|
+
|
|
9
|
+
- Burn quota fast (Corporate plan has request limits)
|
|
10
|
+
- Send your in-flight, sometimes-broken-mid-refactor code to the hosted API
|
|
11
|
+
- Make commits slow (the full protection round-trip is seconds, not milliseconds)
|
|
12
|
+
|
|
13
|
+
The release-check and dry-run modes were built for exactly this use case. They validate configuration, file enumeration, and credentials without sending source. The actual protection happens later — in CI, when the release artifact is built.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 1. Install pre-commit if you haven't already.
|
|
19
|
+
pip install pre-commit
|
|
20
|
+
|
|
21
|
+
# 2. Make sure jso-protector is installed as a dev dependency.
|
|
22
|
+
npm install --save-dev jso-protector
|
|
23
|
+
|
|
24
|
+
# 3. Copy `.pre-commit-config.yaml` from this folder to your repo root,
|
|
25
|
+
# then activate the hooks.
|
|
26
|
+
pre-commit install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
After that every `git commit` runs the JSO checks against staged JavaScript.
|
|
30
|
+
|
|
31
|
+
## What the hooks check
|
|
32
|
+
|
|
33
|
+
| Hook | Stage | Catches |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `jso-release-check` | pre-commit | Config drift: missing required option, broken path, malformed JSON, credential not configured. |
|
|
36
|
+
| `jso-dry-run` | pre-commit, pre-push | File enumeration: catches "I added a new vendor file nobody intended to protect" mistakes. |
|
|
37
|
+
|
|
38
|
+
## CI parity
|
|
39
|
+
|
|
40
|
+
The CI templates in `node_modules/jso-protector/ci/` all run `--release-check` BEFORE the full protect. The pre-commit hooks call the same check, so a commit that passes locally is overwhelmingly likely to pass the CI gate.
|
|
41
|
+
|
|
42
|
+
## See also
|
|
43
|
+
|
|
44
|
+
- [npm CLI workflow](https://www.javascriptobfuscator.com/Docs/NpmCli.aspx)
|
|
45
|
+
- [Build integrations hub](https://www.javascriptobfuscator.com/build-integrations.aspx)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# React Native + JSO playbook (2026 refresh)
|
|
2
|
+
|
|
3
|
+
A walkthrough for layering jso-protector on top of a React Native build,
|
|
4
|
+
plus the device-attestation moves you should make in parallel. Targets
|
|
5
|
+
React Native 0.74+ with the new architecture and Hermes enabled.
|
|
6
|
+
|
|
7
|
+
## Why this is two problems
|
|
8
|
+
|
|
9
|
+
You're defending TWO surfaces simultaneously:
|
|
10
|
+
|
|
11
|
+
1. **The JS bundle** that Metro emits and Hermes byte-codes. JSO
|
|
12
|
+
obfuscates this before Hermes ever sees it.
|
|
13
|
+
2. **The native shell** (the .ipa / .aab) that hosts the JS engine.
|
|
14
|
+
Even perfect JS obfuscation doesn't help if the device itself is
|
|
15
|
+
rooted / on an emulator / running on Frida. That's where device
|
|
16
|
+
attestation (Play Integrity on Android, App Attest + DeviceCheck
|
|
17
|
+
on iOS) comes in.
|
|
18
|
+
|
|
19
|
+
JSO covers (1) end-to-end. You wire (2) yourself; this doc tells you
|
|
20
|
+
what's current as of June 2026.
|
|
21
|
+
|
|
22
|
+
## The pipeline
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
src/*.{js,ts,jsx,tsx}
|
|
26
|
+
| Metro + jso-protector/metro.js serializer
|
|
27
|
+
v
|
|
28
|
+
.build/bundle.js <-- obfuscated, watermarked,
|
|
29
|
+
| release-signed
|
|
30
|
+
| Hermes compiler (release builds)
|
|
31
|
+
v
|
|
32
|
+
.build/bundle.hbc <-- Hermes bytecode shipped to device
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Three layers stacked: source obfuscation -> Hermes bytecode -> native
|
|
36
|
+
container -> device attestation.
|
|
37
|
+
|
|
38
|
+
## Step 1 - JSO via the Metro serializer
|
|
39
|
+
|
|
40
|
+
`jso-protector/metro.js` plugs into Metro's `serializer.customSerializer`.
|
|
41
|
+
The serializer intercepts the bundle on its way to Hermes, sends it to
|
|
42
|
+
the JSO HTTP API, and replaces the bundle's `code` with the protected
|
|
43
|
+
output before Hermes byte-codes it.
|
|
44
|
+
|
|
45
|
+
`metro.config.js`:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const { mergeConfig, getDefaultConfig } = require("@react-native/metro-config");
|
|
49
|
+
const { createMetroSerializer } = require("jso-protector/metro");
|
|
50
|
+
|
|
51
|
+
const defaultConfig = getDefaultConfig(__dirname);
|
|
52
|
+
module.exports = mergeConfig(defaultConfig, {
|
|
53
|
+
serializer: {
|
|
54
|
+
customSerializer: createMetroSerializer({
|
|
55
|
+
apiKey: process.env.JSO_API_KEY,
|
|
56
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
57
|
+
preset: "maximum",
|
|
58
|
+
watermark: `${process.env.npm_package_name}@${process.env.npm_package_version}`,
|
|
59
|
+
watermarkKey: process.env.JSO_WATERMARK_KEY,
|
|
60
|
+
// Named sets work here too -- escalate checkout / wallet bundles:
|
|
61
|
+
namedSets: {
|
|
62
|
+
wallet: { match: ["src/wallet/**", "src/checkout/**"], preset: "maximum",
|
|
63
|
+
countermeasures: { onTamper: ["break", "deleteCookies"] } },
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Validate locally with `npx jso ai compat-scan` BEFORE shipping. The
|
|
71
|
+
compat scanner flags obfuscation pitfalls (eval, Function constructor,
|
|
72
|
+
hot-loaded modules) the bundle is using.
|
|
73
|
+
|
|
74
|
+
## Step 2 - Hermes bytecode
|
|
75
|
+
|
|
76
|
+
Hermes is on by default in modern React Native. The bytecode `.hbc`
|
|
77
|
+
file is what ships to the device; the JS source never does. No JSO
|
|
78
|
+
config needed for this layer - just don't disable Hermes.
|
|
79
|
+
|
|
80
|
+
Verify after a release build:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
unzip -l app-release.aab | grep '\.hbc$' # should NOT see .js
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If you see `.js` files in the AAB, Hermes is disabled. Re-enable it
|
|
87
|
+
in `android/app/build.gradle`:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
hermesEnabled = true
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Step 3 - Device attestation (REPLACE SafetyNet)
|
|
94
|
+
|
|
95
|
+
**Read this section even if you've shipped before.** SafetyNet
|
|
96
|
+
Attestation was deprecated on **June 30, 2024** and the API was
|
|
97
|
+
permanently shut down. Any blog post older than that is referencing
|
|
98
|
+
a dead API.
|
|
99
|
+
|
|
100
|
+
### Android: Play Integrity API
|
|
101
|
+
|
|
102
|
+
You want **Play Integrity API** (com.google.android.play.integrity).
|
|
103
|
+
The token tells you three things:
|
|
104
|
+
|
|
105
|
+
| Field | Tells you |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `deviceIntegrity` | Whether the device passes Google's basic / standard / strong integrity bars (no root, no Frida, no emulator) |
|
|
108
|
+
| `appIntegrity` | Whether the running APK is the same one Google distributed (catches sideloads + repackages) |
|
|
109
|
+
| `accountDetails` | Whether the device's Play account is licensed for your app |
|
|
110
|
+
|
|
111
|
+
Wiring (native module on Android side):
|
|
112
|
+
|
|
113
|
+
```kotlin
|
|
114
|
+
val standardIntegrityManager =
|
|
115
|
+
IntegrityManagerFactory.createStandard(applicationContext)
|
|
116
|
+
val tokenProvider = standardIntegrityManager.prepareIntegrityToken(
|
|
117
|
+
PrepareIntegrityTokenRequest.builder()
|
|
118
|
+
.setCloudProjectNumber(YOUR_CLOUD_PROJECT_NUMBER)
|
|
119
|
+
.build()
|
|
120
|
+
).await()
|
|
121
|
+
|
|
122
|
+
val integrityToken = tokenProvider.request(
|
|
123
|
+
StandardIntegrityTokenRequest.builder()
|
|
124
|
+
.setRequestHash(payloadHash)
|
|
125
|
+
.build()
|
|
126
|
+
).await().token()
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Send `integrityToken` to your server. Validate it via Google's
|
|
130
|
+
`playintegrity.googleapis.com/v1/.../decodeIntegrityToken`. Reject the
|
|
131
|
+
session if `deviceIntegrity.deviceRecognitionVerdict` is empty or
|
|
132
|
+
`appIntegrity.appRecognitionVerdict != PLAY_RECOGNIZED`.
|
|
133
|
+
|
|
134
|
+
### iOS: App Attest + DeviceCheck
|
|
135
|
+
|
|
136
|
+
`DCAppAttestService` is now the iOS equivalent. Per-install you do:
|
|
137
|
+
|
|
138
|
+
```swift
|
|
139
|
+
let service = DCAppAttestService.shared
|
|
140
|
+
guard service.isSupported else { return }
|
|
141
|
+
service.generateKey { keyId, error in
|
|
142
|
+
service.attestKey(keyId!, clientDataHash: payloadHash) { attestation, error in
|
|
143
|
+
// POST { keyId, attestation, deviceIdentifier } to your backend
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The server forwards the attestation to Apple's
|
|
149
|
+
`https://data.appattest.apple.com/v1/attestationData` (production) or
|
|
150
|
+
`development` host (for sandbox). The response confirms the request
|
|
151
|
+
came from a real, un-jailbroken iOS device running your app.
|
|
152
|
+
|
|
153
|
+
`DeviceCheck` (the older `DCDevice` API) is still supported for
|
|
154
|
+
non-attestation use cases (one-bit-per-device state). Use it as a
|
|
155
|
+
secondary signal, not the primary defense.
|
|
156
|
+
|
|
157
|
+
### What attestation does NOT cover
|
|
158
|
+
|
|
159
|
+
- It can't prove the user isn't running a clean device with a tampered
|
|
160
|
+
JS bundle - that's what JSO + Hermes + signed release manifests
|
|
161
|
+
cover. Layer both.
|
|
162
|
+
- Token validation must run server-side. A client that says
|
|
163
|
+
"I'm trustworthy" is not.
|
|
164
|
+
|
|
165
|
+
## Step 4 - Release attestation
|
|
166
|
+
|
|
167
|
+
`jso-protector --sign-release` writes an Ed25519-signed manifest of
|
|
168
|
+
the protected bundle alongside the .hbc. Ship it with the app (in
|
|
169
|
+
`assets/`) so an in-app verifier can confirm the bundle hasn't been
|
|
170
|
+
swapped post-deploy:
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
jso-protector --sign-release release-key.pem \
|
|
174
|
+
--manifest .build/bundle.manifest.json \
|
|
175
|
+
--label "rn-${npm_package_version}"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Pair with a periodic in-app re-check that posts to your beacon URL.
|
|
179
|
+
The jso-beacon-slack adapters forward beacons to Splunk / Elastic /
|
|
180
|
+
generic-webhook SIEM downstream.
|
|
181
|
+
|
|
182
|
+
## Field-tested gotchas
|
|
183
|
+
|
|
184
|
+
- **Reanimated worklets**: they evaluate via `Function()`-equivalents
|
|
185
|
+
on the UI thread. Mark them with the `// jso:protect-disable` comment
|
|
186
|
+
or list them in `exclude:` so JSO leaves them alone.
|
|
187
|
+
- **Native-module bridge**: function names that JS uses to call
|
|
188
|
+
native modules must NOT be mangled. Add them to `VariableExclusion`.
|
|
189
|
+
Examples: `NativeModules.WalletKit.*`, all of `NativeRouter`.
|
|
190
|
+
- **Hot-reload in development**: don't run JSO in dev. Gate the
|
|
191
|
+
Metro serializer on `process.env.NODE_ENV === "production"`.
|
|
192
|
+
- **Source maps for symbolication**: keep them - just don't ship
|
|
193
|
+
them. Upload to your symbolication endpoint (Sentry / Bugsnag /
|
|
194
|
+
Rollbar) as part of the release step.
|
|
195
|
+
|
|
196
|
+
## What's still on the roadmap
|
|
197
|
+
|
|
198
|
+
- A first-party `@react-native-jso/integrity` JS module that wraps
|
|
199
|
+
Play Integrity + DCAppAttest with one promise-based API. Until
|
|
200
|
+
it ships you need to write the native bindings yourself (snippets
|
|
201
|
+
above). Tracking: jso-protector-electron ROADMAP.
|
|
202
|
+
|
|
203
|
+
## Refs
|
|
204
|
+
|
|
205
|
+
- Google Play Integrity API: https://developer.android.com/google/play/integrity
|
|
206
|
+
- Apple DCAppAttestService: https://developer.apple.com/documentation/devicecheck/establishing-your-app-s-integrity
|
|
207
|
+
- Hermes bytecode: https://reactnative.dev/docs/hermes
|
|
208
|
+
- jso-protector Metro adapter: ./metro.config.js
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
|
|
2
|
+
const { withJsoProtectorMetro } = require("jso-protector/react-native");
|
|
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,20 @@
|
|
|
1
|
+
const jsoProtector = require("jso-protector/rollup");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
input: "src/app.js",
|
|
5
|
+
output: {
|
|
6
|
+
dir: "dist",
|
|
7
|
+
format: "iife",
|
|
8
|
+
sourcemap: true
|
|
9
|
+
},
|
|
10
|
+
plugins: [
|
|
11
|
+
jsoProtector({
|
|
12
|
+
apiKey: process.env.JSO_API_KEY,
|
|
13
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
14
|
+
preset: "balanced",
|
|
15
|
+
include: ["app.js"],
|
|
16
|
+
manifest: "dist/jso-manifest.json",
|
|
17
|
+
reservedNames: ["^PublicApi$"]
|
|
18
|
+
})
|
|
19
|
+
]
|
|
20
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const JsoProtectorRspackPlugin = require("jso-protector/rspack");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
plugins: [
|
|
5
|
+
new JsoProtectorRspackPlugin({
|
|
6
|
+
apiKey: process.env.JSO_API_KEY,
|
|
7
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
8
|
+
preset: "balanced",
|
|
9
|
+
exclude: ["vendor.js"],
|
|
10
|
+
manifest: "dist/jso-manifest.json"
|
|
11
|
+
})
|
|
12
|
+
],
|
|
13
|
+
module: {
|
|
14
|
+
rules: [{
|
|
15
|
+
test: /\.js$/,
|
|
16
|
+
include: /src/,
|
|
17
|
+
use: [{
|
|
18
|
+
loader: "jso-protector/rspack-loader",
|
|
19
|
+
options: {
|
|
20
|
+
apiKey: process.env.JSO_API_KEY,
|
|
21
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
22
|
+
include: ["src/*.js"],
|
|
23
|
+
reservedNames: ["^PublicApi$"]
|
|
24
|
+
}
|
|
25
|
+
}]
|
|
26
|
+
}]
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jso-protector-turbopack-example",
|
|
3
|
+
"private": true,
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "next build --turbopack",
|
|
6
|
+
"preflight": "node ./scripts/protect-release.js --plan",
|
|
7
|
+
"protect": "node ./scripts/protect-release.js",
|
|
8
|
+
"release": "npm run build && npm run preflight && npm run protect"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"jso-protector": "file:../.."
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const protectTurbopackBuild = require("jso-protector/turbopack");
|
|
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 = protectTurbopackBuild.planTurbopackBuild(options);
|
|
13
|
+
|
|
14
|
+
console.log(`Protecting ${plan.summary.files.length} Turbopack chunk(s).`);
|
|
15
|
+
|
|
16
|
+
if (planOnly) {
|
|
17
|
+
console.log(`Copying ${plan.summary.assets.length} Turbopack asset(s).`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const result = await protectTurbopackBuild(options);
|
|
22
|
+
console.log(`Wrote ${result.written.length} protected chunk(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,18 @@
|
|
|
1
|
+
const jsoProtector = require("jso-protector/vite");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
build: {
|
|
5
|
+
outDir: "dist",
|
|
6
|
+
sourcemap: true
|
|
7
|
+
},
|
|
8
|
+
plugins: [
|
|
9
|
+
jsoProtector({
|
|
10
|
+
apiKey: process.env.JSO_API_KEY,
|
|
11
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
12
|
+
preset: "balanced",
|
|
13
|
+
exclude: ["**/vendor/**", "**/polyfills-*.js"],
|
|
14
|
+
manifest: "dist/jso-manifest.json",
|
|
15
|
+
reservedNames: ["^PublicApi$"]
|
|
16
|
+
})
|
|
17
|
+
]
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const JsoProtectorWebpackPlugin = require("jso-protector/webpack");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
mode: "production",
|
|
5
|
+
entry: "./src/app.js",
|
|
6
|
+
output: {
|
|
7
|
+
filename: "app.js",
|
|
8
|
+
path: require("path").resolve(__dirname, "dist")
|
|
9
|
+
},
|
|
10
|
+
devtool: "source-map",
|
|
11
|
+
plugins: [
|
|
12
|
+
new JsoProtectorWebpackPlugin({
|
|
13
|
+
apiKey: process.env.JSO_API_KEY,
|
|
14
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
15
|
+
preset: "balanced",
|
|
16
|
+
exclude: ["vendor.js"],
|
|
17
|
+
manifest: "dist/jso-manifest.json",
|
|
18
|
+
reservedNames: ["^PublicApi$"]
|
|
19
|
+
})
|
|
20
|
+
]
|
|
21
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
mode: "production",
|
|
5
|
+
module: {
|
|
6
|
+
rules: [{
|
|
7
|
+
test: /\.js$/,
|
|
8
|
+
include: /src/,
|
|
9
|
+
use: [{
|
|
10
|
+
loader: "jso-protector/webpack-loader",
|
|
11
|
+
options: {
|
|
12
|
+
apiKey: process.env.JSO_API_KEY,
|
|
13
|
+
apiPassword: process.env.JSO_API_PASSWORD,
|
|
14
|
+
preset: "balanced",
|
|
15
|
+
include: ["src/*.js"],
|
|
16
|
+
reservedNames: ["^PublicApi$"],
|
|
17
|
+
maxGrowthRatio: 8
|
|
18
|
+
}
|
|
19
|
+
}]
|
|
20
|
+
}]
|
|
21
|
+
}
|
|
22
|
+
};
|