hexo-blog-encrypt 4.0.3 → 4.1.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/ReadMe.md +252 -256
- package/ReadMe.zh.md +218 -237
- package/lib/hbe.blink.html +1 -1
- package/lib/hbe.bundle.js +1 -1
- package/lib/hbe.bundle.js.map +4 -4
- package/lib/hbe.default.html +1 -1
- package/lib/hbe.flip.html +1 -1
- package/lib/hbe.shrink.html +1 -1
- package/lib/hbe.style.css +50 -20
- package/lib/hbe.surge.html +1 -1
- package/lib/hbe.up.html +1 -1
- package/lib/hbe.wave.html +1 -1
- package/lib/hbe.xray.html +1 -1
- package/package.json +11 -9
- package/src/server/config.js +104 -4
- package/src/server/crypto.js +10 -5
- package/src/server/generator.js +18 -2
- package/src/server/index.js +12 -5
- package/src/server/template.js +2 -1
package/ReadMe.md
CHANGED
|
@@ -1,149 +1,103 @@
|
|
|
1
1
|
# hexo-blog-encrypt
|
|
2
2
|
|
|
3
|
+
> Password-protect individual Hexo posts. Content is encrypted at build time
|
|
4
|
+
> with AES-256-GCM and decrypted in the reader's browser with the Web Crypto
|
|
5
|
+
> API. No server, no plaintext in the generated HTML.
|
|
6
|
+
|
|
7
|
+
**[▶ Live demo](https://d0n9x1n.github.io/hexo-blog-encrypt/)**: every demo password is `hello`.
|
|
8
|
+
|
|
3
9
|
[](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
|
|
4
10
|
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
5
11
|
[](https://www.npmjs.com/package/hexo-blog-encrypt)
|
|
6
12
|
[](./LICENSE)
|
|
7
13
|
[](https://github.com/D0n9X1n/hexo-blog-encrypt/actions/workflows/test.yml)
|
|
14
|
+
[](./docs/DEVELOPMENT.md)
|
|
8
15
|
[](https://d0n9x1n.github.io/hexo-blog-encrypt/)
|
|
9
|
-
|
|
10
|
-
[
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| Safari (macOS / iOS) | 14+ | Manual smoke at release time |
|
|
52
|
-
|
|
53
|
-
If your site is served over plain HTTP from a non-localhost host,
|
|
54
|
-
decryption will silently fail (`crypto.subtle` is `undefined`). Always
|
|
55
|
-
use HTTPS in production.
|
|
56
|
-
|
|
57
|
-
## Why upgrade from v3?
|
|
58
|
-
|
|
59
|
-
v4 isn't a cosmetic refresh — it closes real security gaps and fixes UX
|
|
60
|
-
problems v3 had. The headline reasons:
|
|
61
|
-
|
|
62
|
-
- **Stronger crypto.** **AES-256-GCM** with a built-in authentication
|
|
63
|
-
tag replaces v3's AES-CBC + separate HMAC. One primitive, one auth
|
|
64
|
-
path, hardware-accelerated, and immune to a class of CBC
|
|
65
|
-
padding-oracle and HMAC-comparison bugs.
|
|
66
|
-
- **Per-post salt + nonce.** v3 used the same salt for every post, so
|
|
67
|
-
the same password derived the same key everywhere. v4 derives an
|
|
68
|
-
independent key per post — an attacker can't amortize one password's
|
|
69
|
-
PBKDF2 work across other posts that share the password.
|
|
70
|
-
- **Stronger KDF defaults.** v3 used **1,024** PBKDF2-SHA256 iterations
|
|
71
|
-
— far below current recommendations and easily amortized across many
|
|
72
|
-
guesses on modern hardware. v4 defaults to **250,000** (≈ 240× more
|
|
73
|
-
work per guess) and recommends 600,000+ (OWASP 2023). Tunable per
|
|
74
|
-
post via `kdf.iterations`.
|
|
75
|
-
- **Privacy by default.** v3 always cached decrypted posts in
|
|
76
|
-
`localStorage`, so anyone with subsequent device access could
|
|
77
|
-
re-read them. v4 defaults to `autoSave: false`; you opt in per post
|
|
78
|
-
or globally.
|
|
79
|
-
- **Inline error messages.** v3 fired a `window.alert()` dialog on a
|
|
80
|
-
wrong password — disruptive, especially on mobile. v4 shows the
|
|
81
|
-
error inline next to the password field (`role="alert"`).
|
|
82
|
-
- **Optional click-to-decrypt button.** Discoverable for visitors who
|
|
83
|
-
don't realise Enter submits the form. Label is configurable.
|
|
84
|
-
- **Smaller bundle.** Drops the bundled CryptoJS dependency in
|
|
85
|
-
favour of the browser's native Web Crypto API. The shipped browser
|
|
86
|
-
bundle is ≈ 6 KB minified.
|
|
87
|
-
- **Tested.** Server suite at 100 % line / branch / function coverage
|
|
88
|
-
+ Playwright e2e across all 8 themes. v3 had effectively zero
|
|
89
|
-
automated tests; v4 is regression-guarded on every push.
|
|
90
|
-
|
|
91
|
-
If you care about offline password guessing against your generated
|
|
92
|
-
HTML, or about shared-device exposure of cached keys — upgrade.
|
|
93
|
-
|
|
94
|
-
The deeper rationale per change lives on the wiki:
|
|
95
|
-
[Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
|
|
96
|
-
|
|
97
|
-
## Upgrading from v3
|
|
98
|
-
|
|
99
|
-
v4 changed the wire format (AES-GCM, per-post salt + nonce). Existing
|
|
100
|
-
encrypted output cannot be read by v4 and vice versa, so:
|
|
101
|
-
|
|
102
|
-
1. Upgrade the plugin: `npm install --save hexo-blog-encrypt@^4`.
|
|
103
|
-
2. Rebuild from source: `hexo clean && hexo generate`.
|
|
104
|
-
3. Purge your CDN if you use one (the post HTML changes byte-for-byte
|
|
105
|
-
on every build by design — fresh nonce per encryption — but the
|
|
106
|
-
runtime asset URL `lib/hbe.<hash>.js` is content-hashed and only
|
|
107
|
-
changes when the bundle changes).
|
|
108
|
-
4. Optional: drop `wrong_hash_message` from your config and front-matter
|
|
109
|
-
(deprecated in v4, removed in v5).
|
|
110
|
-
|
|
111
|
-
No source `.md` files are touched. See [CHANGELOG.md](./CHANGELOG.md)
|
|
112
|
-
for the full breaking-changes list and the new `decryptButton` /
|
|
113
|
-
`autoSave` / `kdf.iterations` options.
|
|
16
|
+
[](./package.json)
|
|
17
|
+
[](https://hexo.io/)
|
|
18
|
+
[](./package.json)
|
|
19
|
+
[](https://www.npmjs.com/package/hexo-blog-encrypt#provenance)
|
|
20
|
+
[](https://github.com/D0n9X1n/hexo-blog-encrypt/stargazers)
|
|
21
|
+
|
|
22
|
+
English · [中文说明](./ReadMe.zh.md) · [Wiki](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki) · [Releases](https://github.com/D0n9X1n/hexo-blog-encrypt/releases)
|
|
23
|
+
|
|
24
|
+
## Contents
|
|
25
|
+
|
|
26
|
+
- [Highlights](#highlights)
|
|
27
|
+
- [Live demo](#live-demo)
|
|
28
|
+
- [Install](#install)
|
|
29
|
+
- [Quick start](#quick-start)
|
|
30
|
+
- [Configuration](#configuration)
|
|
31
|
+
- [Theme integration](#theme-integration)
|
|
32
|
+
- [Browser support](#browser-support)
|
|
33
|
+
- [Why upgrade from v3?](#why-upgrade-from-v3)
|
|
34
|
+
- [Upgrading from v3](#upgrading-from-v3)
|
|
35
|
+
- [Contributing](#contributing)
|
|
36
|
+
- [License](#license)
|
|
37
|
+
|
|
38
|
+
## Highlights
|
|
39
|
+
|
|
40
|
+
| | |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| **Authenticated encryption** | [PBKDF2](https://www.rfc-editor.org/rfc/rfc8018)-SHA256 key derivation and [AES-256-GCM](https://csrc.nist.gov/pubs/sp/800/38/d/final). The GCM tag rejects wrong passwords and tampered ciphertext. |
|
|
43
|
+
| **Native crypto only** | Node.js [`crypto`](https://nodejs.org/api/crypto.html) at build time, the browser [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) at read time. No runtime dependencies. |
|
|
44
|
+
| **Per-post keys** | Each post has its own 32-byte salt and 12-byte nonce, so one cracked post does not speed up attacks on the others. |
|
|
45
|
+
| **Front-matter or tag passwords** | Set `password:` on a post, or map tags to passwords in `_config.yml`. |
|
|
46
|
+
| **Eight themes** | `default`, `blink`, `flip`, `shrink`, `surge`, `up`, `wave`, `xray`. Add your own by dropping in one HTML file. |
|
|
47
|
+
| **Scripts keep working** | Scripts inside a decrypted post run in document order. A `hexo-blog-decrypt` event fires when the post is revealed. |
|
|
48
|
+
| **Privacy by default** | Passwords and keys are not stored unless you opt in with `autoSave`. |
|
|
49
|
+
| **Tested** | 100% server line, branch and function coverage, plus Playwright end-to-end tests across every theme. |
|
|
50
|
+
|
|
51
|
+
## Live demo
|
|
52
|
+
|
|
53
|
+
Open the **[demo site](https://d0n9x1n.github.io/hexo-blog-encrypt/)**. All passwords are `hello`.
|
|
54
|
+
|
|
55
|
+
- [Theme gallery](https://d0n9x1n.github.io/hexo-blog-encrypt/tags/theme-demo/)
|
|
56
|
+
- [Decrypt callback](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/callback/)
|
|
57
|
+
- [Script loading order and cached keys](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/script-order/)
|
|
114
58
|
|
|
115
59
|
## Install
|
|
116
60
|
|
|
117
|
-
|
|
61
|
+
```bash
|
|
62
|
+
npm install --save hexo-blog-encrypt
|
|
63
|
+
```
|
|
118
64
|
|
|
119
|
-
|
|
65
|
+
Requires Node.js 18 or later and Hexo 5 or later. The package is published to
|
|
66
|
+
npm with [provenance](https://docs.npmjs.com/generating-provenance-statements)
|
|
67
|
+
and mirrored to GitHub Packages as `@d0n9x1n/hexo-blog-encrypt`.
|
|
120
68
|
|
|
121
69
|
## Quick start
|
|
122
70
|
|
|
123
|
-
|
|
71
|
+
Add a `password` to a post's front matter:
|
|
124
72
|
|
|
125
73
|
```markdown
|
|
126
|
-
|
|
127
74
|
---
|
|
128
75
|
title: Hello World
|
|
129
76
|
date: 2016-03-30 21:18:02
|
|
130
77
|
password: hello
|
|
131
78
|
---
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Then rebuild and preview:
|
|
132
82
|
|
|
83
|
+
```bash
|
|
84
|
+
hexo clean && hexo generate && hexo server
|
|
133
85
|
```
|
|
134
86
|
|
|
135
|
-
|
|
87
|
+
The post body is replaced by a password form. Index pages show the `abstract`
|
|
88
|
+
text instead of the content.
|
|
136
89
|
|
|
137
|
-
##
|
|
90
|
+
## Configuration
|
|
138
91
|
|
|
139
|
-
|
|
92
|
+
Settings are resolved in this order:
|
|
140
93
|
|
|
141
|
-
|
|
94
|
+
**post front matter > `_config.yml` `encrypt:` block > built-in defaults**
|
|
142
95
|
|
|
143
|
-
|
|
96
|
+
A front-matter `password` takes precedence over a tag password.
|
|
144
97
|
|
|
145
|
-
|
|
98
|
+
### Front matter
|
|
146
99
|
|
|
100
|
+
```markdown
|
|
147
101
|
---
|
|
148
102
|
title: Hello World
|
|
149
103
|
tags:
|
|
@@ -153,150 +107,161 @@ password: mikemessi
|
|
|
153
107
|
abstract: Here's something encrypted, password is required to continue reading.
|
|
154
108
|
message: Hey, password is required here.
|
|
155
109
|
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
156
|
-
|
|
157
|
-
# failures, so this option is now an alias of `wrong_pass_message`. Set
|
|
158
|
-
# `wrong_pass_message` instead.
|
|
159
|
-
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
110
|
+
theme: xray
|
|
160
111
|
---
|
|
161
|
-
|
|
162
112
|
```
|
|
163
113
|
|
|
164
|
-
###
|
|
165
|
-
|
|
166
|
-
#### Example
|
|
114
|
+
### Site-wide `_config.yml`
|
|
167
115
|
|
|
168
116
|
```yaml
|
|
169
|
-
# Security
|
|
170
117
|
encrypt: # hexo-blog-encrypt
|
|
171
118
|
abstract: Here's something encrypted, password is required to continue reading.
|
|
172
119
|
message: Hey, password is required here.
|
|
120
|
+
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
121
|
+
theme: default
|
|
122
|
+
silent: false
|
|
123
|
+
|
|
124
|
+
# Encrypt every post that carries one of these tags.
|
|
173
125
|
tags:
|
|
174
126
|
- {name: encryptAsDiary, password: passwordA}
|
|
175
127
|
- {name: encryptAsTips, password: passwordB}
|
|
176
|
-
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
177
|
-
# Deprecated under v4 (alias of `wrong_pass_message`). See note above.
|
|
178
|
-
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
179
128
|
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
# Themes that already include a button via `<%- decrypt_button %>`
|
|
183
|
-
# ignore this option. Default: true.
|
|
129
|
+
# Show a visible "Decrypt" button next to the password field.
|
|
130
|
+
# Default: true.
|
|
184
131
|
decryptButton:
|
|
185
132
|
show: true
|
|
186
133
|
text: Decrypt
|
|
187
134
|
|
|
188
135
|
# Cache the derived AES key in localStorage so reloads skip the password
|
|
189
|
-
# prompt.
|
|
190
|
-
#
|
|
191
|
-
# `hbe.v4.<post-permalink-hash>`.
|
|
136
|
+
# prompt. Default: false. Enable globally here or per post in front matter.
|
|
137
|
+
# Entries are stored under `hbe.v4.<page path>`.
|
|
192
138
|
autoSave: false
|
|
193
139
|
|
|
194
|
-
# Keep the PBKDF2 salt stable across clean
|
|
195
|
-
#
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
# every deploy.
|
|
140
|
+
# Keep the PBKDF2 salt stable across clean builds for the same post
|
|
141
|
+
# permalink. Default: false. Useful with autoSave on Cloudflare Pages,
|
|
142
|
+
# Vercel, Netlify, GitHub Actions, and other platforms that rebuild
|
|
143
|
+
# generated HTML from a clean environment on every deploy.
|
|
199
144
|
#
|
|
200
|
-
# Only the salt is stable. The AES-GCM nonce
|
|
145
|
+
# Only the salt is stable. The AES-GCM nonce stays random for every
|
|
201
146
|
# encryption to avoid nonce reuse. If the post permalink changes, the
|
|
202
|
-
# stable salt changes too, and existing localStorage cache
|
|
203
|
-
#
|
|
147
|
+
# stable salt changes too, and the page's existing localStorage cache is
|
|
148
|
+
# invalidated.
|
|
204
149
|
stableSalt: false
|
|
205
150
|
|
|
206
|
-
# PBKDF2 iteration count. Floor: 100_000. Recommended
|
|
207
|
-
# (OWASP 2023 for PBKDF2-SHA256).
|
|
208
|
-
#
|
|
151
|
+
# PBKDF2 iteration count. Floor: 100_000. Recommended: 600_000 or more
|
|
152
|
+
# (OWASP 2023 for PBKDF2-SHA256). Values below the recommendation log a
|
|
153
|
+
# build warning. Default: 250_000.
|
|
209
154
|
kdf:
|
|
210
155
|
iterations: 250000
|
|
211
|
-
|
|
212
156
|
```
|
|
213
157
|
|
|
214
158
|
When `autoSave` reads a cached key, it compares the cached salt with the
|
|
215
|
-
current page salt. A nonce change alone does not delete the cache up
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
159
|
+
current page salt. A nonce change alone does not delete the cache up front;
|
|
160
|
+
the browser tries the cached key with the current page nonce and ciphertext.
|
|
161
|
+
If AES-GCM authentication fails, the cache entry is cleared and the visitor is
|
|
162
|
+
asked for the password again.
|
|
163
|
+
|
|
164
|
+
**Saved keys and their exposure.** A saved key lives in `localStorage` under
|
|
165
|
+
`hbe.v4.<page path>` and unlocks that post on this device until it is removed.
|
|
166
|
+
Any script running on the same origin (your theme, analytics, comment
|
|
167
|
+
widgets, or an injected script) can read it, so enable `autoSave` only when
|
|
168
|
+
you trust every script on the site. After a post is revealed with a saved
|
|
169
|
+
key, a **Forget saved key** button above it deletes the entry. Turning
|
|
170
|
+
`autoSave` off for a post deletes that post's saved key on the next visit,
|
|
171
|
+
and leftover v3 `hexo-blog-encrypt:#…` entries are removed automatically.
|
|
172
|
+
|
|
173
|
+
### Option reference
|
|
174
|
+
|
|
175
|
+
| Option | Default | Description |
|
|
176
|
+
| --- | --- | --- |
|
|
177
|
+
| `password` | none | Encrypts the post. `""` disables encryption, including tag encryption. A matching tag entry without a password fails the build. |
|
|
178
|
+
| `password: { env: NAME }` | none | Reads the password from environment variable `NAME` at build time (front matter, `encrypt.password` or `encrypt.tags[].password`). A missing or empty variable fails the build; the value is never logged or rendered. This keeps passwords out of config files, not out of plaintext Markdown you commit publicly. |
|
|
179
|
+
| `abstract` | `Here's something encrypted…` | Excerpt shown on index and archive pages. |
|
|
180
|
+
| `message` | `Hey, password is required here.` | Label of the password field. |
|
|
181
|
+
| `wrong_pass_message` | `Oh, this is an invalid password…` | Inline error after a failed attempt. |
|
|
182
|
+
| `theme` | `default` | One of the eight bundled themes. Unknown names fall back to `default` with a warning. |
|
|
183
|
+
| `tags` | `[]` | `_config.yml` only. `{name, password}` pairs for tag encryption. |
|
|
184
|
+
| `decryptButton.show` / `.text` | `true` / `Decrypt` | Visible submit button and its label. |
|
|
185
|
+
| `autoSave` | `false` | Cache the derived key in `localStorage`. |
|
|
186
|
+
| `stableSalt` | `false` | Derive the salt from the permalink so cached keys survive clean rebuilds. |
|
|
187
|
+
| `kdf.iterations` | `250000` | PBKDF2 iterations. Must be an integer of at least 100,000. |
|
|
188
|
+
| `silent` | `false` | Suppress build-time info logs. Warnings and errors still print. |
|
|
189
|
+
| `wrong_hash_message` | `wrong_pass_message` | Deprecated alias. AES-GCM reports wrong passwords and tampering the same way. |
|
|
190
|
+
| `template` | none | Deprecated alias of `theme`. |
|
|
219
191
|
|
|
220
|
-
|
|
192
|
+
Boolean options (`autoSave`, `stableSalt`, `silent`, `decryptButton.show`) must be `true` or `false`. Quoted `"true"`/`"false"` are accepted with a warning; any other value fails the build.
|
|
221
193
|
|
|
222
|
-
|
|
194
|
+
The default `abstract`, `message`, `wrong_pass_message` and `decryptButton.text` follow the post's `lang`/`language`, else the site `language`. `zh`, `zh-CN` and `zh-Hans` use Simplified Chinese; everything else uses English. Explicit values always win.
|
|
223
195
|
|
|
224
|
-
|
|
196
|
+
### Disable tag encryption for one post
|
|
225
197
|
|
|
226
|
-
|
|
198
|
+
Set an empty password in that post's front matter:
|
|
199
|
+
|
|
200
|
+
```markdown
|
|
227
201
|
---
|
|
228
|
-
title:
|
|
229
|
-
date: 2019-12-21 11:54:07
|
|
202
|
+
title: Public post with an encrypted tag
|
|
230
203
|
tags:
|
|
231
204
|
- A Tag should be encrypted
|
|
232
205
|
password: ""
|
|
233
206
|
---
|
|
234
|
-
|
|
235
|
-
Use a "" to disable tag encryption.
|
|
236
207
|
```
|
|
237
208
|
|
|
238
|
-
|
|
209
|
+
## Theme integration
|
|
239
210
|
|
|
240
|
-
|
|
211
|
+
### After-decrypt event
|
|
241
212
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
213
|
+
The plugin dispatches `hexo-blog-decrypt` once on `window` after each post is
|
|
214
|
+
revealed. `event.detail.mode` is `manual` (password entered) or `cached`
|
|
215
|
+
(saved key), and `event.detail.element` is the revealed container (useful when
|
|
216
|
+
an index page shows several encrypted posts). Listen for it to re-run anything
|
|
217
|
+
that scans the post body:
|
|
245
218
|
|
|
219
|
+
```js
|
|
220
|
+
window.addEventListener('hexo-blog-decrypt', function (event) {
|
|
221
|
+
// Reinitialize your theme's table of contents, syntax highlighting, etc.
|
|
222
|
+
console.log('Decrypted:', event.detail.mode, event.detail.element);
|
|
223
|
+
});
|
|
246
224
|
```
|
|
247
|
-
---
|
|
248
|
-
title: Callback Test
|
|
249
|
-
date: 2019-12-21 11:54:07
|
|
250
|
-
tags:
|
|
251
|
-
- Encrypted
|
|
252
|
-
---
|
|
253
225
|
|
|
254
|
-
|
|
226
|
+
### PJAX and SPA themes
|
|
255
227
|
|
|
256
|
-
|
|
228
|
+
The bundle initializes every encrypted post on the page once. It re-scans
|
|
229
|
+
automatically on `pjax:complete`, `pjax:success`, `swup:contentReplaced` and
|
|
230
|
+
`turbo:load` (dispatched on `document`). For other routers, call the idempotent
|
|
231
|
+
initializer after swapping content:
|
|
257
232
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
</script>
|
|
233
|
+
```js
|
|
234
|
+
window.hexoBlogEncrypt.init(); // whole document
|
|
235
|
+
window.hexoBlogEncrypt.init(container); // only a subtree
|
|
262
236
|
```
|
|
263
237
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
### After Decrypt Event
|
|
238
|
+
### Scripts inside encrypted posts
|
|
267
239
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
240
|
+
Scripts in a post run after it is decrypted. Since **4.0.3**, ordinary external
|
|
241
|
+
scripts load in document order before later inline scripts run, so
|
|
242
|
+
library-dependent code such as DPlayer initializes correctly. The decrypt event
|
|
243
|
+
waits until restored external scripts load, fail, or reach a **15-second
|
|
244
|
+
per-script deadline**. A timeout does not cancel a script; it can still execute
|
|
245
|
+
later. Existing `onload` and `onerror` handlers are preserved. Explicit `async`
|
|
246
|
+
scripts still load independently, and restored `defer` scripts do not recreate a
|
|
247
|
+
document parsing phase. Inline `type="module"` scripts and asynchronous work
|
|
248
|
+
inside scripts keep native scheduling and may finish after the decrypt event.
|
|
271
249
|
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
//
|
|
275
|
-
console.log('
|
|
276
|
-
|
|
250
|
+
```markdown
|
|
251
|
+
<script>
|
|
252
|
+
// Runs after this post is decrypted.
|
|
253
|
+
console.log('Hello from an encrypted post');
|
|
254
|
+
</script>
|
|
277
255
|
```
|
|
278
256
|
|
|
279
|
-
|
|
280
|
-
following inline scripts run. This fixes library-dependent initialization such
|
|
281
|
-
as DPlayer. The decrypt event waits for restored external scripts to load, fail,
|
|
282
|
-
or reach a **15-second per-script deadline**. Existing `onload` / `onerror`
|
|
283
|
-
handlers are preserved. A timeout does not cancel a script; it can execute later.
|
|
284
|
-
Explicit `async` scripts still load independently; restored `defer` scripts do
|
|
285
|
-
not recreate a document parsing phase. Inline `type="module"` scripts and
|
|
286
|
-
asynchronous work inside scripts retain native scheduling and are not guaranteed
|
|
287
|
-
to finish before the decrypt event. Use their own readiness signals when needed.
|
|
288
|
-
|
|
289
|
-
Try the [script-loading demo](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/script-order/)
|
|
290
|
-
(password `hello`) for both manual and cached-key decryption.
|
|
257
|
+
### Table of contents
|
|
291
258
|
|
|
292
|
-
|
|
259
|
+
**Never render an encrypted post's `post.origin` into generated HTML.** It
|
|
260
|
+
holds plaintext for legacy Hexo integrations. A TOC hidden with
|
|
261
|
+
`display:none` still publishes its headings. Search, feed and sitemap
|
|
262
|
+
integrations must also exclude plaintext fields from encrypted posts.
|
|
293
263
|
|
|
294
|
-
|
|
295
|
-
plaintext retained for legacy Hexo integrations. Hiding a generated TOC with
|
|
296
|
-
`display:none` still exposes its headings. Search and feed integrations must also
|
|
297
|
-
exclude plaintext fields from encrypted posts.
|
|
298
|
-
|
|
299
|
-
Generate a server-side TOC only for unencrypted posts. For example:
|
|
264
|
+
Render a server-side TOC only for unencrypted posts:
|
|
300
265
|
|
|
301
266
|
```ejs
|
|
302
267
|
<% if (post.toc === true && !post.encrypt) { %>
|
|
@@ -305,74 +270,105 @@ Generate a server-side TOC only for unencrypted posts. For example:
|
|
|
305
270
|
<%- post.content %>
|
|
306
271
|
```
|
|
307
272
|
|
|
308
|
-
For encrypted posts,
|
|
309
|
-
`hexo-blog-decrypt`
|
|
310
|
-
rather than publishing a hidden plaintext TOC.
|
|
273
|
+
For encrypted posts, build the TOC in the browser inside the
|
|
274
|
+
`hexo-blog-decrypt` handler from the revealed `#hexo-blog-encrypt` content.
|
|
311
275
|
|
|
312
|
-
###
|
|
313
|
-
If you want to disable the logging, you can add a silent property in `_config.yml` and set it to true.
|
|
276
|
+
### Encryption themes
|
|
314
277
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
encrypt: # hexo-blog-encrypt
|
|
318
|
-
silent: true
|
|
319
|
-
```
|
|
278
|
+
Pick a theme per post with `theme:` in front matter, or for the whole site in
|
|
279
|
+
`_config.yml`. Preview each one:
|
|
320
280
|
|
|
321
|
-
|
|
281
|
+
[default](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/default/) ·
|
|
282
|
+
[blink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/blink/) ·
|
|
283
|
+
[flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/) ·
|
|
284
|
+
[shrink](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/shrink/) ·
|
|
285
|
+
[surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/) ·
|
|
286
|
+
[up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/) ·
|
|
287
|
+
[wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/) ·
|
|
288
|
+
[xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
|
|
322
289
|
|
|
323
|
-
|
|
324
|
-
Previously, we use `template` to let users modify their own themes. Turn out that it's not a simple way. So, we are introducing this feature here.
|
|
290
|
+
To add a theme, see [docs/THEMES.md](./docs/THEMES.md).
|
|
325
291
|
|
|
326
|
-
|
|
292
|
+
## Browser support
|
|
327
293
|
|
|
328
|
-
|
|
294
|
+
Decryption uses Web Crypto (`crypto.subtle`), which requires a **secure
|
|
295
|
+
context**: HTTPS or `http://localhost`.
|
|
329
296
|
|
|
330
|
-
|
|
331
|
-
---
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
theme: xray
|
|
337
|
-
password: "hello"
|
|
338
|
-
---
|
|
339
|
-
```
|
|
297
|
+
| Browser | Minimum | Tested |
|
|
298
|
+
| --- | --- | --- |
|
|
299
|
+
| Chromium / Edge | 92+ | Automated: Playwright Chromium in CI, Hexo 7 and 8 |
|
|
300
|
+
| Firefox | 90+ | Automated: Playwright Firefox in CI |
|
|
301
|
+
| Safari (macOS) | 14+ | Automated: Playwright WebKit in CI (WebKit engine, not Safari itself) |
|
|
302
|
+
| Safari (iOS) | 14+ | Manual only |
|
|
340
303
|
|
|
341
|
-
|
|
304
|
+
Minimum versions come from Web Crypto and language feature support; CI runs
|
|
305
|
+
the current Playwright builds, not these minimums.
|
|
342
306
|
|
|
343
|
-
|
|
307
|
+
On plain HTTP from a non-localhost host, `crypto.subtle` is `undefined`, so
|
|
308
|
+
decryption cannot run; the post shows an "open this page over HTTPS" message
|
|
309
|
+
instead of the wrong-password error. Always serve production sites over HTTPS.
|
|
344
310
|
|
|
345
|
-
|
|
346
|
-
# Security
|
|
347
|
-
encrypt: # hexo-blog-encrypt
|
|
348
|
-
abstract: Here's something encrypted, password is required to continue reading.
|
|
349
|
-
message: Hey, password is required here.
|
|
350
|
-
tags:
|
|
351
|
-
- {name: encryptAsDiary, password: passwordA}
|
|
352
|
-
- {name: encryptAsTips, password: passwordB}
|
|
353
|
-
theme: xray
|
|
354
|
-
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
|
|
355
|
-
# Deprecated under v4 (alias of `wrong_pass_message`); see "Advanced settings".
|
|
356
|
-
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
|
|
311
|
+
## Why upgrade from v3?
|
|
357
312
|
|
|
358
|
-
|
|
313
|
+
v4 closes real security gaps and fixes v3's UX problems:
|
|
314
|
+
|
|
315
|
+
- **Stronger crypto.** **AES-256-GCM** with a built-in authentication tag
|
|
316
|
+
replaces v3's AES-CBC plus a separate HMAC: one primitive, one
|
|
317
|
+
authentication path, and no CBC padding-oracle or HMAC-comparison bugs.
|
|
318
|
+
- **Per-post salt and nonce.** v3 used the same salt for every post, so one
|
|
319
|
+
password derived the same key everywhere. v4 derives an independent key per
|
|
320
|
+
post, so an attacker cannot reuse PBKDF2 work across posts that share a
|
|
321
|
+
password.
|
|
322
|
+
- **Stronger KDF defaults.** v3 used **1,024** PBKDF2-SHA256 iterations. v4
|
|
323
|
+
defaults to **250,000** (about 240 times more work per guess) and recommends
|
|
324
|
+
600,000 or more (OWASP 2023). Tune it per post with `kdf.iterations`.
|
|
325
|
+
- **Privacy by default.** v3 always cached decrypted posts in `localStorage`,
|
|
326
|
+
so anyone with later access to the device could read them again. v4 defaults
|
|
327
|
+
to `autoSave: false`; you opt in per post or globally.
|
|
328
|
+
- **Inline errors.** v3 showed a `window.alert()` dialog on a wrong password.
|
|
329
|
+
v4 shows the error next to the field (`role="alert"`).
|
|
330
|
+
- **Optional decrypt button** for readers who don't know Enter submits the form.
|
|
331
|
+
- **Smaller bundle.** CryptoJS is gone; the browser bundle is about 6 KB
|
|
332
|
+
minified.
|
|
333
|
+
- **Tested.** 100% server coverage plus Playwright tests across all eight
|
|
334
|
+
themes, on every push.
|
|
335
|
+
|
|
336
|
+
The rationale for each change is on the wiki:
|
|
337
|
+
[Migration v3 → v4](https://github.com/D0n9X1n/hexo-blog-encrypt/wiki/Migration-v3-to-v4).
|
|
338
|
+
|
|
339
|
+
## Upgrading from v3
|
|
340
|
+
|
|
341
|
+
v4 changed the encrypted format (AES-GCM, per-post salt and nonce). v4 cannot
|
|
342
|
+
read v3 output and v3 cannot read v4 output.
|
|
343
|
+
|
|
344
|
+
1. Upgrade the plugin: `npm install --save hexo-blog-encrypt@^4`.
|
|
345
|
+
2. Rebuild from source: `hexo clean && hexo generate`.
|
|
346
|
+
3. Purge your CDN if you use one. Post HTML changes on every build because each
|
|
347
|
+
encryption uses a fresh nonce. The runtime asset `lib/hbe.<hash>.js` is
|
|
348
|
+
content-hashed and changes only when the bundle changes.
|
|
349
|
+
4. Optional: remove `wrong_hash_message` from your config and front matter. It
|
|
350
|
+
is deprecated in v4 and will be removed in v5.
|
|
351
|
+
|
|
352
|
+
Your source `.md` files are not touched. See the
|
|
353
|
+
[v4.0.0 release notes](https://github.com/D0n9X1n/hexo-blog-encrypt/releases/tag/v4.0.0)
|
|
354
|
+
and [Releases](https://github.com/D0n9X1n/hexo-blog-encrypt/releases) for the
|
|
355
|
+
full list of breaking changes.
|
|
359
356
|
|
|
360
|
-
|
|
357
|
+
## Contributing
|
|
361
358
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
+ [flip](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/flip/)
|
|
366
|
-
+ [up](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/up/)
|
|
367
|
-
+ [surge](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/surge/)
|
|
368
|
-
+ [wave](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/wave/)
|
|
369
|
-
+ [xray](https://d0n9x1n.github.io/hexo-blog-encrypt/demo/theme/xray/)
|
|
359
|
+
Issues and pull requests are welcome. Please read
|
|
360
|
+
[CONTRIBUTING.md](./.github/CONTRIBUTING.md) and include reproduction steps,
|
|
361
|
+
logs and your configuration when reporting a bug.
|
|
370
362
|
|
|
363
|
+
- [Architecture](./docs/ARCHITECTURE.md)
|
|
364
|
+
- [Development](./docs/DEVELOPMENT.md)
|
|
365
|
+
- [Releasing](./docs/RELEASING.md)
|
|
366
|
+
- [Themes](./docs/THEMES.md)
|
|
371
367
|
|
|
372
368
|
## License
|
|
373
369
|
|
|
374
|
-
|
|
370
|
+
[MIT](./LICENSE)
|
|
375
371
|
|
|
376
372
|
## Thanks
|
|
377
373
|
|
|
378
|
-
Collaborator
|
|
374
|
+
Collaborator: [xiazeyu](https://github.com/xiazeyu)
|