domma-cms 1.41.0 → 1.42.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.42.0] - 2026-11-06
4
+
5
+ - **A Manager's SEO redirects no longer reach the sites it hosts.** SEO's redirect rules and the WordPress importer's `/?p=` redirects run before the Manager's site proxy, so a rule made on the Manager answered every hosted site's address too (a `/tools` rule looped domma-cms.com/tools). Plugins can now claim the hosts they hand on (`hooks.claimHosts`), and those redirects step aside for them. See `server/services/hostClaims.js`.
6
+
3
7
  ## [1.41.0] - 2026-11-06
4
8
 
5
9
  - Add Domma JS Admin Atelier light and dark palettes to admin theme pickers.
package/CLAUDE.md CHANGED
@@ -214,6 +214,12 @@ plugin; the code editor is read only). Nothing may write server.json from the ad
214
214
  admin put code or a file into plugins/ or server/ must call `assertMayChangeCode()`. `.env` loads through `server/env.js`
215
215
  (`dotenv.config({override: false})`, never `dotenv/config`, which reads `DOTENV_CONFIG_OVERRIDE` from the environment).
216
216
 
217
+ **A Manager's own redirects stay off the sites it proxies - `server/services/hostClaims.js`.** Core onRequest hooks added
218
+ before `registerPlugins()` see every hosted site's request before site-manager's proxy hook. site-manager claims every
219
+ non-manager host (`hooks.claimHosts`), and SEO's redirect hook and the WordPress importer's `/?p=` hook return early on
220
+ `answeredElsewhere(request)`. A new core onRequest hook that REPLIES and is added before the plugins must do the same
221
+ (or be added after them, like `adminAssets.serve()`).
222
+
217
223
  **File stores take plain names only - `server/services/safePath.js` `fileIn(dir, name, ext)`.** Fastify decodes
218
224
  route params, so `/api/forms/..%2F..%2Fconfig%2Fserver` arrived as `../../config/server` and the forms PUT
219
225
  rewrote config/server.json. forms, views, menus, context menus, components, collections (+ FileAdapter) and
@@ -357,6 +357,7 @@ roles and notifications are stamped with it). The sections below cover the main
357
357
  | `registerLoginCheck({id, phase, check, verify?})` | A sign-in check: `phase: 'before'` (e.g. lockout, before the password is checked) or `'after'` (e.g. two-factor, can ask one more question) (0.83.0) |
358
358
  | `registerPasswordCheck({id, check})` | A password rule applied wherever a password is set (0.83.0) |
359
359
  | `safeFetch(url, {method, headers, body, timeoutMs, maxBytes, maxRedirects, truncate, signal})` | Fetch an address a site user chose, under the site's outbound rules (`services/outbound.js`): public addresses only, the connection pinned to the checked address, redirects re-checked, ports 80/443; `outboundAllowPrivate` applies on a self-hosted site and never on a signed-only one. Limits default to 1 MB / 15 s / 3 redirects and may be raised to 25 MB / 60 s / 5. Resolves `{ok, status, headers, buffer, text(), json(), url, truncated}`; a refusal rejects with `err.code === 'EREFUSED_SSRF'`. `body` is a string, Buffer or Uint8Array and `headers` a plain object or `Headers`; anything else rejects with a TypeError rather than going out empty. Use it instead of `fetch` for any user-chosen URL. Call it with `?.` - older cores lack it (1.10.31) |
