@sysce/estrogen 0.0.0-stage → 0.5.4
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/LICENSE +15 -0
- package/README.md +207 -2
- package/bin/estrogen.js +38 -0
- package/dist/cjs/astro.d.ts +31 -0
- package/dist/cjs/astro.js +45 -0
- package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
- package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/cjs/cloak/astro/HolyText.astro +31 -0
- package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/cjs/cloak/astro.d.ts +2 -0
- package/dist/cjs/cloak/astro.js +10 -0
- package/dist/cjs/cloak/base64.d.ts +2 -0
- package/dist/cjs/cloak/base64.js +20 -0
- package/dist/cjs/cloak/crypto.d.ts +16 -0
- package/dist/cjs/cloak/crypto.js +40 -0
- package/dist/cjs/cloak/decrypt.d.ts +23 -0
- package/dist/cjs/cloak/decrypt.js +144 -0
- package/dist/cjs/cloak/elements.d.ts +45 -0
- package/dist/cjs/cloak/elements.js +195 -0
- package/dist/cjs/cloak/index.d.ts +10 -0
- package/dist/cjs/cloak/index.js +41 -0
- package/dist/cjs/cloak/preact.d.ts +10 -0
- package/dist/cjs/cloak/preact.js +19 -0
- package/dist/cjs/cloak/props.d.ts +18 -0
- package/dist/cjs/cloak/props.js +27 -0
- package/dist/cjs/cloak/react-extra.d.ts +327 -0
- package/dist/cjs/cloak/react-extra.js +169 -0
- package/dist/cjs/cloak/react.d.ts +28 -0
- package/dist/cjs/cloak/react.js +159 -0
- package/dist/cjs/cloak/render.d.ts +37 -0
- package/dist/cjs/cloak/render.js +54 -0
- package/dist/cjs/cloak/server.d.ts +35 -0
- package/dist/cjs/cloak/server.js +87 -0
- package/dist/cjs/cloak/server.node.d.ts +15 -0
- package/dist/cjs/cloak/server.node.js +36 -0
- package/dist/cjs/cloak/solid.d.ts +13 -0
- package/dist/cjs/cloak/solid.js +55 -0
- package/dist/cjs/cloak/span.d.ts +8 -0
- package/dist/cjs/cloak/span.js +123 -0
- package/dist/cjs/cloak/strings.d.ts +18 -0
- package/dist/cjs/cloak/strings.js +53 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte.d.ts +2 -0
- package/dist/cjs/cloak/svelte.js +10 -0
- package/dist/cjs/cloak/vue.d.ts +36 -0
- package/dist/cjs/cloak/vue.js +34 -0
- package/dist/cjs/esbuild.d.ts +33 -0
- package/dist/cjs/esbuild.js +79 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/node-require.js +7 -0
- package/dist/cjs/obfuscate.d.ts +23 -0
- package/dist/cjs/obfuscate.js +148 -0
- package/dist/cjs/options.d.ts +217 -0
- package/dist/cjs/options.js +89 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/report.d.ts +64 -0
- package/dist/cjs/report.js +55 -0
- package/dist/cjs/resolve-binary.d.ts +44 -0
- package/dist/cjs/resolve-binary.js +109 -0
- package/dist/cjs/rollup.d.ts +30 -0
- package/dist/cjs/rollup.js +57 -0
- package/dist/cjs/rsbuild.d.ts +29 -0
- package/dist/cjs/rsbuild.js +45 -0
- package/dist/cjs/vendor.d.ts +16 -0
- package/dist/cjs/vendor.js +95 -0
- package/dist/cjs/vite.d.ts +31 -0
- package/dist/cjs/vite.js +53 -0
- package/dist/esm/astro.d.ts +31 -0
- package/dist/esm/astro.js +42 -0
- package/dist/esm/cloak/astro/HolyLink.astro +36 -0
- package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/esm/cloak/astro/HolyText.astro +31 -0
- package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/esm/cloak/astro.d.ts +2 -0
- package/dist/esm/cloak/astro.js +2 -0
- package/dist/esm/cloak/base64.d.ts +2 -0
- package/dist/esm/cloak/base64.js +16 -0
- package/dist/esm/cloak/crypto.d.ts +16 -0
- package/dist/esm/cloak/crypto.js +36 -0
- package/dist/esm/cloak/decrypt.d.ts +23 -0
- package/dist/esm/cloak/decrypt.js +136 -0
- package/dist/esm/cloak/elements.d.ts +45 -0
- package/dist/esm/cloak/elements.js +189 -0
- package/dist/esm/cloak/index.d.ts +10 -0
- package/dist/esm/cloak/index.js +13 -0
- package/dist/esm/cloak/preact.d.ts +10 -0
- package/dist/esm/cloak/preact.js +15 -0
- package/dist/esm/cloak/props.d.ts +18 -0
- package/dist/esm/cloak/props.js +23 -0
- package/dist/esm/cloak/react-extra.d.ts +327 -0
- package/dist/esm/cloak/react-extra.js +161 -0
- package/dist/esm/cloak/react.d.ts +28 -0
- package/dist/esm/cloak/react.js +147 -0
- package/dist/esm/cloak/render.d.ts +37 -0
- package/dist/esm/cloak/render.js +48 -0
- package/dist/esm/cloak/server.d.ts +35 -0
- package/dist/esm/cloak/server.js +75 -0
- package/dist/esm/cloak/server.node.d.ts +15 -0
- package/dist/esm/cloak/server.node.js +22 -0
- package/dist/esm/cloak/solid.d.ts +13 -0
- package/dist/esm/cloak/solid.js +51 -0
- package/dist/esm/cloak/span.d.ts +8 -0
- package/dist/esm/cloak/span.js +117 -0
- package/dist/esm/cloak/strings.d.ts +18 -0
- package/dist/esm/cloak/strings.js +47 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
- package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte.d.ts +2 -0
- package/dist/esm/cloak/svelte.js +2 -0
- package/dist/esm/cloak/vue.d.ts +36 -0
- package/dist/esm/cloak/vue.js +31 -0
- package/dist/esm/esbuild.d.ts +33 -0
- package/dist/esm/esbuild.js +76 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/node-require.js +8 -0
- package/dist/esm/obfuscate.d.ts +23 -0
- package/dist/esm/obfuscate.js +145 -0
- package/dist/esm/options.d.ts +217 -0
- package/dist/esm/options.js +85 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/report.d.ts +64 -0
- package/dist/esm/report.js +49 -0
- package/dist/esm/resolve-binary.d.ts +44 -0
- package/dist/esm/resolve-binary.js +101 -0
- package/dist/esm/rollup.d.ts +30 -0
- package/dist/esm/rollup.js +54 -0
- package/dist/esm/rsbuild.d.ts +29 -0
- package/dist/esm/rsbuild.js +42 -0
- package/dist/esm/vendor.d.ts +16 -0
- package/dist/esm/vendor.js +92 -0
- package/dist/esm/vite.d.ts +31 -0
- package/dist/esm/vite.js +50 -0
- package/package.json +282 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Reed
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,208 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sysce/estrogen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Post-build web obfuscator. estrogen rewrites an already built output directory in
|
|
4
|
+
place: string and template literals into an encrypted per-file pool, proxy and
|
|
5
|
+
store names into per-build substitutes, and the embedded wasm names to match. It
|
|
6
|
+
leaves a build with no sensitive plaintext from the canary list and does not
|
|
7
|
+
change what the code does.
|
|
8
|
+
|
|
9
|
+
estrogen raises the cost of reading a build. It is not secrecy. A decoder key ships
|
|
10
|
+
in each file, and anyone with devtools can run the code. Do not describe the
|
|
11
|
+
output as secret.
|
|
12
|
+
|
|
13
|
+
This package is the Node launcher and integration layer. It resolves the native
|
|
14
|
+
binary for the running platform from a per-target optional dependency and runs
|
|
15
|
+
it. The obfuscation engine is a separate native binary; this package only
|
|
16
|
+
resolves and spawns it.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install --save-dev @sysce/estrogen
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
npm installs the one `@sysce/estrogen-<os>-<cpu>` package that matches your
|
|
25
|
+
platform through optional dependencies. The supported targets are
|
|
26
|
+
`linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`, and `win32-x64`.
|
|
27
|
+
|
|
28
|
+
A nightly build of `main` is published under the `nightly` dist-tag, versioned
|
|
29
|
+
like `0.5.5-nightly.202611230617.g1a2b3c4` (UTC time and commit), once a day
|
|
30
|
+
when `main` has a new commit that passed CI:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm i -D @sysce/estrogen@nightly
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## CLI
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
estrogen [options] <dir>...
|
|
40
|
+
estrogen build [options] <dir>...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`estrogen` rewrites each directory in place. `estrogen build` first copies the
|
|
44
|
+
config's `[[vendor]]` inputs into each directory, then obfuscates. The common
|
|
45
|
+
options:
|
|
46
|
+
|
|
47
|
+
| flag | meaning |
|
|
48
|
+
| ----------------------- | --------------------------------------------------------------- |
|
|
49
|
+
| `-c`, `--config <file>` | TOML config file |
|
|
50
|
+
| `--canary <file>` | canary list the output must not leak |
|
|
51
|
+
| `--names <file>` | proxy and store names to rename |
|
|
52
|
+
| `--sourcemap <dir>` | write maps here, outside the served tree, for private debugging |
|
|
53
|
+
| `--seed <hex>` | fixed seed for reproducible output (tests only) |
|
|
54
|
+
| `-j`, `--jobs <n>` | worker count |
|
|
55
|
+
| `--check` | report and run the canary check without writing |
|
|
56
|
+
| `--watch` | re-run on each change until stopped |
|
|
57
|
+
| `--quiet` | print nothing but errors |
|
|
58
|
+
| `-v`, `--verbose` | per-file detail |
|
|
59
|
+
| `-V`, `--version` | print the version |
|
|
60
|
+
| `-h`, `--help` | print help |
|
|
61
|
+
|
|
62
|
+
`estrogen --help` lists the rest: the VM switches (`--no-vm`, `--no-vm-glob`,
|
|
63
|
+
`--module-glob`, `--top-level`, `--shared-runtime`, `--no-function-source`,
|
|
64
|
+
`--no-function-source-warning`), the asset passes (`--no-minify`,
|
|
65
|
+
`--no-optimize-svg`, `--no-minify-html`, `--no-minify-css`), vendoring
|
|
66
|
+
(`--vendor-file`, `--manifest`, `--no-manifest`) and the live injector
|
|
67
|
+
(`--cloak-target`, `--cloaks`, `--cloak-shortcut`, `--cloak-mount`). The
|
|
68
|
+
repository's `docs/CLI.md` covers each one.
|
|
69
|
+
|
|
70
|
+
Exit code 0 means success. Any nonzero code means the build was not fully
|
|
71
|
+
rewritten; estrogen writes no partial output for a file it cannot handle and names
|
|
72
|
+
the file and the reason.
|
|
73
|
+
|
|
74
|
+
## Node API
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { obfuscate } from '@sysce/estrogen';
|
|
78
|
+
|
|
79
|
+
const report = await obfuscate({
|
|
80
|
+
dirs: 'dist',
|
|
81
|
+
canary: 'canary-list.json',
|
|
82
|
+
});
|
|
83
|
+
console.log(report.ok, report.durationMs);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`obfuscate(options)` spawns the binary once over one or more directories. It
|
|
87
|
+
resolves with a `Report` when estrogen exits 0 and rejects with an `EstrogenError`
|
|
88
|
+
(carrying the partial report) when it exits nonzero or fails to start.
|
|
89
|
+
|
|
90
|
+
## esbuild
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import estrogen from '@sysce/estrogen/esbuild';
|
|
94
|
+
import { build } from 'esbuild';
|
|
95
|
+
|
|
96
|
+
await build({
|
|
97
|
+
entryPoints: ['src/app.ts'],
|
|
98
|
+
bundle: true,
|
|
99
|
+
outdir: 'dist',
|
|
100
|
+
plugins: [estrogen({ canary: 'canary-list.json' })],
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The plugin runs in `onEnd`, after esbuild writes the bundle. It takes the output
|
|
105
|
+
directory from `outdir`, or from the directory of `outfile`, resolved against
|
|
106
|
+
`absWorkingDir`. It skips a build that produced errors and turns an estrogen failure
|
|
107
|
+
into an esbuild error.
|
|
108
|
+
|
|
109
|
+
## Rsbuild
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { defineConfig } from '@rsbuild/core';
|
|
113
|
+
import { pluginEstrogen } from '@sysce/estrogen/rsbuild';
|
|
114
|
+
|
|
115
|
+
export default defineConfig({
|
|
116
|
+
plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The plugin runs in `onAfterBuild`, after Rsbuild writes the output. It takes the
|
|
121
|
+
dist directory from `api.context.distPath`, the path Rsbuild resolved for the
|
|
122
|
+
build.
|
|
123
|
+
|
|
124
|
+
## Vite, Rollup and Astro
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { pluginEstrogen } from '@sysce/estrogen/vite';
|
|
128
|
+
import { defineConfig } from 'vite';
|
|
129
|
+
|
|
130
|
+
export default defineConfig({
|
|
131
|
+
plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The Vite plugin runs after `vite build` writes `build.outDir` and does nothing
|
|
136
|
+
under `vite serve`. `@sysce/estrogen/rollup` exports the same `pluginEstrogen`
|
|
137
|
+
and runs in `writeBundle` over `output.dir`. `@sysce/estrogen/astro` default
|
|
138
|
+
exports an integration that runs on `astro:build:done`.
|
|
139
|
+
|
|
140
|
+
`esbuild`, `@rsbuild/core`, `vite`, `rollup` and `astro` are optional peer
|
|
141
|
+
dependencies: install whichever one you use. The plugin options are the same as
|
|
142
|
+
`obfuscate` options without `dirs`, which each plugin fills in from the build.
|
|
143
|
+
|
|
144
|
+
## Text cloak and live injector
|
|
145
|
+
|
|
146
|
+
The opt-in text cloak uses the same `#eckey` and AES-256-CBC wire format as
|
|
147
|
+
the existing HolyText implementations. The server helpers create a fresh
|
|
148
|
+
key and IV for each response; custom elements render decrypted text inside
|
|
149
|
+
closed shadow roots. The `cloak`, `cloak/server`, `cloak/react`,
|
|
150
|
+
`cloak/preact`, `cloak/vue`, `cloak/svelte`, `cloak/solid` and `cloak/astro`
|
|
151
|
+
subpaths all belong to this package. Only the framework you use is needed.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import {
|
|
155
|
+
cloakKeyMarkup,
|
|
156
|
+
cloakText,
|
|
157
|
+
createEncryptionSession,
|
|
158
|
+
} from '@sysce/estrogen/cloak/server';
|
|
159
|
+
|
|
160
|
+
const session = createEncryptionSession();
|
|
161
|
+
const html = cloakKeyMarkup(session) + cloakText('Private title', session);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Include the returned markup in your HTML response and import
|
|
165
|
+
`@sysce/estrogen/cloak` in your browser bundle to register its custom
|
|
166
|
+
elements. The key is shipped to the browser; this is obfuscation, not secrecy.
|
|
167
|
+
|
|
168
|
+
To inject a separate built frontend that appears when Ctrl+E is pressed:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
await obfuscate({
|
|
172
|
+
dirs: 'dist',
|
|
173
|
+
injector: {
|
|
174
|
+
target: 'index.html',
|
|
175
|
+
cloaks: new URL('../cloaks', import.meta.url),
|
|
176
|
+
shortcut: 'Ctrl+E',
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The frontend is served from `_estrogen/cloaks/` in a closed-shadow iframe.
|
|
182
|
+
For partial-page overlays, set `mount: '#decoy'`. Build frontend assets with
|
|
183
|
+
a relative public base to keep CSS, modules and fonts at their copied paths.
|
|
184
|
+
The same `injector` option works through the existing build plugins. The CLI
|
|
185
|
+
accepts `--cloak-target`, repeatable `--cloaks`, `--cloak-mount` and
|
|
186
|
+
`--cloak-shortcut`. See `docs/CLOAK.md` in the repository for details.
|
|
187
|
+
|
|
188
|
+
## Binary resolution
|
|
189
|
+
|
|
190
|
+
The `estrogen` command and `obfuscate()` look up the `@sysce/estrogen-<os>-<cpu>`
|
|
191
|
+
package for the running platform and run `bin/estrogen` from it
|
|
192
|
+
(`bin/estrogen.exe` on Windows). An install with `--omit=optional` or
|
|
193
|
+
`--no-optional` leaves that package out, and both then fail with a
|
|
194
|
+
`MissingBinaryError` that names the package to install. To run a binary built
|
|
195
|
+
elsewhere, set `ESTROGEN_BINARY=/path/to/estrogen` for the command, or pass
|
|
196
|
+
`binaryPath` to `obfuscate()` or any plugin.
|
|
197
|
+
|
|
198
|
+
## Source maps
|
|
199
|
+
|
|
200
|
+
A map that traces the output back to its source is the one thing the
|
|
201
|
+
obfuscation withholds, so the default writes none and strips any
|
|
202
|
+
`sourceMappingURL` comment from each file it processes. Pass `--sourcemap <dir>`
|
|
203
|
+
(or the `sourcemap` option) to write maps outside the served tree for private
|
|
204
|
+
debugging, and keep that directory private.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
ISC. David Reed.
|
package/bin/estrogen.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// estrogen launcher. Resolves the per-platform binary from the installed
|
|
3
|
+
// @sysce/estrogen-<os>-<cpu> optional dependency and execs it, forwarding argv and
|
|
4
|
+
// the exit code. A missing binary is a clear error, not a stack trace.
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
|
|
8
|
+
import { MissingBinaryError, resolveBinaryPath } from '../dist/esm/resolve-binary.js';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
let binaryPath;
|
|
13
|
+
try {
|
|
14
|
+
// ESTROGEN_BINARY lets a local build or a test point the launcher at its own
|
|
15
|
+
// binary without installing a per-platform package.
|
|
16
|
+
binaryPath = resolveBinaryPath(require, process.env.ESTROGEN_BINARY);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof MissingBinaryError) {
|
|
19
|
+
process.stderr.write(`${error.message}\n`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
26
|
+
|
|
27
|
+
child.on('error', (error) => {
|
|
28
|
+
process.stderr.write(`estrogen failed to start: ${error.message}\n`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
child.on('close', (code, signal) => {
|
|
33
|
+
if (signal) {
|
|
34
|
+
process.kill(process.pid, signal);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
process.exit(code ?? 1);
|
|
38
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import type { PluginOptions } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Astro integration that runs estrogen over the build output directory once Astro
|
|
5
|
+
* has written it.
|
|
6
|
+
*
|
|
7
|
+
* It hooks `astro:build:done`, which runs after the build is on disk, and reads
|
|
8
|
+
* the final output directory from that hook's `dir` URL through
|
|
9
|
+
* `fileURLToPath`. For a static (SSG) build this is the directory Astro serves;
|
|
10
|
+
* for an SSR build it is the client output directory, so the integration
|
|
11
|
+
* rewrites the client assets. An estrogen failure is thrown so the build fails.
|
|
12
|
+
*
|
|
13
|
+
* estrogen rewrites that directory in place and raises the cost of reading it.
|
|
14
|
+
* It is not secrecy: a decoder key ships in each file, and anyone with devtools
|
|
15
|
+
* can run the code.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineConfig } from 'astro/config';
|
|
20
|
+
* import estrogen from '@sysce/estrogen/astro';
|
|
21
|
+
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* integrations: [estrogen({ canary: 'canary-list.json' })],
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param options estrogen options. `dirs` is ignored; the output directory comes
|
|
28
|
+
* from the Astro build hook.
|
|
29
|
+
*/
|
|
30
|
+
export declare function estrogen(options?: PluginOptions): AstroIntegration;
|
|
31
|
+
export default estrogen;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estrogen = estrogen;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
const obfuscate_js_1 = require("./obfuscate.js");
|
|
6
|
+
/**
|
|
7
|
+
* Astro integration that runs estrogen over the build output directory once Astro
|
|
8
|
+
* has written it.
|
|
9
|
+
*
|
|
10
|
+
* It hooks `astro:build:done`, which runs after the build is on disk, and reads
|
|
11
|
+
* the final output directory from that hook's `dir` URL through
|
|
12
|
+
* `fileURLToPath`. For a static (SSG) build this is the directory Astro serves;
|
|
13
|
+
* for an SSR build it is the client output directory, so the integration
|
|
14
|
+
* rewrites the client assets. An estrogen failure is thrown so the build fails.
|
|
15
|
+
*
|
|
16
|
+
* estrogen rewrites that directory in place and raises the cost of reading it.
|
|
17
|
+
* It is not secrecy: a decoder key ships in each file, and anyone with devtools
|
|
18
|
+
* can run the code.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { defineConfig } from 'astro/config';
|
|
23
|
+
* import estrogen from '@sysce/estrogen/astro';
|
|
24
|
+
*
|
|
25
|
+
* export default defineConfig({
|
|
26
|
+
* integrations: [estrogen({ canary: 'canary-list.json' })],
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param options estrogen options. `dirs` is ignored; the output directory comes
|
|
31
|
+
* from the Astro build hook.
|
|
32
|
+
*/
|
|
33
|
+
function estrogen(options = {}) {
|
|
34
|
+
return {
|
|
35
|
+
name: '@sysce/estrogen',
|
|
36
|
+
hooks: {
|
|
37
|
+
'astro:build:done': async ({ dir, logger }) => {
|
|
38
|
+
const outDir = (0, node_url_1.fileURLToPath)(dir);
|
|
39
|
+
logger.info(`running estrogen over ${outDir}`);
|
|
40
|
+
await (0, obfuscate_js_1.obfuscate)({ ...options, dirs: outDir });
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
exports.default = estrogen;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { linkElementProps, type CloakLinkProps } from '../props.js';
|
|
3
|
+
import HolyText from './HolyText.astro';
|
|
4
|
+
|
|
5
|
+
type Props = CloakLinkProps & { plain?: boolean; spanHost?: boolean; text?: string; labelCiphertext?: string; [attribute: string]: unknown };
|
|
6
|
+
const { plain: plainProp, spanHost = false, href, hrefCipher, target, text, labelCiphertext, ...rest } = Astro.props as Props;
|
|
7
|
+
const plain = plainProp ?? (Astro.locals as { isMainWebsite?: boolean }).isMainWebsite ?? false;
|
|
8
|
+
// An HTML href must not ship in the cloak branch. Match website2's
|
|
9
|
+
// request-local encryption when the link was given only a plaintext URL.
|
|
10
|
+
let encryptedHref = hrefCipher;
|
|
11
|
+
if (!plain && href !== undefined && !encryptedHref) {
|
|
12
|
+
const encryptText = (Astro.locals as { encryptText?: (text: string) => Promise<string> }).encryptText;
|
|
13
|
+
if (!encryptText) {
|
|
14
|
+
throw new Error('cloak: HolyLink needs Astro.locals.encryptText or an explicit hrefCipher');
|
|
15
|
+
}
|
|
16
|
+
encryptedHref = await encryptText(href);
|
|
17
|
+
}
|
|
18
|
+
const attributes = linkElementProps({ href, hrefCipher: encryptedHref, target });
|
|
19
|
+
---
|
|
20
|
+
{plain ? (
|
|
21
|
+
<a {...rest} href={href} target={target}>{typeof text === 'string' ? text : <slot />}</a>
|
|
22
|
+
) : spanHost ? (
|
|
23
|
+
<span {...rest} data-eclink={attributes['href-cipher']} data-target={target}>
|
|
24
|
+
{typeof text === 'string' ? <HolyText spanHost text={text} ciphertext={labelCiphertext} /> : <slot />}
|
|
25
|
+
</span>
|
|
26
|
+
) : (
|
|
27
|
+
<holy-link {...rest} href={attributes.href} href-cipher={attributes['href-cipher']} target={attributes.target}>
|
|
28
|
+
{typeof text === 'string' ? <HolyText text={text} ciphertext={labelCiphertext} /> : <slot />}
|
|
29
|
+
</holy-link>
|
|
30
|
+
)}
|
|
31
|
+
<script>
|
|
32
|
+
import '../elements.js';
|
|
33
|
+
import { navigate } from 'astro:transitions/client';
|
|
34
|
+
import { setupSpanCloak } from '../span.js';
|
|
35
|
+
setupSpanCloak(navigate);
|
|
36
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
|
2
|
+
import type { CloakLinkProps } from '../props.js';
|
|
3
|
+
|
|
4
|
+
declare const HolyLink: AstroComponentFactory &
|
|
5
|
+
((
|
|
6
|
+
props: CloakLinkProps & {
|
|
7
|
+
plain?: boolean;
|
|
8
|
+
spanHost?: boolean;
|
|
9
|
+
text?: string;
|
|
10
|
+
labelCiphertext?: string;
|
|
11
|
+
[attribute: string]: unknown;
|
|
12
|
+
},
|
|
13
|
+
) => unknown);
|
|
14
|
+
export default HolyLink;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { textElementProps, type CloakTextProps } from '../props.js';
|
|
3
|
+
|
|
4
|
+
type Props = CloakTextProps & { plain?: boolean; spanHost?: boolean; [attribute: string]: unknown };
|
|
5
|
+
const { plain: plainProp, spanHost = false, text, ciphertext, ellipsis, revealForBots, ...rest } = Astro.props as Props;
|
|
6
|
+
const plain = plainProp ?? (Astro.locals as { isMainWebsite?: boolean }).isMainWebsite ?? false;
|
|
7
|
+
// website2's HolyText encrypts its text on each SSR request. Keep that
|
|
8
|
+
// contract in the shared component, rather than emitting an unencrypted
|
|
9
|
+
// fallback when a caller supplies text but not a precomputed ciphertext.
|
|
10
|
+
let encrypted = ciphertext;
|
|
11
|
+
if (!plain && text !== undefined && !encrypted) {
|
|
12
|
+
const encryptText = (Astro.locals as { encryptText?: (text: string) => Promise<string> }).encryptText;
|
|
13
|
+
if (!encryptText) {
|
|
14
|
+
throw new Error('cloak: HolyText needs Astro.locals.encryptText or an explicit ciphertext');
|
|
15
|
+
}
|
|
16
|
+
encrypted = await encryptText(text);
|
|
17
|
+
}
|
|
18
|
+
const { attributes, placeholder } = textElementProps({ text, ciphertext: encrypted, ellipsis, revealForBots });
|
|
19
|
+
---
|
|
20
|
+
{plain ? (
|
|
21
|
+
<span {...rest} set:text={text ?? ''} />
|
|
22
|
+
) : spanHost ? (
|
|
23
|
+
<span {...rest} data-ectext={attributes.ciphertext}>{placeholder}</span>
|
|
24
|
+
) : (
|
|
25
|
+
<holy-text {...rest} ciphertext={attributes.ciphertext} ellipsis={attributes.ellipsis} reveal-for-bots={attributes['reveal-for-bots']}>{placeholder}</holy-text>
|
|
26
|
+
)}
|
|
27
|
+
<script>
|
|
28
|
+
import '../elements.js';
|
|
29
|
+
import { setupSpanCloak } from '../span.js';
|
|
30
|
+
setupSpanCloak();
|
|
31
|
+
</script>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
|
2
|
+
import type { CloakTextProps } from '../props.js';
|
|
3
|
+
|
|
4
|
+
declare const HolyText: AstroComponentFactory &
|
|
5
|
+
((
|
|
6
|
+
props: CloakTextProps & {
|
|
7
|
+
plain?: boolean;
|
|
8
|
+
spanHost?: boolean;
|
|
9
|
+
[attribute: string]: unknown;
|
|
10
|
+
},
|
|
11
|
+
) => unknown);
|
|
12
|
+
export default HolyText;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HolyLink = exports.HolyText = void 0;
|
|
7
|
+
var HolyText_astro_1 = require("./astro/HolyText.astro");
|
|
8
|
+
Object.defineProperty(exports, "HolyText", { enumerable: true, get: function () { return __importDefault(HolyText_astro_1).default; } });
|
|
9
|
+
var HolyLink_astro_1 = require("./astro/HolyLink.astro");
|
|
10
|
+
Object.defineProperty(exports, "HolyLink", { enumerable: true, get: function () { return __importDefault(HolyLink_astro_1).default; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Base64 helpers that work in a browser, on Node and on edge runtimes without
|
|
3
|
+
// Buffer. The cloak key and ciphertext move as base64 strings, so both the
|
|
4
|
+
// server (encrypt) and client (decrypt) sides share this one implementation.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toBase64 = toBase64;
|
|
7
|
+
exports.fromBase64 = fromBase64;
|
|
8
|
+
function toBase64(bytes) {
|
|
9
|
+
let binary = '';
|
|
10
|
+
for (let i = 0; i < bytes.length; i++)
|
|
11
|
+
binary += String.fromCharCode(bytes[i]);
|
|
12
|
+
return btoa(binary);
|
|
13
|
+
}
|
|
14
|
+
function fromBase64(str) {
|
|
15
|
+
const binary = atob(str.trim());
|
|
16
|
+
const bytes = new Uint8Array(binary.length);
|
|
17
|
+
for (let i = 0; i < binary.length; i++)
|
|
18
|
+
bytes[i] = binary.charCodeAt(i);
|
|
19
|
+
return bytes;
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface EncryptionSession {
|
|
2
|
+
/** 32-byte AES key. */
|
|
3
|
+
key: Uint8Array;
|
|
4
|
+
/** 16-byte IV. */
|
|
5
|
+
iv: Uint8Array;
|
|
6
|
+
/** base64(iv ++ key), the value that ships in the #eckey element. */
|
|
7
|
+
combinedKeyBase64: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Make a fresh random key+IV. Call this once per request (or per build) so the
|
|
11
|
+
* same source text encrypts to different ciphertext every time. Publish
|
|
12
|
+
* `combinedKeyBase64` into the page's #eckey element.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createEncryptionSession(randomFill?: (buffer: Uint8Array) => Uint8Array): EncryptionSession;
|
|
15
|
+
/** Encrypt one string under a session. Returns base64 AES-256-CBC ciphertext. */
|
|
16
|
+
export declare function encryptText(text: string, session: EncryptionSession): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Server/build side of the cloak: make a per-request key and encrypt text with
|
|
3
|
+
// it. AES-256-CBC via @noble/ciphers and web getRandomValues, so this runs the
|
|
4
|
+
// same on Node, on an edge runtime (Cloudflare Pages, Deno) and in a build
|
|
5
|
+
// step. The wire format matches what the client decryptor expects: a 48-byte
|
|
6
|
+
// combined key, base64(iv(16) ++ key(32)), and base64 AES-CBC ciphertext.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createEncryptionSession = createEncryptionSession;
|
|
9
|
+
exports.encryptText = encryptText;
|
|
10
|
+
const aes_js_1 = require("@noble/ciphers/aes.js");
|
|
11
|
+
const base64_js_1 = require("./base64.js");
|
|
12
|
+
function randomBytes(length, randomFill) {
|
|
13
|
+
const out = new Uint8Array(length);
|
|
14
|
+
if (randomFill)
|
|
15
|
+
return randomFill(out);
|
|
16
|
+
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
|
|
17
|
+
throw new Error('cloak: globalThis.crypto.getRandomValues is unavailable; need Node >=19, an edge runtime or a browser');
|
|
18
|
+
}
|
|
19
|
+
globalThis.crypto.getRandomValues(out);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Make a fresh random key+IV. Call this once per request (or per build) so the
|
|
24
|
+
* same source text encrypts to different ciphertext every time. Publish
|
|
25
|
+
* `combinedKeyBase64` into the page's #eckey element.
|
|
26
|
+
*/
|
|
27
|
+
function createEncryptionSession(randomFill) {
|
|
28
|
+
const key = randomBytes(32, randomFill);
|
|
29
|
+
const iv = randomBytes(16, randomFill);
|
|
30
|
+
const combined = new Uint8Array(48);
|
|
31
|
+
combined.set(iv, 0);
|
|
32
|
+
combined.set(key, 16);
|
|
33
|
+
return { key, iv, combinedKeyBase64: (0, base64_js_1.toBase64)(combined) };
|
|
34
|
+
}
|
|
35
|
+
const encoder = new TextEncoder();
|
|
36
|
+
/** Encrypt one string under a session. Returns base64 AES-256-CBC ciphertext. */
|
|
37
|
+
function encryptText(text, session) {
|
|
38
|
+
const ciphertext = (0, aes_js_1.cbc)(session.key, session.iv).encrypt(encoder.encode(text));
|
|
39
|
+
return (0, base64_js_1.toBase64)(ciphertext);
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Read the key from a host application's existing runtime, without copying globals. */
|
|
2
|
+
export declare function setCloakKeyProvider(provider: (() => string | null | undefined) | undefined): void;
|
|
3
|
+
/**
|
|
4
|
+
* Tell the decryptor where to look for the #eckey element first, e.g. a decoy
|
|
5
|
+
* overlay's shadow root. The document is always checked as a fallback.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setCloakRoot(resolver: (() => Document | ShadowRoot | null | undefined) | undefined): void;
|
|
8
|
+
/** Load the combined key from the DOM (or the window global). Safe to re-call. */
|
|
9
|
+
export declare function loadDecryptionKey(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Decrypt one base64 ciphertext string to plaintext. Returns "" on a missing
|
|
12
|
+
* key or a decrypt error, so a caller can keep its dash placeholder rather than
|
|
13
|
+
* blanking the text.
|
|
14
|
+
*/
|
|
15
|
+
export declare function holyDecrypt(ciphertextB64: string): string;
|
|
16
|
+
/** Parse a JSON payload encrypted with `encryptJson` on the server. */
|
|
17
|
+
export declare function holyDecryptJson<T = unknown>(ciphertextB64: string): T | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* A tripwire, not a security control: flags a likely headless/automated browser
|
|
20
|
+
* so the reveal step can stay on the dash placeholder. Must never block a real
|
|
21
|
+
* user, so it only reads navigator.webdriver.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isLikelyBot(): boolean;
|