domma-cms 1.44.0 → 1.45.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 +11 -0
- package/CLAUDE.md +5 -2
- package/admin/js/lib/plugins-arrange.js +1 -1
- package/docs/DommaFeatures.md +4 -2
- package/package.json +1 -1
- package/public/css/site.css +1 -1
- package/server/server.js +4 -0
- package/server/services/markdown.js +64 -41
- package/server/services/notification-sources.js +5 -2
- package/server/services/pluginEntitlement.js +46 -2
- package/server/services/pluginInstaller.js +31 -0
- package/server/services/request-log.js +3 -1
- package/server/services/storeClient.js +52 -3
- package/server/templates/page.html +2 -2
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*
|
|
30
30
|
* @module server/services/storeClient
|
|
31
31
|
*/
|
|
32
|
+
import {randomBytes} from 'node:crypto';
|
|
32
33
|
import fs from 'node:fs';
|
|
33
34
|
import path from 'node:path';
|
|
34
35
|
import {getConfig} from '../config.js';
|
|
@@ -153,6 +154,53 @@ export function pendingPurchases(now = Date.now()) {
|
|
|
153
154
|
// Talking to the store
|
|
154
155
|
// ---------------------------------------------------------------------------
|
|
155
156
|
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Proving this site is the address it buys for
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A licence is for one site address, and the store checks the asker really is
|
|
163
|
+
* that site: each checkout, claim and paid download carries a fresh proof token,
|
|
164
|
+
* and the store fetches https://<site>/.well-known/domma-store/<token> back. Only
|
|
165
|
+
* the server answering at that address knows the token, so a key bought for an
|
|
166
|
+
* address nobody controls (or copied to another site) cannot be used.
|
|
167
|
+
*/
|
|
168
|
+
const PROOF_MS = 10 * 60_000;
|
|
169
|
+
export const PROOF_FORMAT = /^[A-Za-z0-9_-]{32,64}$/;
|
|
170
|
+
const proofs = new Map();
|
|
171
|
+
|
|
172
|
+
function purgeProofs(now) {
|
|
173
|
+
for (const [token, until] of proofs) if (until <= now) proofs.delete(token);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A new proof token, live for ten minutes. */
|
|
177
|
+
export function newProof(now = Date.now()) {
|
|
178
|
+
purgeProofs(now);
|
|
179
|
+
const token = randomBytes(24).toString('base64url');
|
|
180
|
+
proofs.set(token, now + PROOF_MS);
|
|
181
|
+
return token;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Is this a proof token this site handed out, still live? */
|
|
185
|
+
export function proofLive(token, now = Date.now()) {
|
|
186
|
+
if (typeof token !== 'string' || !PROOF_FORMAT.test(token)) return false;
|
|
187
|
+
purgeProofs(now);
|
|
188
|
+
return proofs.has(token);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Test-only: forget every proof. */
|
|
192
|
+
export function _resetProofs() { proofs.clear(); }
|
|
193
|
+
|
|
194
|
+
/** GET /.well-known/domma-store/:token - the store's check that this site is the address it says. No auth. */
|
|
195
|
+
export async function storeProofRoutes(fastify) {
|
|
196
|
+
fastify.get('/.well-known/domma-store/:token', {config: {rateLimit: {max: 60, timeWindow: '1 minute'}}}, async (request, reply) => {
|
|
197
|
+
reply.header('Cache-Control', 'no-store').header('X-Robots-Tag', 'noindex');
|
|
198
|
+
const token = String(request.params?.token || '');
|
|
199
|
+
if (!storeOpen() || !proofLive(token)) return reply.code(404).type('text/plain; charset=utf-8').send('Not found');
|
|
200
|
+
return reply.type('text/plain; charset=utf-8').send(token);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
156
204
|
/** A refusal from the store, carried to the admin as its own words. */
|
|
157
205
|
export class StoreError extends Error {
|
|
158
206
|
constructor(message, status = 502, code = null) {
|
|
@@ -199,7 +247,7 @@ export function fetchStoreCatalogue(site, keys) {
|
|
|
199
247
|
*/
|
|
200
248
|
export async function startPurchase({site, slug, email, name}) {
|
|
201
249
|
const key = readState().keys[slug] || heldKeys([slug])[slug] || '';
|
|
202
|
-
const out = await call('/checkout', {site, slug, email, name, ...(key && {key})});
|
|
250
|
+
const out = await call('/checkout', {site, slug, email, name, ...(key && {key}), proof: newProof()});
|
|
203
251
|
if (typeof out.id !== 'string' || typeof out.claim !== 'string' || typeof out.checkoutUrl !== 'string' || !/^https:\/\//i.test(out.checkoutUrl)) {
|
|
204
252
|
throw new StoreError('The store gave an answer this site does not understand.', 502);
|
|
205
253
|
}
|
|
@@ -220,7 +268,7 @@ export async function startPurchase({site, slug, email, name}) {
|
|
|
220
268
|
export async function claimPurchase(id) {
|
|
221
269
|
const p = readState().pending.find((x) => x.id === id);
|
|
222
270
|
if (!p) return {status: 'unknown'};
|
|
223
|
-
const out = await call('/claim', {id: p.id, claim: p.claim});
|
|
271
|
+
const out = await call('/claim', {id: p.id, claim: p.claim, proof: newProof()});
|
|
224
272
|
if (out.status === 'paid' && typeof out.licenceKey === 'string') {
|
|
225
273
|
await changeState((s) => {
|
|
226
274
|
s.keys[p.slug] = out.licenceKey;
|
|
@@ -314,7 +362,8 @@ export async function downloadPlugin(slug) {
|
|
|
314
362
|
const base = storeUrl();
|
|
315
363
|
if (!base) throw new StoreError('The store is switched off on this site.', 503);
|
|
316
364
|
const key = heldKeys([slug])[slug] || '';
|
|
317
|
-
|
|
365
|
+
// A paid download carries a proof: the store checks this site is the address the licence is for.
|
|
366
|
+
const url = `${base.replace(/\/store$/, '')}/plugins/${encodeURIComponent(slug)}/download${key ? `?licence=${encodeURIComponent(key)}&proof=${newProof()}` : ''}`;
|
|
318
367
|
let res;
|
|
319
368
|
try {
|
|
320
369
|
res = await fetch(url, {signal: AbortSignal.timeout(60_000)});
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
|
|
26
26
|
|
|
27
27
|
<!-- Site CSS -->
|
|
28
|
-
<link rel="stylesheet" href="/public/css/site.css?v=
|
|
28
|
+
<link rel="stylesheet" href="/public/css/site.css?v=20261108-hero-outline">
|
|
29
29
|
<link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
|
|
30
30
|
<!-- Menu item hover / current-page effects. Loaded after site.css so a
|
|
31
31
|
menu's own highlight wins over the blanket link styling there. -->
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
searchable / filterable / sortable / paginate attributes) -->
|
|
184
184
|
<!-- Its range-filter arithmetic; a module that runs first and sets window.DommaCollectionRange -->
|
|
185
185
|
<script src="/public/js/collection-range.mjs?v=20261025-range-slider" type="module"></script>
|
|
186
|
-
<script src="/public/js/collection-browser.js?v=
|
|
186
|
+
<script src="/public/js/collection-browser.js?v=20261108-hero-outline" defer></script>
|
|
187
187
|
<!-- Core Forms logic engine (must run before forms.js and site.js) -->
|
|
188
188
|
<script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
|
|
189
189
|
|