360
+ | `claimHosts(fn)` | `fn(host)` returns `true` for a host this server hands on to another (a proxy - the Manager's site-manager). Core's redirect hooks, which run before plugins' `onRequest` hooks (SEO's rules, the WordPress importer's `/?p=`), then leave that host's requests alone. `host` is lower case with no port. Returns a function that withdraws the claim. Call it with `?.` - older cores lack it |
360
361
  | `registerComponent({name, source})` | Add a Domma component from a `.dmc` source string, used on pages as `<dm-name>` or `[component]`; it is listed read-only in Components (0.92.2) |
361
362
 
362
363
  `onEnable` / `onDisable` exports receive `{fastify, services, hooks}` where `hooks` holds only the role and notification
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
5
5
  "type": "module",
6
6
  "main": "server/server.js",
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Hosts another server answers - the Manager's proxied sites.
3
+ *
4
+ * On a Manager, one process receives every hosted site's requests and its site-manager plugin proxies them
5
+ * from an onRequest hook added during registerPlugins(). Core hooks added BEFORE that (SEO's redirects, the
6
+ * WordPress importer's `/?p=` redirects) see those requests first, so the Manager's own redirect rules used to
7
+ * answer other sites' addresses: a rule `/tools -> https://domma-cms.com/tools` on the Manager looped
8
+ * domma-cms.com/tools. A plugin that hands a host on claims it here (`hooks.claimHosts(fn)`), and those core
9
+ * hooks step aside for a claimed host. Nothing else is decided by it - the plugin still does the proxying.
10
+ *
11
+ * @module services/hostClaims
12
+ */
13
+
14
+ const claims = new Map();
15
+
16
+ /** The request's host name: lower case, no port (IPv6 brackets kept). */
17
+ export function hostOf(request) {
18
+ const raw = String(request?.headers?.host || '').trim().toLowerCase();
19
+ if (raw.startsWith('[')) return raw.slice(0, raw.indexOf(']') + 1);
20
+ return raw.split(':')[0];
21
+ }
22
+
23
+ /**
24
+ * `fn(host)` answers true for a host this server does not answer itself. One per owner; a second call replaces it.
25
+ * Returns a function that withdraws the claim.
26
+ */
27
+ export function claimHosts(owner, fn) {
28
+ if (typeof fn !== 'function') throw new TypeError('claimHosts needs a function (host) => boolean.');
29
+ const key = String(owner || 'unknown');
30
+ claims.set(key, fn);
31
+ return () => { if (claims.get(key) === fn) claims.delete(key); };
32
+ }
33
+
34
+ /** True when a plugin hands this request's host on - this site's own rules are not for it. Never throws. */
35
+ export function answeredElsewhere(request) {
36
+ if (!claims.size) return false;
37
+ const host = hostOf(request);
38
+ if (!host) return false;
39
+ for (const fn of claims.values()) {
40
+ try { if (fn(host) === true) return true; } catch { /* a broken claim claims nothing */ }
41
+ }
42
+ return false;
43
+ }
44
+
45
+ /** Tests only. */
46
+ export function _resetHostClaims() { claims.clear(); }
@@ -39,6 +39,7 @@ import {registerThemeProvider} from './themeSettings.js';
39
39
  import {classifyEntitlement, mayLoad} from './pluginEntitlement.js';
40
40
  import {notifierFor} from './notify.js';
41
41
  import {disableInstantCalls, enableInstantCalls, grantInstantCallsOnce} from './instantCalls.js';
42
+ import {claimHosts} from './hostClaims.js';
42
43
  import {pluginSafeFetch} from './outbound.js';
43
44
  import {disableDashboardPro, enableDashboardPro, registerWidget, unregisterWidgetsFrom} from './widgets.js';
44
45
  import {createCollection, getCollection} from './collections.js';
@@ -573,7 +574,10 @@ export async function registerPlugins(fastify) {
573
574
  // Direct messages between team members (Messages) - hooks.js 7c; a call's "Add people" uses it.
574
575
  registerDirectMessenger: (fn) => registerDirectMessenger(manifest.name, fn),
575
576
  // Fetching an address a site user chose (services/outbound.js) - the site's policy, never the plugin's.
576
- safeFetch: pluginSafeFetch},
577
+ safeFetch: pluginSafeFetch,
578
+ // Hosts this plugin hands on to another server (the Manager's site proxy): core's redirect
579
+ // hooks, which run before plugins' onRequest hooks, step aside for them (services/hostClaims.js).
580
+ claimHosts: (fn) => claimHosts(manifest.name, fn)},
577
581
  settings,
578
582
  config: {}
579
583
  });
@@ -28,6 +28,7 @@ import fp from 'fastify-plugin';
28
28
  import {createStore} from './store.js';
29
29
  import {auditAll, auditOne, AUDIT_UA, fetchLocal, hostOf, scanDetached} from './audit.js';
30
30
  import {seoRegistry} from './registry.js';
31
+ import {answeredElsewhere} from '../hostClaims.js';
31
32
  import {analyse, scanHtml, siteIssues} from '../../../admin/js/lib/seo-analyse.js';
32
33
  import {chains, checkRule, matchRedirect, MAX_RULES, normalisePath, onMoved} from '../../../admin/js/lib/seo-redirects.js';
33
34
  import {applySeo, robotsLines} from '../../../admin/js/lib/seo-schema.js';
@@ -114,6 +115,8 @@ async function seo(fastify, {enabled = true, getBaseUrl = null, rolesService = n
114
115
  if (request.method !== 'GET' && request.method !== 'HEAD') return;
115
116
  const url = String(request.url || '');
116
117
  if (SKIP.test(url)) return;
118
+ // Another site's request passing through (the Manager's proxy): this site's rules are not for it.
119
+ if (answeredElsewhere(request)) return;
117
120
  const rules = store.rules();
118
121
  if (!rules.length) return;
119
122
  const hit = matchRedirect(rules, url);
@@ -91,6 +91,7 @@ import {readWie, widgetAreaHtml, WIE_MAX_BYTES} from './widgets.js';
91
91
  import {FOOTER_BLOCKS_MAX} from '../renderer.js';
92
92
  import {allowInGitignore} from '../siteGitignore.js';
93
93
  import fsSync from 'node:fs';
94
+ import {answeredElsewhere} from '../hostClaims.js';
94
95
 
95
96
  export const WXR_MAX_BYTES = 50 * 1024 * 1024;
96
97
  export const UPLOADS_ZIP_MAX_BYTES = 1024 * 1024 * 1024;
@@ -1667,6 +1668,7 @@ async function wordpressQueryRedirects(fastify) {
1667
1668
  if (q === -1) return;
1668
1669
  const p = url.slice(0, q);
1669
1670
  if (p !== '/' && p !== '/index.php') return;
1671
+ if (answeredElsewhere(request)) return; // another site's request on its way through the Manager
1670
1672
  let params;
1671
1673
  try { params = new URLSearchParams(url.slice(q + 1)); } catch { return; }
1672
1674
  for (const name of QUERY_PARAMS) {