domma-cms 1.67.0 → 1.67.1
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 +6 -0
- package/CLAUDE.md +1 -1
- package/package.json +1 -1
- package/server/services/markdown.js +101 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.67.1] - 2026-11-15
|
|
4
|
+
|
|
5
|
+
### Security
|
|
6
|
+
|
|
7
|
+
- **Entry text inside a card, tab or column can no longer run as shortcodes.** When a `[collection]` or `[view]` was written inside a card, box, tab, accordion, column, hero, slide, slideover or an effect, text stored in an entry - a public form submission included - could come alive as a banner, button, card, slideover, badge or other shortcode on the page. It is now shown as the text it is, as it already was outside a container. Links written in an entry still work, and the shortcodes you write yourself are unaffected.
|
|
8
|
+
|
|
3
9
|
## [1.67.0] - 2026-11-15
|
|
4
10
|
|
|
5
11
|
### Added
|
package/CLAUDE.md
CHANGED
|
@@ -84,7 +84,7 @@ wrappers) run the inline tags (`[image]` among them) plus `[grid]`/`[card]` over
|
|
|
84
84
|
so every value they draw goes through `inertShortcodes()` (the character after each `[` becomes an entity, so
|
|
85
85
|
`[form` is `[form` and nothing matches, while Markdown links in values still work): displays with no authored
|
|
86
86
|
markup encode their whole output, block templates encode each `{{field}}` / `{{{field}}}` value and leave the
|
|
87
|
-
template's own shortcodes live. A new display or placeholder must do the same. The base64 `data-ctx` / table
|
|
87
|
+
template's own shortcodes live. A new display or placeholder must do the same. Inertness only holds while nothing decodes entities mid-pipeline: every marked pass before the last one goes through `markedKeepingInert()` (`midMarked` - no numeric-entity decoding, image alt text re-inerted), never plain `marked`; a new container must use `markedBody()` or it. The base64 `data-ctx` / table
|
|
88
88
|
payloads stay raw (no brackets in base64), so filter, search and export see the stored value.
|
|
89
89
|
|
|
90
90
|
Backgrounds share `public/js/background-style.mjs` between the renderer and admin. A bare/self-closing
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import {decodeMessageAttribute} from '../../public/js/celebrations/message-attrs
|
|
|
6
6
|
import {normaliseBackground, backgroundStyle} from '../../public/js/background-style.mjs';
|
|
7
7
|
import {cssClasses} from '../../public/js/css-classes.mjs';
|
|
8
8
|
import matter from 'gray-matter';
|
|
9
|
-
import {marked} from 'marked';
|
|
9
|
+
import {Marked, marked} from 'marked';
|
|
10
10
|
import sanitizeHtml from 'sanitize-html';
|
|
11
11
|
import {readdir, readFile} from 'fs/promises';
|
|
12
12
|
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
@@ -90,8 +90,12 @@ marked.setOptions({
|
|
|
90
90
|
* @returns {string}
|
|
91
91
|
*/
|
|
92
92
|
export function inertShortcodes(html) {
|
|
93
|
+
// \x02 / \x03 frame the code-scrub placeholders: data must not be able to
|
|
94
|
+
// write one. A backslash after "[" is covered too, because Markdown reads
|
|
95
|
+
// "[\/card]" as "[/card]".
|
|
93
96
|
return String(html ?? '')
|
|
94
|
-
.replace(
|
|
97
|
+
.replace(/[\x02\x03]/g, '')
|
|
98
|
+
.replace(/\[([\w\s\/\\-])/g, (_, c) => `[&#${c.codePointAt(0)};`)
|
|
95
99
|
.replace(/\[$/, '[');
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -2090,7 +2094,9 @@ export function unindentShortTags(markdown) {
|
|
|
2090
2094
|
}
|
|
2091
2095
|
|
|
2092
2096
|
const SCRUB_PLACEHOLDER = /\x02SC(\d+):(\d+)\x03/g;
|
|
2093
|
-
|
|
2097
|
+
// The nonce keeps data from writing a placeholder of its own.
|
|
2098
|
+
const SHIELD_NONCE = randomUUID().replace(/-/g, '');
|
|
2099
|
+
const SHIELD_PLACEHOLDER = new RegExp(`DMSCT${SHIELD_NONCE}x(\\d+)x(\\d+)x`, 'g');
|
|
2094
2100
|
|
|
2095
2101
|
/**
|
|
2096
2102
|
* The two patterns a shortcode name is matched with - self-closing and wrapping -
|
|
@@ -2162,15 +2168,83 @@ let shieldCallId = 0;
|
|
|
2162
2168
|
const ATTR_TAG = /\[\/?[a-z][\w-]*\s[^\]\n]*=[^\]\n]*\](?![(\[:])/gi;
|
|
2163
2169
|
function markedBody(md) {
|
|
2164
2170
|
const text = String(md ?? '');
|
|
2165
|
-
if (!text.includes('=')) return
|
|
2171
|
+
if (!text.includes('=')) return markedKeepingInert(text);
|
|
2166
2172
|
const id = ++shieldCallId;
|
|
2167
2173
|
const held = [];
|
|
2168
2174
|
const {scrubbed, restore} = scrubCodeRegions(text);
|
|
2169
|
-
const shielded = restore(scrubbed.replace(ATTR_TAG, (tag) => { held.push(tag); return `DMSCT${id}x${held.length - 1}x`; }));
|
|
2170
|
-
if (!held.length) return
|
|
2171
|
-
return
|
|
2175
|
+
const shielded = restore(scrubbed.replace(ATTR_TAG, (tag) => { held.push(tag); return `DMSCT${SHIELD_NONCE}x${id}x${held.length - 1}x`; }));
|
|
2176
|
+
if (!held.length) return markedKeepingInert(text);
|
|
2177
|
+
return markedKeepingInert(shielded).replace(SHIELD_PLACEHOLDER, (m, call, i) => (Number(call) === id ? held[Number(i)] : m));
|
|
2172
2178
|
}
|
|
2173
2179
|
|
|
2180
|
+
/**
|
|
2181
|
+
* marked for text that later shortcode stages will still read (a container's
|
|
2182
|
+
* body, a table, a list group item), keeping inert brackets inert.
|
|
2183
|
+
*
|
|
2184
|
+
* inertShortcodes() writes the character after a `[` as a numeric entity, and
|
|
2185
|
+
* marked reads numeric entities in text back into characters. So entry data
|
|
2186
|
+
* shown inside a [card], [tabs], [grid] or an effect came out of that
|
|
2187
|
+
* container's marked pass as a plain `[banner …]` / `[button …]` /
|
|
2188
|
+
* `[slideover …]` again, and the stages after the container ran it. The same
|
|
2189
|
+
* went for a bracket an entry spelt as an entity itself (`[badge]`).
|
|
2190
|
+
*
|
|
2191
|
+
* These passes use `midMarked`, a marked that does not decode: its inlineText
|
|
2192
|
+
* tokenizer hands the text on as written, and the renderer's usual escaping
|
|
2193
|
+
* leaves existing entities alone. Nothing else differs - code, HTML blocks,
|
|
2194
|
+
* links and tables come out as marked's own. The LAST marked pass, in
|
|
2195
|
+
* parseMarkdown, stays on plain marked: nothing reads shortcodes after it.
|
|
2196
|
+
*
|
|
2197
|
+
* @param {string} text
|
|
2198
|
+
* @param {boolean} [inline] - parseInline instead of parse
|
|
2199
|
+
* @param {object} [options] - passed to marked as given
|
|
2200
|
+
* @returns {string}
|
|
2201
|
+
*/
|
|
2202
|
+
function markedKeepingInert(text, inline = false, options = undefined) {
|
|
2203
|
+
const source = String(text ?? '');
|
|
2204
|
+
if (inline) return options === undefined ? midMarked.parseInline(source) : midMarked.parseInline(source, options);
|
|
2205
|
+
return options === undefined ? midMarked.parse(source) : midMarked.parse(source, options);
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
const midMarked = new Marked({gfm: true, breaks: false});
|
|
2209
|
+
midMarked.use({
|
|
2210
|
+
tokenizer: {
|
|
2211
|
+
// marked's own inlineText, minus the numeric-entity decoding.
|
|
2212
|
+
inlineText(src) {
|
|
2213
|
+
const cap = this.rules.inline.text.exec(src);
|
|
2214
|
+
if (!cap) return undefined;
|
|
2215
|
+
return {type: 'text', raw: cap[0], text: cap[0], escaped: this.lexer.state.inRawBlock};
|
|
2216
|
+
},
|
|
2217
|
+
},
|
|
2218
|
+
// An image's alt text is its content with the markup taken out, which joins
|
|
2219
|
+
// "[**f**orm …]" back into "[form …]" inside the alt attribute - where the
|
|
2220
|
+
// later stages would run it. The flattened text is made inert again.
|
|
2221
|
+
walkTokens(token) {
|
|
2222
|
+
if (token.type !== 'image') return;
|
|
2223
|
+
token.text = inertShortcodes(token.tokens ? flatTokenText(token.tokens) : String(token.text ?? ''));
|
|
2224
|
+
delete token.tokens;
|
|
2225
|
+
},
|
|
2226
|
+
});
|
|
2227
|
+
|
|
2228
|
+
/** The plain text of inline tokens, as marked's text renderer would give it. */
|
|
2229
|
+
function flatTokenText(tokens) {
|
|
2230
|
+
let out = '';
|
|
2231
|
+
for (const token of tokens || []) {
|
|
2232
|
+
if (token.type === 'br') continue;
|
|
2233
|
+
if (token.type === 'image') out += token.tokens ? flatTokenText(token.tokens) : String(token.text ?? '');
|
|
2234
|
+
else if (token.tokens) out += flatTokenText(token.tokens);
|
|
2235
|
+
else out += String(token.text ?? token.raw ?? '');
|
|
2236
|
+
}
|
|
2237
|
+
return out;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
// marked for code that takes a marked-like object: the card renderers, and the
|
|
2241
|
+
// shortcode handlers plugins register (they render bodies that later stages
|
|
2242
|
+
// still read). Everything else on it is marked's own.
|
|
2243
|
+
const inertMarked = Object.assign((text, options) => markedKeepingInert(text, false, options), marked, {
|
|
2244
|
+
parse: (text, options) => markedKeepingInert(text, false, options),
|
|
2245
|
+
parseInline: (text, options) => markedKeepingInert(text, true, options),
|
|
2246
|
+
});
|
|
2247
|
+
|
|
2174
2248
|
/**
|
|
2175
2249
|
* Run all plugin-registered shortcode handlers against the markdown string.
|
|
2176
2250
|
* Self-closing ([name attrs /]) and wrapping ([name attrs]...[/name]) forms are both supported.
|
|
@@ -2187,7 +2261,7 @@ async function processPluginShortcodes(markdown, user = null) {
|
|
|
2187
2261
|
let result = scrubbed;
|
|
2188
2262
|
// renderMap tells a plugin with its own [map] (Blog Pro: OpenStreetMap by lat/lon) that the CMS has one too, so it can
|
|
2189
2263
|
// hand back the tags it cannot draw (an address, a postcode) for processMapBlocks.
|
|
2190
|
-
const context = {parseShortcodeAttrs, scrubCodeRegions, marked, processCardBlocks, processGridBlocks, escapeAttr, renderMap, user};
|
|
2264
|
+
const context = {parseShortcodeAttrs, scrubCodeRegions, marked: inertMarked, processCardBlocks, processGridBlocks, escapeAttr, renderMap, user};
|
|
2191
2265
|
|
|
2192
2266
|
async function replaceAsync(input, regex, mapMatch) {
|
|
2193
2267
|
const matches = [];
|
|
@@ -2271,7 +2345,7 @@ function processEffectsBlocks(markdown) {
|
|
|
2271
2345
|
.map(key => ` data-fx-${key}="${escapeAttr(String(attrs[key]))}"`).join('');
|
|
2272
2346
|
return `<div class="dm-fx-celebrate dm-fx-character"${dataAttrs} style="display:inline-block;max-width:100%;width:${width}px;vertical-align:bottom"></div>`;
|
|
2273
2347
|
}
|
|
2274
|
-
const dataAttrs = Object.entries(attrs).map(([k, v]) => ` data-fx-${k}="${
|
|
2348
|
+
const dataAttrs = Object.entries(attrs).map(([k, v]) => ` data-fx-${k}="${bracketSafeAttr(v)}"`).join('');
|
|
2275
2349
|
return `<div class="dm-fx-celebrate"${dataAttrs}></div>`;
|
|
2276
2350
|
}
|
|
2277
2351
|
apply('celebrate', renderCelebration);
|
|
@@ -2287,7 +2361,7 @@ function processEffectsBlocks(markdown) {
|
|
|
2287
2361
|
const attrs = parseShortcodeAttrs(attrStr);
|
|
2288
2362
|
if (typeof attrs.message === 'string') attrs.message = decodeMessageAttribute(attrs.message);
|
|
2289
2363
|
delete attrs.theme;
|
|
2290
|
-
const dataAttrs = Object.entries(attrs).map(([k, v]) => ` data-fx-${k}="${
|
|
2364
|
+
const dataAttrs = Object.entries(attrs).map(([k, v]) => ` data-fx-${k}="${bracketSafeAttr(v)}"`).join('');
|
|
2291
2365
|
return `<div class="dm-fx-celebrate" data-fx-theme="${themeName}"${dataAttrs}></div>`;
|
|
2292
2366
|
});
|
|
2293
2367
|
});
|
|
@@ -2625,6 +2699,15 @@ export function collectAndRewriteComponents(source) {
|
|
|
2625
2699
|
* @param {unknown} value
|
|
2626
2700
|
* @returns {string}
|
|
2627
2701
|
*/
|
|
2702
|
+
/**
|
|
2703
|
+
* An attribute value whose square brackets are entities. A celebration's
|
|
2704
|
+
* message is decoded first (authors write [ for a bracket), so without
|
|
2705
|
+
* this a "[badge]" in it sat in the attribute as live text for later stages.
|
|
2706
|
+
*/
|
|
2707
|
+
function bracketSafeAttr(value) {
|
|
2708
|
+
return escapeAttr(String(value)).replace(/\[/g, '[').replace(/\]/g, ']');
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2628
2711
|
export function classToken(value) {
|
|
2629
2712
|
return String(value ?? '').replace(/[^\w-]/g, '');
|
|
2630
2713
|
}
|
|
@@ -2944,7 +3027,7 @@ function cardImageParts(attrs, body, markedInstance) {
|
|
|
2944
3027
|
const LAYOUT_RENDERERS = {};
|
|
2945
3028
|
|
|
2946
3029
|
LAYOUT_RENDERERS['basic'] = (attrs, body) => {
|
|
2947
|
-
const im = cardImageParts(attrs, body,
|
|
3030
|
+
const im = cardImageParts(attrs, body, inertMarked);
|
|
2948
3031
|
const bodyHtml = markedBody(im.body.trim());
|
|
2949
3032
|
return `${cardRoot(attrs)}${im.media}${im.wrapBody(bodyHtml)}${cardFooterAttr(attrs)}</div>\n`;
|
|
2950
3033
|
};
|
|
@@ -2952,7 +3035,7 @@ LAYOUT_RENDERERS['basic'] = (attrs, body) => {
|
|
|
2952
3035
|
LAYOUT_RENDERERS['header-body'] = (attrs, body) => {
|
|
2953
3036
|
const title = typeof attrs.title === 'string' ? attrs.title.trim() : '';
|
|
2954
3037
|
const hdr = title ? `<div class="card-header"><div class="card-title">${escapeAttr(title)}</div></div>` : '';
|
|
2955
|
-
const im = cardImageParts(attrs, body,
|
|
3038
|
+
const im = cardImageParts(attrs, body, inertMarked);
|
|
2956
3039
|
const bodyHtml = markedBody(processGridBlocks(processInlineShortcodes(im.body.trim())));
|
|
2957
3040
|
return `${cardRoot(attrs)}${im.media}${hdr}${im.wrapBody(bodyHtml)}${cardFooterAttr(attrs)}</div>\n`;
|
|
2958
3041
|
};
|
|
@@ -2961,7 +3044,7 @@ LAYOUT_RENDERERS['header-body-footer'] = (attrs, body) => {
|
|
|
2961
3044
|
const title = typeof attrs.title === 'string' ? attrs.title.trim() : '';
|
|
2962
3045
|
const footer = typeof attrs.footer === 'string' ? attrs.footer.trim() : '';
|
|
2963
3046
|
const hdr = title ? `<div class="card-header"><div class="card-title">${escapeAttr(title)}</div></div>` : '';
|
|
2964
|
-
const im = cardImageParts(attrs, body,
|
|
3047
|
+
const im = cardImageParts(attrs, body, inertMarked);
|
|
2965
3048
|
const bodyHtml = markedBody(processGridBlocks(processInlineShortcodes(im.body.trim())));
|
|
2966
3049
|
const ftr = footer ? `<div class="card-footer">${escapeAttr(footer)}</div>` : '';
|
|
2967
3050
|
return `${cardRoot(attrs)}${im.media}${hdr}${im.wrapBody(bodyHtml)}${ftr}</div>\n`;
|
|
@@ -2969,7 +3052,7 @@ LAYOUT_RENDERERS['header-body-footer'] = (attrs, body) => {
|
|
|
2969
3052
|
|
|
2970
3053
|
LAYOUT_RENDERERS['no-header-footer'] = (attrs, body) => {
|
|
2971
3054
|
const footer = typeof attrs.footer === 'string' ? attrs.footer.trim() : '';
|
|
2972
|
-
const im = cardImageParts(attrs, body,
|
|
3055
|
+
const im = cardImageParts(attrs, body, inertMarked);
|
|
2973
3056
|
const bodyHtml = markedBody(processGridBlocks(processInlineShortcodes(im.body.trim())));
|
|
2974
3057
|
const ftr = footer ? `<div class="card-footer">${escapeAttr(footer)}</div>` : '';
|
|
2975
3058
|
return `${cardRoot(attrs)}${im.media}${im.wrapBody(bodyHtml)}${ftr}</div>\n`;
|
|
@@ -3599,7 +3682,7 @@ function processCardBlocks(markdown) {
|
|
|
3599
3682
|
const renderer = LAYOUT_RENDERERS[layout] || renderLegacyCard;
|
|
3600
3683
|
const html = range.name === 'box'
|
|
3601
3684
|
? renderBox(attrs, body)
|
|
3602
|
-
: renderer(attrs, body,
|
|
3685
|
+
: renderer(attrs, body, inertMarked, escapeAttr);
|
|
3603
3686
|
const token = `<!--cms-card-${nonce}-${held.size}-->`;
|
|
3604
3687
|
held.set(token, html);
|
|
3605
3688
|
const gap = nested ? '\n\n' : '';
|
|
@@ -3659,7 +3742,7 @@ function processTabsBlocks(markdown) {
|
|
|
3659
3742
|
// that would confuse subsequent scrubCodeRegions calls.
|
|
3660
3743
|
const restoredBody = restore(tabBody.trim());
|
|
3661
3744
|
const bodyHtml = markedBody(processCardBlocks(processGridBlocks(processInlineShortcodes(restoredBody))));
|
|
3662
|
-
const icon = tabAttrs.icon ? tabAttrs.icon.trim() : '';
|
|
3745
|
+
const icon = typeof tabAttrs.icon === 'string' ? tabAttrs.icon.trim() : '';
|
|
3663
3746
|
items.push({title, icon, paneId, bodyHtml, first: tabIdx === 1});
|
|
3664
3747
|
});
|
|
3665
3748
|
|
|
@@ -4133,7 +4216,7 @@ function processTableBlocks(markdown) {
|
|
|
4133
4216
|
: '';
|
|
4134
4217
|
const idAttr = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
|
|
4135
4218
|
|
|
4136
|
-
let tableHtml =
|
|
4219
|
+
let tableHtml = markedKeepingInert(restore(body.trim()));
|
|
4137
4220
|
|
|
4138
4221
|
tableHtml = tableHtml.replace(
|
|
4139
4222
|
'<table>',
|
|
@@ -4239,7 +4322,7 @@ function processListGroupBlocks(markdown) {
|
|
|
4239
4322
|
const itemClassStr = itemClasses.join(' ');
|
|
4240
4323
|
let items = '';
|
|
4241
4324
|
body.replace(/\[item\]([\s\S]*?)\[\/item\]/gi, (__, content) => {
|
|
4242
|
-
const html =
|
|
4325
|
+
const html = markedKeepingInert(processInlineShortcodes(restore(content.trim())), true);
|
|
4243
4326
|
items += `<div class="${itemClassStr}">${html}</div>\n`;
|
|
4244
4327
|
});
|
|
4245
4328
|
|