Files
inline-comment/.docs/decisions/0005-no-markup-sinks.md
T
Oliver_Herb 9053327486 Inline Comment 0.2.0 - initial public release
Thunderbird/Betterbird add-on (Manifest V3): typing inside a quote splits
the quote and inserts your own text with a marker such as [OH]:.

- English and German user interface
- Licensed under the Mozilla Public License 2.0
- English documentation, JSDoc lint gate, 87 tests (node:test + jsdom)
2026-11-24 12:07:09 +01:00

54 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 0005 – No markup sinks: build DOM with DOM APIs
**Date:** 2026-11-24 · **Status:** accepted
## Context
Version 0.1.0 assembled the comment block as an HTML string with hand-written escaping and wrote it
into the DOM with `innerHTML` for the manual split and the options page preview. Reviewers on
addons.thunderbird.net (ATN) reject add-ons that create DOM nodes from HTML strings that may contain
unsanitized data, i.e. code that writes markup into DOM sinks: assignments to `innerHTML` or
`outerHTML`, `insertAdjacentHTML` and `document.write`. Such sinks are also the usual way for
untrusted text to turn into markup; here the marker template, the identity name and translated
messages all end up in the page.
At the same time, the comment must reach the mail editor through `execCommand("insertHTML")`: only
editor commands end up in the undo history, so Ctrl+Z keeps working (see
[decision 0002](./0002-split-quote-via-editor.md)).
## Decision
- **DOM APIs only.** Elements are built with `createElement`, `createTextNode`, `textContent`,
`setAttribute`, `append`, `replaceChildren` and `new Option()`. User data and messages are always
set as text, never parsed as markup.
- **Comment block:** `createCommentNode()` in `src/lib/marker.js` builds the `<div>` with the marker
`<span>` and the first text as a DOM node. The options page preview and the manual split insert
this node directly.
- **`insertHTML` stays for undo.** In the editor, the compose script serializes the same node with
`outerHTML` (reading only) and passes the string to `execCommand("insertHTML", …)`. The HTML is
therefore generated from DOM nodes, never assembled by hand, and text such as `<b>` in a marker
template arrives as escaped text.
- **Translations** are applied with `textContent` and `setAttribute` (`localizeDocument()`). Because
`textContent` replaces the whole content, elements with `data-i18n` must contain text only.
- **Guarded by a test:** `test/dom-sinks.test.js` scans every file in `src/` and fails on
`innerHTML`, `outerHTML` assignments, `insertAdjacentHTML` and `document.write`. Reading
`outerHTML` is allowed.
## Alternatives considered
- **Insert the node with DOM methods (such as `insertBefore()`) in the editor as well:** no markup
string at all, but the change bypasses the editor and Ctrl+Z no longer undoes it. Kept only for
the manual split.
- **`execCommand("insertText")` plus formatting commands:** no undo problem, but colours, bold and
data attributes would need several commands and are hard to control. Used only for plain-text
messages.
- **Keep escaping HTML strings by hand (as in 0.1.0) or sanitize them:** still writes into a markup
sink and would not pass the review rule; every new string is another chance to forget the escaping.
## Consequences
- New UI code must use DOM APIs; `npm test` fails otherwise.
- Elements with `data-i18n` must not contain child elements (checked by `test/i18n.test.js`).
- The preview in the options page and the comment in the editor are built by the same function and
look the same.