diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md index 32bf6b01..3d46e008 100644 --- a/.planning/ROADMAP.md +++ b/.planning/ROADMAP.md @@ -1936,7 +1936,7 @@ Plans: **Requirements**: TBD **Depends on:** Phase 34 **Context:** postcard already loads plugin templates and layouts from `views/mail/` (`pact.HasMailTemplates`, `postcard.BootPlugin`); this phase adds the editable database layer, admin screens and image handling on top. To confirm in discussion: partials (WinterCMS mail partials), preview and test send, per-locale variants, and whether the screens live in cabana or in a plugin. -**Plans:** 7/7 plans executed +**Plans:** 7/9 plans executed Plans: **Wave 1** @@ -1959,3 +1959,9 @@ Plans: **Wave 7** *(gap closure, blocked on Wave 6 completion)* - [x] 35-07-PLAN.md — unit tests for both gaps and `scripts/check-phase35.sh` with a read-only scratch-modfile consumers stage + +**Wave 8** *(gap closure CR-01, blocked on Wave 7 completion)* +- [ ] 35-08-PLAN.md — URL-scheme check on decoded attribute values instead of the whole document, a site name never stops a send (dropped with a warning) and an unsafe one is refused on the Branding form, the inlined result never stops mail, literal footer (CR-01, WR-01, WR-05), decision note + +**Wave 9** *(gap closure tests, blocked on Wave 8 completion)* +- [ ] 35-09-PLAN.md — regression and unit tests for CR-01, WR-01 and WR-05, new names required by `scripts/check-phase35.sh` (plus the IN-03 self-test fix), validation map diff --git a/.planning/phases/35-mail-templates-and-layouts-editor/35-08-PLAN.md b/.planning/phases/35-mail-templates-and-layouts-editor/35-08-PLAN.md new file mode 100644 index 00000000..75416ccc --- /dev/null +++ b/.planning/phases/35-mail-templates-and-layouts-editor/35-08-PLAN.md @@ -0,0 +1,431 @@ +--- +phase: 35-mail-templates-and-layouts-editor +plan: 08 +type: execute +wave: 8 +depends_on: ["35-06", "35-07"] +gap_closure: true +gap_ids: [CR-01] +files_modified: + - .planning/notes/2026-11-14-mail-url-scheme-check.md + - modules/postcard/safety.go + - modules/postcard/templates.go + - modules/postcard/editor.go + - modules/postcard/mailer.go + - modules/postcard/assets/partials/footer.htm + - modules/postcard/assets/default.htm + - modules/postcard/assets/system.htm + - modules/postcard/safety_smoke_test.go + - modules/postcard/editor_smoke_test.go + - modules/postcard/override_test.go + - modules/postcard/partials_smoke_test.go + - modules/postcard/override_smoke_test.go + - modules/postcard/layouts_test.go + - modules/postcard/inline_test.go + - modules/postcard/README.md + - modules/cabana/mail_admin.go + - modules/cabana/mail_brand_layout_postgres_test.go + - modules/cabana/README.md + - modules/phrasebook/backend/lang/en/lang.yaml + - modules/phrasebook/backend/lang/pl/lang.yaml + - docs/services/mail.md + - .planning/phases/35-mail-templates-and-layouts-editor/35-UI-SPEC.md +autonomous: true +requirements: [CR-01, WR-01, WR-05, D-10, D-13, D-14] + +estimate: + tokens: 110000 + raw_tokens: 110000 + tasks: 3 + confidence: low + +must_haves: + truths: + - "Mail that already works keeps working: an application that sends mail today keeps sending it after upgrading, and no admin-saved Branding value can stop mail on the built-in layouts (CR-01; roadmap goal clause; 35-06 must-have; D-14 'a failing override never stops mail')" + - "A send on the default layout and on the system layout succeeds with mail.from \"Metadata: Weekly\" and with Branding Site name 'Big Data: Summit', on the file-version path and on the override path, and the name shows in the header and the footer (CR-01)" + - "A site name that would fail the safety check (javascript:alert(1), javascript: Acme, an event-handler-shaped text, or a mail.from display name holding one) is left out of the header and footer at render time with one rate-limited warning naming its source, never its value, and the send succeeds on the override path, the file-version path, the override-failure fallback and in the editor (D-14)" + - "Saving such a name on the Branding form is a 422 on site_name with the translated en/pl message backend::lang.mail.brand.site_name_unsafe; saving a template or a layout while an unsafe name is stored is not refused (D-10, D-13)" + - "The URL-scheme check of rendered HTML looks only at URL-bearing attribute values, style attributes, style elements, comments and meta content, after decoding character references: body text such as 'metadata:' or 'Big Data: Summit' passes, while href=\"javascript:...\" is refused whether or not the layout opts out of inlining (WR-05, D-13)" + - "An inlined result that fails the safety check never stops the message: the already-checked un-inlined HTML is sent with its style block and a rate-limited warning, as docs/services/mail.md promises (WR-05, D-14)" + - "The footer of the default and system layouts prints the site name literally and HTML-escaped, as the header does: *Acme*, Acme and [x](url) are not turned into emphasis, an HTML comment or a link (WR-01)" + - "sm-user-plugin and sm-paymentgateway-plugin mail tests still pass against this checkout, read-only (check-phase35.sh --consumers)" + prohibitions: + - statement: "No file in sm-user-plugin, sm-paymentgateway-plugin or any other sibling repository is changed." + status: unresolved + verification: judgment + - statement: "Nothing is pushed or tagged (tag only at phase completion, on the default branch, after Jakub's go-ahead)." + status: unresolved + verification: judgment + - statement: "No breaking change to the mail API the core plugins use: modules/pact is untouched, postcard.Mailer, Catalog.Register and pact.HasMailTemplates keep their signatures, and every postcard and cabana API change is additive (check-phase35.sh --additive)." + status: unresolved + verification: automated + - statement: "No new dependency: go.mod and go.sum are unchanged; the tokenizer is golang.org/x/net/html, already a direct requirement, and the escaping is the standard library html package." + status: unresolved + verification: automated + - statement: "admin/ and modules/boardwalk/dist are unchanged; the 422 on site_name surfaces through the existing field-error rendering." + status: unresolved + verification: automated + - statement: "Framework code, docs and tests name no consuming application." + status: unresolved + verification: judgment + artifacts: + - path: "modules/postcard/safety.go" + provides: "attribute-scoped, entity-decoding URL-scheme check and the exported postcard.UnsafeText" + contains: "func UnsafeText" + - path: "modules/postcard/safety_smoke_test.go" + provides: "smoke test for the gap closure (prose names, encoded schemes, unsafe names, literal footer, unsafe inlined output)" + contains: "func TestMailSafetySmoke" + - path: ".planning/notes/2026-11-14-mail-url-scheme-check.md" + provides: "decision note: anchored and decoded scheme check, site-name rule, post-inline behaviour, literal footer" + contains: "WR-05" + - path: "modules/postcard/assets/partials/footer.htm" + provides: "footer partial with a plain-text argument" + contains: ".text" + key_links: + - from: "modules/postcard/templates.go" + to: "modules/postcard/safety.go" + via: "validateHTML runs the tokenizer walk instead of the whole-document scheme regex" + pattern: "unsafeMarkup" + - from: "modules/postcard/mailer.go" + to: "modules/postcard/safety.go" + via: "options and the Branding preview take the site name through layoutSiteName, which drops a name UnsafeText refuses" + pattern: "layoutSiteName" + - from: "modules/cabana/mail_admin.go" + to: "modules/postcard/safety.go" + via: "MailBrandSetting.BeforeValidate refuses a site name postcard.UnsafeText refuses" + pattern: "postcard.UnsafeText" + - from: "modules/postcard/assets/default.htm" + to: "modules/postcard/assets/partials/footer.htm" + via: "the copyright line is passed as the footer's text argument" + pattern: "partial \"footer\" \"text\"" +--- + +## Phase Goal + +ROADMAP Goal (not in user-story format; no story is invented): administrators edit every mail the application sends from the admin panel, and postcard renders the override or the file "so mail that already works keeps working". This gap-closure plan fixes the one goal-blocking gap of the 2026-11-13 re-verification (35-VERIFICATION.md `gaps:`; 35-REVIEW.md CR-01), with WR-01 and WR-05 bundled as the user confirmed. + +Gap truth (35-VERIFICATION.md): "Mail that already works keeps working: an application that sends mail today keeps sending it after upgrading, and no admin-saved Branding value can stop mail on the built-in layouts." + +Source: 35-VERIFICATION.md (gap, CR-01 regression), 35-REVIEW.md (CR-01, WR-01, WR-05), user decisions of 2026-11-14 (two plans: this fix, then 35-09 with the regression and unit tests). Spec-less probe fallback: skipped, the phase has no requirement IDs to probe (visible skip). + + +- Anchor postcard's URL-scheme check to URL-bearing attribute values, style attributes, style elements, comments and meta content, read through golang.org/x/net/html's tokenizer so attribute values are entity-decoded (CR-01 root cause, WR-05). +- Never let a site name fail a send: an unsafe Branding Site name or mail.from display name is left out of the layouts with a rate-limited warning, on every render path (CR-01, D-14). +- Refuse an unsafe Site name on the Branding form with a 422 on site_name and a translated en/pl message, through an exported postcard helper (CR-01, D-10, D-13). +- Keep the docs' promise that the inliner never stops mail: an inlined result that fails the check sends the un-inlined, already-checked HTML (WR-05). +- Print the site name literally in the footer, as in the header (WR-01). +- Record the decisions in a note; update the postcard and cabana READMEs, docs/services/mail.md and the UI-SPEC copy in the same commits as the changes they describe. + +Purpose: an application whose sender name or Branding name contains ordinary text such as "Metadata:" or "Big Data:" keeps sending password resets and every other mail on the built-in layouts, and no Branding value an administrator can save stops mail. + +Output: commits in this repository only (code and planning docs in separate commits). Nothing in sibling repositories, nothing pushed or tagged. + +**Planner decisions recorded here (Claude's discretion within the user's 2026-11-14 decisions):** +- **What the scheme check reads.** Single-URL attributes (`action`, `background`, `cite`, `codebase`, `data`, `dynsrc`, `formaction`, `href`, `icon`, `longdesc`, `lowsrc`, `manifest`, `poster`, `profile`, `src`, `usemap`, `xlink:href`, and SVG animation targets `from`, `to`, `by`) are refused when their decoded value, with every ASCII whitespace and control character removed and lower-cased, starts with `javascript:`, `vbscript:` or `data:`. List-valued attributes (`srcset`, `ping`, `archive`, `values`), `style` attributes, the `content` attribute of `meta` elements, the text of `style` elements and comment data are refused when the existing `dangerousScheme` pattern matches anywhere in them (the conservative rule stays for CSS, where prose does not belong). Text content is not checked for schemes: it is not a URL. Error messages are unchanged. +- **Event handlers.** The raw-markup regexes for script/iframe/object/embed tags and for whitespace-prefixed `on*=` stay as they are. The tokenizer walk additionally refuses any attribute whose name starts with `on`, which closes the `` form the regex misses (planner addition, T-35-47; no legitimate mail markup uses such an attribute). +- **Unsafe site name** (`postcard.UnsafeText`): a text is unsafe when, HTML-escaped as html/template prints text, it fails the rendered-HTML checks (for example event-handler-shaped text such as `Shop onclick=x`), or when it holds a script URL: `javascript:` or `vbscript:` at a scheme boundary, or `data:` at a scheme boundary directly followed by a non-space character (a data URL). A scheme boundary is the start of the text or a character that cannot belong to a URL scheme (anything but ASCII letters, digits, `+`, `.` and `-`). So `Big Data: Summit`, `Metadata: Weekly` and `Metadata:Weekly` are safe; `javascript:alert(1)`, `javascript: Acme` and `data:text/html,x` are not. +- **Render-time drop.** An unsafe Branding Site name is treated as empty, so the documented fallback applies (the display name of mail.from, if that one is safe); an unsafe mail.from display name gives no name. One warning per source per minute through the mailer's existing rate-limited `warn`, keyed `site_name:branding` or `site_name:mail.from`, logging the source and never the value. The Branding preview of an unsaved draft drops the name the same way (the save is what refuses it), so the preview shows what would be sent. +- **Post-inline failure** (WR-05 contradiction): the documented behaviour wins. The check now sees decoded attribute values and style element CSS before inlining, regardless of `disable_auto_inline_css`; an inlined result that still fails it is treated like an inliner error: the un-inlined HTML (which passed the check) is sent with its style block and the existing `inline:` warning. The README sentence that said such a result "fails the render" is corrected; the reviewer's alternative (fail the render, change the docs) is rejected in the note because it stops mail that passed the check. +- **Footer.** The `footer` partial gains a `text` argument printed as plain text (`

` through html/template in HTML, verbatim in the text part); `body` stays Markdown for callers that pass Markdown on purpose. The default and system layouts pass the copyright line as `text`. The footer partial shipped in 35-06 and is not in any tag yet (newest tag v0.6.4 predates it), so no released override depends on the old call. +- **Copy (en/pl)** `mail.brand.site_name_unsafe`: "This name cannot be shown in mail. Remove addresses that start with javascript:, vbscript: or data: and text such as onclick=." / "Tej nazwy nie można pokazać w wiadomościach. Usuń adresy zaczynające się od javascript:, vbscript: lub data: oraz tekst w rodzaju onclick=." +- **Assumption delta:** 35-RESEARCH.md Pitfall 8 ("keep the behaviour, it matches sends") and 35-PATTERNS.md "HTML safety gate: reuse them unchanged" are superseded for postcard by the user's 2026-11-14 decision; cabana.RenderMarkdown's own regexes (admin Markdown preview) are out of scope and unchanged. + + + +@~/.claude/msd-core/workflows/execute-plan.md +@~/.claude/msd-core/templates/summary.md + + + +@.planning/phases/35-mail-templates-and-layouts-editor/35-VERIFICATION.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-REVIEW.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-CONTEXT.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-06-SUMMARY.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-07-SUMMARY.md +@CLAUDE.md + + +- modules/postcard/templates.go: `dangerousScheme`, `eventHandler`, `rawUnsafeTag` (~44-47); `renderParts` (~629-720: body `validateHTML` ~658, layout HTML `validateHTML` ~701, then `inlineHTML` unless `layout.disableInline` ~704); `inlineHTML` (~731-751: inliner error warns and keeps the HTML; a failing check on the inlined output returns an error today); `validateHTML` (~813-824: raw tags, handlers, then the whole-document scheme regex); `snippetAt` (~828); `unsafeError{msg, snippet}` (~608). +- modules/postcard/partials.go: partial HTML output and the partial `markdown` func output pass `validateHTML` (~122, ~215). +- modules/postcard/editor.go: `renderLayout` checks draft CSS with `closingStyle` then `validateHTML(d.CSS)` (~243-250, error on `content_css`); `renderBrand` sets `opts.siteName = siteName(&brand, e.m.opts.From)` (~316-332); `Editor.render` builds opts with `m.options(ov.Brand)` (~191-209); `draftErrorFor` maps `unsafeError` to rule `unsafe` with its snippet (~394-436). +- modules/postcard/mailer.go: `render` builds `file := m.options(ov.Brand)` and the override render from it, then falls back to `file` (~110-147); `options` sets `siteName: siteName(brand, m.opts.From)` (~154-171); `siteName(brand *Brand, from string) string` (~176-187); `warn(key, msg string, args ...any)` rate-limited per key per minute (~217). +- modules/postcard/assets/default.htm and system.htm build `$copy` from `.year` and `.siteName` and pass it to the `footer` partial in both wrappers (default.htm lines 5 and 34, system.htm lines 9 and 39); assets/partials/footer.htm prints `{{ .body }}` in text and `{{ markdown .body }}` in HTML; partials/header.htm prints the name escaped. +- modules/cabana/mail_admin.go: `MailBrandSetting` (~1749), `Rules` (`site_name: nullable|max:255`, ~1781), `BeforeValidate` (~1805: trims site_name, collects `details[...] = []string{"backend::lang."}` and returns `&ValidationError{Details: details}`); crud.go `localizeDetails` translates those keys. +- Tests pinned to the old whole-document behaviour (must change with the code): modules/postcard/editor_smoke_test.go validate case "body scheme" (~217, prose `metadata:` expected unsafe); modules/postcard/override_test.go `TestFallback/unsafe_override` (~150-154, prose body); modules/postcard/partials_smoke_test.go `TestMailPartialsSmoke/errors` case `unsafe_html` (~327, prose in a panel body); modules/postcard/override_smoke_test.go `TestMailOverrideSmoke/fallback` case `unsafe` (~434, prose body, Postgres); modules/cabana/mail_brand_layout_postgres_test.go the last `TestMailBrandSiteName` subtest (~93-103, pins an unsafe name as saved and the preview as 422). +- Tests that keep passing and need no change: templates_test.go and mailer_test.go "unsafe vars stay out of HTML" (the dangerous value sits in a Markdown link target, which goldmark drops); inline_test.go `TestInlineCSS/safety_check` (a style-attribute URL in a direct `validateHTML` call, and a style-element URL caught before inlining). +- Test helpers: partials_smoke_test.go `fakeOverrides`, `partialsMailer`, `sendTemplate`, `copyright`; override_test.go `assertFileFallback`, `acmeBlog`, `fileWelcome`; layouts_test.go `brandedSend`, `headerCell`, `footerText`, `logoSpan`; inline_test.go `noInline`, `buttonStyle`, `styleBlock`, `defaultLayoutWithCSS`; editor_smoke_test.go `newEditor`; mailer field `log` (capture warnings) and `inline` (inliner seam). cabana: `newMailScreensEnv`, `env.expect`, `env.expectFieldRefusal(t, status, method, path, token, body, field, want, inMessage)`, `brandPreview`, `headerSpan`, `sendGrace`, `mailBrandPath`, `templateBody`, `env.mailRowID`. +- golang.org/x/net/html (v0.62.0, direct requirement; used by modules/seaglass, modules/tide, modules/cabana): `NewTokenizer(io.Reader)`, `Next()` token types `ErrorToken`, `TextToken`, `StartTagToken`, `EndTagToken`, `SelfClosingTagToken`, `CommentToken`, `DoctypeToken`; `Raw()` (raw bytes of the current token, read before `Token()`); `Token()` returns lower-cased attribute keys and attribute values with character references decoded; style contents arrive as one raw text token. +- Existing decision note format: .planning/notes/2026-11-13-mail-layouts-css-inlining.md; the sanitizer note that scopes bluemonday to stored rich text: .planning/notes/2026-10-11-framework-html-sanitizer-bluemonday.md. + + + +## Execution units and resume points + +- Other sessions work in this repository. Before each task run `git status --short modules/postcard modules/cabana modules/phrasebook docs .planning/notes .planning/phases/35-mail-templates-and-layouts-editor` and stop if another session holds uncommitted edits in a file this task touches. Never stage `examples/hello/plugins.gen.go`, `.planning/G15OFFICE.md`, `.planning/state.json` or `.planning/phases/35-mail-templates-and-layouts-editor/deferred-items.md` (other sessions' edits). +- Stage by explicit path; code and planning docs in separate commits; no co-author tags. `go vet ./...` and `go test ./...` green at every code commit, including the Docker-backed Postgres tests (run them without `-short`; if the Docker socket is denied, run through `sudo -u golem`). +- TDD tasks: verify RED before GREEN, but land each test with its fix in the listed fix commit (CLAUDE.md forbids failing commits), as 35-06 did. +- Resume check: `git log --format=%s -F --grep=''`. + +| Task | Commit subject | Resume point | +|------|----------------|--------------| +| 1 | `docs(35): decision note for the mail URL scheme check and site name safety` then `fix(postcard): check URL schemes in decoded attribute values, not in text` | TestMailSafetySmoke/prose_site_name and /encoded_scheme pass | +| 2 | `fix(postcard,cabana): unsafe site names never stop a send and are refused at save` then `docs(35): UI-SPEC copy for the unsafe site name refusal` | TestMailBrandSiteName/unsafe_name_refused passes | +| 3 | `fix(postcard): an inlined result that fails the safety check sends the style block` then `fix(postcard): print the site name literally in the built-in layouts' footer` | TestMailSafetySmoke/inline_unsafe_output and /literal_footer pass | + + + + + Task 1: End-to-end "an application whose mail.from display name is 'Metadata: Weekly' sends a template on the default and on the system layout" — the send path's scheme check only + 35-07 is complete: `git merge-base --is-ancestor a3ce0974 HEAD` exits 0 + Changes what the render-time check accepts and refuses; no schema, no exported API, no stored data; reverting the fix commit restores the old check. + .planning/notes/2026-11-14-mail-url-scheme-check.md, modules/postcard/safety.go, modules/postcard/templates.go, modules/postcard/editor.go, modules/postcard/safety_smoke_test.go, modules/postcard/editor_smoke_test.go, modules/postcard/override_test.go, modules/postcard/partials_smoke_test.go, modules/postcard/override_smoke_test.go, modules/cabana/mail_brand_layout_postgres_test.go, modules/postcard/README.md, docs/services/mail.md + + - .planning/phases/35-mail-templates-and-layouts-editor/35-REVIEW.md (CR-01, WR-05) and 35-VERIFICATION.md (`gaps:` block) + - modules/postcard/templates.go (~41-50, ~606-614, ~629-760, ~805-832) + - modules/postcard/partials.go (~108-126, ~206-220) + - modules/postcard/editor.go (~236-273, ~391-436) + - the fixtures listed in interfaces: modules/postcard/editor_smoke_test.go (~180-240), modules/postcard/override_test.go (~140-200), modules/postcard/partials_smoke_test.go (~78-140, ~318-345), modules/postcard/override_smoke_test.go (~420-450), modules/cabana/mail_brand_layout_postgres_test.go (~25-104) + - modules/seaglass/seaglass.go (~140-190, how this repository drives the x/net/html tokenizer) + - .planning/notes/2026-11-13-mail-layouts-css-inlining.md (note format) and .planning/notes/2026-10-11-framework-html-sanitizer-bluemonday.md (scope of the sanitizer decision) + - modules/postcard/README.md (~23-36, ~355-372, ~466-472) and docs/services/mail.md (~11-24, ~150-158) + + + Closes the root cause of CR-01 and the decoding half of WR-05; D-13's refusal of javascript:/vbscript:/data: URLs is kept, prose is no longer treated as a URL. + - First a planning-docs commit, alone, with the first subject: `.planning/notes/2026-11-14-mail-url-scheme-check.md` (Status: Accepted; Context: 35-VERIFICATION.md gap and 35-REVIEW.md CR-01, WR-01, WR-05; user decisions of 2026-11-14). Record every decision in this plan's "Planner decisions" list (what the check reads and how values are normalized, the on-attribute rule, the UnsafeText rule, the render-time drop and its warning, the post-inline behaviour, the footer text argument, the copy keys). Record what it supersedes: 35-RESEARCH.md Pitfall 8 "keep the behaviour" and the postcard README sentence saying text such as metadata: is refused at save; D-13 itself stands. Rejected alternatives: keep the whole-document regex and only guard the site name (body text and other configuration text keep stopping sends); a bluemonday-based mail sanitizer (it rewrites instead of refusing and would need a mail allowlist for style elements, tables and layout attributes; the 2026-10-11 note scopes bluemonday to stored rich text, and this check only locates attribute values with x/net/html, already a direct requirement); failing the render when the inlined result fails the check (stops mail that passed the check, contradicts the documented promise and D-14). Residual risk accepted: CSS escape sequences inside CSS are not decoded (mail clients do not run script URLs from CSS). + - New file modules/postcard/safety.go (package postcard), importing golang.org/x/net/html under the alias `xhtml`: + - `urlAttributes` (single-URL attribute names) and `urlListAttributes` (srcset, ping, archive, values), both as listed in the planner decisions. + - `hasDangerousScheme(val string) bool`: removes every ASCII whitespace and control character (U+0000 to U+0020 and U+007F) from the decoded value, lower-cases it, and reports whether it starts with `javascript:`, `vbscript:` or `data:`. + - `unsafeMarkup(doc string) error`: tokenizes doc with `xhtml.NewTokenizer(strings.NewReader(doc))`, keeps each token's byte offset from the length of `Raw()` (read before `Token()`), and stops at the first ErrorToken. For start and self-closing tag tokens it checks every attribute of `Token()` (keys lower-cased, values decoded): a name beginning with `on` gives an `unsafeError` with msg "rendered HTML contains event handlers"; a name in urlAttributes whose value `hasDangerousScheme` gives msg "rendered HTML contains a dangerous URL scheme"; a name in urlListAttributes, a `style` attribute, or the `content` attribute of a `meta` element whose decoded value `dangerousScheme` matches anywhere gives the same scheme msg. It tracks whether it is inside a `style` element and checks those text tokens with `dangerousScheme`; it checks comment token data with `dangerousScheme`; other text is not checked. The snippet is `snippetAt(doc, [start, end])` of the offending token, so `DraftError.Message` shows the raw markup (for example the encoded form). Doc comments say what is read and why text is not. + - templates.go `validateHTML`: keep the `rawUnsafeTag` and `eventHandler` checks on the raw markup unchanged and first, and replace the whole-document `dangerousScheme.FindStringIndex` call with `unsafeMarkup(html)`. `dangerousScheme` keeps its pattern; update its comment and the one on `validateHTML` to say where it now applies. `inlineHTML` is not changed in this task. + - editor.go `renderLayout`: check the draft CSS as the content of a style element (`validateHTML` over the CSS wrapped in an opening and a closing style tag), after the existing `closingStyle` check, so the scheme check still reads it and the error stays on `content_css` (bare CSS text would otherwise no longer be checked). + - Fixtures pinned to the old whole-document behaviour, changed in the same fix commit so `go test ./...` stays green: + - editor_smoke_test.go: the prose body draft ("See the metadata: field.") now validates. Move it into the valid-drafts loop, and replace the "body scheme" row with a "layout scheme" row: a layout draft whose HTML holds an anchor with an `href` of `javascript:alert(1)` gives field `content_html`, rule `unsafe`, and a message holding the encoded href. + - override_test.go `TestFallback/unsafe_override`: replace the prose body with a template override that selects a layout override (same `fakeOverrides`) whose HTML wrapper holds an anchor with that entity-encoded href; `assertFileFallback` still holds. + - partials_smoke_test.go `TestMailPartialsSmoke/errors` case `unsafe_html`: prose in a panel body passes now. Make the partial's own output carry a markup-level dangerous URL (register, for that case, a plugin partial whose HTML holds the entity-encoded href, called from the body) and keep the expected "dangerous". + - override_smoke_test.go `TestMailOverrideSmoke/fallback` case `unsafe`: a template body cannot produce a markup-level URL (goldmark drops raw HTML and dangerous link targets), so use a body whose rendered HTML still fails the unchanged handler check: a sentence with event-handler-shaped text such as " onclick=". Keep the case comment accurate; the file-version and log assertions are unchanged. + - mail_brand_layout_postgres_test.go: delete the 35-07 subtest of TestMailBrandSiteName that pinned an unsafe name as saved and refused by the preview. Its premise (name text failing the scheme check) is gone; Task 2 adds its replacement, `unsafe_name_refused`. + - Smoke test modules/postcard/safety_smoke_test.go, `TestMailSafetySmoke` (Docker-free, no t.Skip, package postcard). Subtests: + - `prose_site_name`: an fstest.MapFS catalog in the acme.blog namespace with one template on layout `default` and one on `system`. Send with Options.From `"Metadata: Weekly" ` and no Branding; then with `fakeOverrides` Brand SiteName "Big Data: Summit"; then with a template override present as well (override path). Every Send returns nil and the HTML holds the name. A body with "See the metadata: field." sends too. + - `encoded_scheme`: a layout override whose HTML holds the entity-encoded javascript: href, with DisableAutoInlineCSS false and then true: the file version is sent both times and the encoded form never reaches the driver. + - Docs in the same fix commit: + - postcard README: the Features "Safety checks" bullet (schemes are checked in URL-bearing attributes, style attributes, style elements, comments and meta content, after decoding character references; tags and event handlers as before, plus any attribute whose name starts with on); the Editing drafts `unsafe` row and the paragraph after it (replace the sentence that says text such as metadata: is refused with: text is not a URL, so prose such as metadata: or Big Data: Summit passes, and an encoded javascript: is decoded and refused); Dependencies, Third-party: golang.org/x/net/html (tokenizing rendered HTML for the safety checks, already a framework dependency). + - docs/services/mail.md: the Sending paragraph about rejected HTML, in the same terms. + Commit as listed in Execution units. + + + go test -short ./modules/postcard -count=1 -run '^TestMailSafetySmoke$' -v 2>&1 | grep -E '^\s*(--- FAIL|--- SKIP|--- PASS|FAIL|ok)' | tail -12 + a "FAIL" or "--- SKIP" line, or no "--- PASS: TestMailSafetySmoke/prose_site_name" or "--- PASS: TestMailSafetySmoke/encoded_scheme" line + go vet ./... && go test -short ./... && go test ./modules/postcard ./modules/cabana -count=1 2>&1 | tail -4 && (cd examples/hello && go test ./... 2>&1 | tail -3) + non-zero exit or a "FAIL" line + bash scripts/check-phase35.sh --consumers 2>&1 | tail -6; git -C ../sm-user-plugin status --porcelain; git -C ../sm-paymentgateway-plugin status --porcelain + a "refuse:" or "FAIL" line, no "phase35 consumers passed" line, or any porcelain output + go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1 2>&1 | tail -3 && go run ./cmd/summer docs:build --check 2>&1 | tail -5 + non-zero exit, or a "FAIL" or "unknown identifier" line + + + - `grep -n "^func unsafeMarkup\|^func hasDangerousScheme" modules/postcard/safety.go` prints two lines and `grep -n "golang.org/x/net/html" modules/postcard/safety.go` prints one line + - `grep -n "unsafeMarkup(" modules/postcard/templates.go` prints at least one line + - `grep -rhn 'unsafe_name_current_behaviour' modules/cabana | grep -vE '^[0-9]+:\s*//'` prints nothing + - `grep -n "^func TestMailSafetySmoke" modules/postcard/safety_smoke_test.go` prints one line and `grep -n "t.Skip" modules/postcard/safety_smoke_test.go` prints nothing + - `grep -n "x/net/html" modules/postcard/README.md` prints at least one line + - `git log --format=%s -1 -- .planning/notes/2026-11-14-mail-url-scheme-check.md` prints the docs(35) subject, on a commit older than the fix commit (`git log --format=%s -1 -- modules/postcard/safety.go` prints the fix subject) + - `git status --porcelain -- go.mod go.sum` prints nothing and `git log --oneline 0aa38db8..HEAD -- go.mod go.sum modules/pact admin modules/boardwalk/dist` prints nothing + + A sender name or Branding name with ordinary text such as "Metadata:" or "Big Data:" no longer stops mail on the built-in layouts, while URLs with a javascript:, vbscript: or data: scheme, encoded or not, are still refused in every attribute that carries one. + + + + Task 2: An unsafe site name never stops a send and is refused at save — postcard.UnsafeText, the render-time drop, the Branding 422, en/pl copy + postcard.UnsafeText becomes exported framework API that other modules and applications may call; the phrase key backend::lang.mail.brand.site_name_unsafe is published copy. + modules/postcard/safety.go, modules/postcard/mailer.go, modules/postcard/editor.go, modules/postcard/safety_smoke_test.go, modules/cabana/mail_admin.go, modules/phrasebook/backend/lang/en/lang.yaml, modules/phrasebook/backend/lang/pl/lang.yaml, modules/cabana/mail_brand_layout_postgres_test.go, modules/postcard/README.md, modules/cabana/README.md, docs/services/mail.md, .planning/phases/35-mail-templates-and-layouts-editor/35-UI-SPEC.md + + - UnsafeText: "", "Acme", "Big Data: Summit", "Metadata: Weekly", "Metadata:Weekly", "Acme ", "*Acme*" and "[x](https://example.com)" are safe; "javascript:alert(1)", "javascript: Acme", "JavaScript:x", "Go vbscript:msgbox(1)", "data:text/html,x" and "Shop onclick=x" are unsafe + - Branding SiteName "javascript:alert(1)" with mail.from "Acme ": a send on the default layout succeeds, the header and footer show Acme, neither the HTML nor the text part holds "javascript:", and one warning naming source=branding is logged; a second send within a minute logs no second warning + - Branding SiteName unsafe and the mail.from display name unsafe: the send succeeds with no header row (no logo) and a footer with the year only + - Editor.Validate of a template draft and of a layout draft under a stored unsafe Branding name returns nil; Editor.Preview of a Branding draft with an unsafe name renders without it + - PUT of the Branding settings with site_name "javascript: Acme" is a 422 on site_name with the translated text and stores nothing; "Big Data: Summit" saves and a send on the default layout shows it in the header + + + - modules/postcard/safety.go (as left by Task 1) + - modules/postcard/mailer.go (~107-222) and modules/postcard/editor.go (~189-210, ~314-332) + - modules/postcard/layouts_test.go `TestSiteName` (~362-393), so its existing cases keep passing + - modules/cabana/mail_admin.go (~1747-1851) and modules/cabana/crud.go (~104-150, localizeDetails) + - modules/phrasebook/backend/lang/en/lang.yaml and pl/lang.yaml (the `mail:` → `brand:` block with site_name and site_name_comment) + - modules/cabana/mail_brand_layout_postgres_test.go (whole file) and modules/cabana/administrators_harness_test.go (~458-482, expectFieldRefusal) + - modules/postcard/README.md Branding section (~257-293) and API reference (~385-436); modules/cabana/README.md Mail screens bullet (Branding part); docs/services/mail.md Branding (~74-89) + - .planning/phases/35-mail-templates-and-layouts-editor/35-UI-SPEC.md Branding page table (~421-430), C15 (~872-888) and the state table rows for Branding (~966-967) + + + Closes CR-01's "a site name never fails a send" and "save-time refusal" items. D-14 (mail never stops over an override) is extended to the Branding name; D-10's Branding gets a save rule; D-13 save validation is unchanged for templates and layouts. + - safety.go: exported `UnsafeText(s string) bool`. Rule per the planner decisions: unsafe when `validateHTML` fails on the text escaped with the standard library's `html.EscapeString`, or when the unexported regexp `scriptURLText` matches. `scriptURLText` holds javascript: or vbscript: at a scheme boundary, or data: at a scheme boundary directly followed by a non-space character; a boundary is the start of the text or a character other than an ASCII letter, digit, `+`, `.` or `-`. For example `(?i)(?:^|[^a-z0-9+.\-])(?:(?:javascript|vbscript):|data:\S)`. The doc comment says what it is for (text a layout prints, such as the site name), names both rules and gives "Big Data: Summit" as a safe example. + - mailer.go: + - New unexported `siteNameFrom(brand *Brand, from string) (name, skipped string)`. The candidates, in order, are the trimmed Brand.SiteName (when brand is non-nil) and the trimmed display name of from (net/mail.ParseAddress, nothing on an error). It returns the first non-empty candidate UnsafeText accepts, and in skipped the source ("branding" or "mail.from") of the first non-empty candidate it refused. + - `siteName(brand, from)` keeps its signature and returns siteNameFrom's name, so TestSiteName's cases keep passing. + - New method `(*mailer).layoutSiteName(brand *Brand) string` calls siteNameFrom with m.opts.From. When skipped is set it calls `m.warn` with key "site_name:"+skipped, message "postcard: site name left out of the layouts, it fails the mail safety check" and `slog.String("source", skipped)`, never the value. + - `(*mailer).options` uses layoutSiteName. The file version, the override render built from it and the override-failure fallback therefore all carry the same checked name. Update the comments of options and siteName. + - editor.go `renderBrand`: set `opts.siteName` from `e.m.layoutSiteName(&brand)`. The Branding preview of an unsafe draft name then renders without it; the save is what refuses it. + - cabana mail_admin.go `MailBrandSetting.BeforeValidate`: after the trim, when `postcard.UnsafeText(b.SiteName)` is true, set `details["site_name"]` to `backend::lang.mail.brand.site_name_unsafe`, collected with the colour and logo details so one 422 lists them all. Update the doc comment. Rules stay `nullable|max:255`. + - Copy: add `site_name_unsafe` under `mail.brand`, after `site_name_comment`, in modules/phrasebook/backend/lang/en/lang.yaml and pl/lang.yaml, with the en/pl texts from the planner decisions. + - Tests (smoke, in this fix commit): + - TestMailBrandSiteName gains subtest `unsafe_name_refused`. `env.expectFieldRefusal` returns 422 on site_name, containing "cannot be shown in mail", for "javascript: Acme", and the stored row keeps its previous name. `brandPreview` with that name answers 200, and its HTML holds no "javascript:". PUT of "Big Data: Summit" answers 200, and the welcome template, moved to the default layout as in the `send` subtest, shows it in the header span. site_name is cleared at the end. + - TestMailSafetySmoke gains subtest `unsafe_site_name` (the behavior items above for the mailer and the editor, with warnings captured through the mailer's `log` field). + - Docs in the same fix commit: + - postcard README: the Branding section (an unsafe name is left out of the layouts with a warning naming its source, and the mail.from fallback applies); the API reference row for `postcard.UnsafeText`; Dependencies, Standard library: add `html`. + - cabana README: the Branding part of the Mail screens bullet (a name `postcard.UnsafeText` refuses is a 422 on site_name with backend::lang.mail.brand.site_name_unsafe). + - docs/services/mail.md Branding paragraph: which names are refused at save, and that a name stored earlier is left out of mail. + - Then a planning-docs commit for 35-UI-SPEC.md: + - a Branding page table row for the refusal copy (key mail.brand.site_name_unsafe, en, pl); + - a C15 row: Unsafe site name | Branding save | 422, Details.site_name | Field line | mail.brand.site_name_unsafe; + - a state-table row: error | Branding unsafe site name | covered | field line, nothing stored, the preview shows the mail without the name. + Commit as listed in Execution units. + + + go test -short ./modules/postcard -count=1 -run '^(TestMailSafetySmoke|TestSiteName)$' -v 2>&1 | grep -E '^\s*(--- FAIL|--- SKIP|--- PASS|FAIL|ok)' | tail -12 + a "FAIL" or "--- SKIP" line, or no "--- PASS: TestMailSafetySmoke/unsafe_site_name" or "--- PASS: TestSiteName" line + go test ./modules/cabana -count=1 -run '^TestMailBrandSiteName$' -v 2>&1 | grep -E '^\s*(--- FAIL|--- SKIP|--- PASS|FAIL|ok)' | tail -10 + a "FAIL" or "--- SKIP" line, or no "--- PASS: TestMailBrandSiteName/unsafe_name_refused" line + go vet ./... && go test -short ./... && go test ./modules/postcard ./modules/cabana -count=1 2>&1 | tail -4 + non-zero exit or a "FAIL" line + go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1 2>&1 | tail -3 && go run ./cmd/summer docs:build --check 2>&1 | tail -5 && bash scripts/check-phase35.sh --additive 2>&1 | tail -3 + non-zero exit, or a "FAIL", "refuse:" or "unknown identifier" line + + + - `grep -n "^func UnsafeText" modules/postcard/safety.go` prints one line + - `grep -n "layoutSiteName" modules/postcard/mailer.go modules/postcard/editor.go` prints at least three lines (definition, options, renderBrand) + - `grep -n "postcard.UnsafeText" modules/cabana/mail_admin.go` prints one line + - `grep -n "site_name_unsafe" modules/phrasebook/backend/lang/en/lang.yaml modules/phrasebook/backend/lang/pl/lang.yaml` prints two lines + - `grep -n "postcard.UnsafeText" modules/postcard/README.md modules/cabana/README.md` prints at least two lines + - `grep -n "site_name_unsafe" .planning/phases/35-mail-templates-and-layouts-editor/35-UI-SPEC.md` prints at least two lines + - `git status --porcelain -- go.mod go.sum` prints nothing + + No Branding value an administrator can save, and no mail.from display name, can stop mail on the built-in layouts: an unsafe name is refused on the form and, if stored earlier, is left out of the mail with one warning, while prose names save and send. + + + + Task 3: The inlined result never stops mail and the footer prints the site name literally (WR-05 contradiction, WR-01) + The footer partial's text argument becomes part of the published partial contract administrators write overrides against; the post-inline change is code only. + modules/postcard/templates.go, modules/postcard/assets/partials/footer.htm, modules/postcard/assets/default.htm, modules/postcard/assets/system.htm, modules/postcard/safety_smoke_test.go, modules/postcard/layouts_test.go, modules/postcard/inline_test.go, modules/postcard/README.md, docs/services/mail.md + + - With the mailer's inliner seam returning HTML that holds an anchor with a javascript: href, the send succeeds with the un-inlined HTML (style element present, no inlined style attribute on the button, no "javascript:"), one warning keyed inline: is logged, and the text part equals the text part sent with inlining off + - With Branding SiteName `*Acme*`, the footer of the default and system layouts reads `© *Acme*` with no em element; `Acme ` appears escaped with no "raw HTML omitted" comment; `[x](https://example.com)` appears literally with no anchor inside the footer table; the header span shows the same text + - The text part's footer is the dashes line followed by the copyright line with the name verbatim + - The footer partial called with body only still renders that body as Markdown + + + - modules/postcard/templates.go (~722-751 inlineHTML) and inline_test.go (~190-230 TestInlineFailure) + - modules/postcard/assets/partials/footer.htm, assets/default.htm, assets/system.htm, assets/partials/header.htm + - modules/postcard/layouts_test.go (`footerText` ~195, `TestHeaderFooterPartials` ~212-300) + - modules/postcard/README.md CSS inlining (~184-206, including the partial table) and Branding (~290); docs/services/mail.md CSS inlining (~19-24), Partials table (~45-58), Built-in layouts (~60-73) + + + WR-05: the docs' promise wins (decision note). WR-01: the name is literal in the footer, as in the header. + - templates.go `inlineHTML`: when `validateHTML` fails on the inlined output, call opts.warn with key "inline:"+layout, message "postcard: inlined CSS failed the safety check, sending the style block only" and the layout and error args, then return the un-inlined html with a nil error, exactly as for an inliner error. Rewrite the doc comment: the input already passed validateHTML in renderParts, which now reads decoded attribute values and the CSS of style elements whether or not the layout opts out, so sending it is safe; mail is never stopped by the inliner. Commit with the first Task 3 subject, together with subtest `TestMailSafetySmoke/inline_unsafe_output` (the first behavior item) and the README and docs sentences below about inlining. + - footer.htm: add a `text` argument. The HTML section prints a paragraph holding `.text` through html/template when text is set and otherwise keeps the Markdown rendering of `.body`. The text section prints `.text` when set, otherwise `.body`, after the dashes line. The name header stays "Footer". + - default.htm and system.htm: in both wrappers of both layouts (four calls), pass the copyright line to the footer partial as its `text` argument instead of its `body` argument. + - Tests: adjust layouts_test.go or inline_test.go only where an assertion depended on the Markdown-rendered footer markup (the visible "© " text stays the same). Add subtest `TestMailSafetySmoke/literal_footer` (the footer behavior items). Commit with the second Task 3 subject, together with the README and docs changes below about the footer. + - Docs, each in the commit of the change it describes: + - postcard README: the CSS inlining paragraph (replace the sentence that says the inlined HTML failing the check fails the render with: the check runs on the decoded markup before inlining, whether or not the layout opts out, and an inlined result that fails it is sent as its style-block version with the same warning); the opt-out paragraph's failure sentence; the partial table's footer row (`text`, plain and printed escaped, or `body`, Markdown); the layouts paragraph (the footer line is passed as `text`); the Branding sentence about escaping, which is now true in header and footer. + - docs/services/mail.md: the CSS inlining paragraph (same rule), the Partials table footer row, and the Built-in layouts paragraph. + Commit as listed in Execution units. + + + go test -short ./modules/postcard -count=1 -run '^(TestMailSafetySmoke|TestHeaderFooterPartials|TestBuiltinLayoutsLogo|TestSiteName|TestInlineCSS|TestInlineCSSOptOut|TestInlineFailure)$' -v 2>&1 | grep -E '^\s*(--- FAIL|--- SKIP|--- PASS|FAIL|ok)' | tail -24 + a "FAIL" or "--- SKIP" line, or no "--- PASS: TestMailSafetySmoke/inline_unsafe_output" or "--- PASS: TestMailSafetySmoke/literal_footer" line + go vet ./... && go test -short ./... && go test ./modules/postcard ./modules/cabana -count=1 2>&1 | tail -4 && (cd examples/hello && go test ./... 2>&1 | tail -3) + non-zero exit or a "FAIL" line + bash scripts/check-phase35.sh --consumers 2>&1 | tail -6; git -C ../sm-user-plugin status --porcelain; git -C ../sm-paymentgateway-plugin status --porcelain + a "refuse:" or "FAIL" line, no "phase35 consumers passed" line, or any porcelain output + go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree' -count=1 2>&1 | tail -3 && go run ./cmd/summer docs:build --check 2>&1 | tail -5 && bash scripts/check-phase35.sh --additive 2>&1 | tail -3 + non-zero exit, or a "FAIL", "refuse:" or "unknown identifier" line + + + - `grep -c 'partial "footer" "text"' modules/postcard/assets/default.htm` prints 2 and `grep -c 'partial "footer" "text"' modules/postcard/assets/system.htm` prints 2 + - `grep -c 'partial "footer" "body"' modules/postcard/assets/default.htm modules/postcard/assets/system.htm` prints 0 for each file + - `grep -c "\.text" modules/postcard/assets/partials/footer.htm` prints at least 2 + - `grep -n "inlined CSS failed the safety check" modules/postcard/templates.go` prints one line + - `grep -n "fails the render as before" modules/postcard/README.md` prints nothing + - `git log --oneline 0aa38db8..HEAD -- go.mod go.sum modules/pact admin modules/boardwalk/dist` prints nothing + + The inliner can no longer stop a message that passed the safety check, the docs say the same thing in both places, and the footer shows the site name exactly as typed, escaped, like the header. + + + + + +## Trust Boundaries + +| Boundary | Description | +|----------|-------------| +| admin browser → layouts, partials, template overrides | administrators with system.manage_mail_layouts or system.manage_mail_templates write raw layout and partial HTML and Markdown bodies that reach every recipient | +| admin browser → Branding settings | administrators with system.manage_mail_layouts set the site name printed in every built-in-layout mail | +| application config → mail.from | the display name reaches every layout without any admin action | +| rendered mail → recipients' mail clients | HTML leaves the system; a script URL in it is stored XSS in webmail | + +## STRIDE Threat Register + +| Threat ID | Category | Component | Severity | Disposition | Mitigation Plan | +|-----------|----------|-----------|----------|-------------|-----------------| +| T-35-41 | Tampering | URL-bearing attributes in rendered mail (href, src, action, formaction, background, poster, xlink:href, srcset, SVG animation targets) | high | mitigate | `unsafeMarkup` checks every such attribute of the rendered body, partial outputs and layout HTML at save (Editor.Validate) and at send, before inlining; prefix rule after removing whitespace and control characters; list attributes checked anywhere (TestMailSafetySmoke/encoded_scheme; TestURLSchemeCheck in 35-09) | +| T-35-42 | Tampering | entity-encoded schemes (`javascript:`, `:`, `:`, `javascript:`, tab-split) bypassing the check, notably with disable_auto_inline_css on (WR-05) | high | mitigate | the x/net/html tokenizer decodes attribute values before the check; the check runs on the pre-inline HTML whatever the opt-out (TestMailSafetySmoke/encoded_scheme with the switch on and off) | +| T-35-43 | Tampering | CSS contexts (style attributes, style elements, layout CSS drafts) carrying url(javascript:/vbscript:/data:) | medium | mitigate | conservative whole-value pattern over decoded style attributes and style element text; draft CSS checked as a style element so the error stays on content_css; CSS escape sequences are not decoded, accepted because mail clients do not run script URLs from CSS (recorded in the decision note) | +| T-35-44 | Denial of service | Branding Site name or mail.from display name stopping every send on the default and system layouts, file version included (CR-01) | high | mitigate | prose no longer matches (anchored check); `postcard.UnsafeText` refuses an unsafe name at save (422 on site_name); `layoutSiteName` drops an unsafe stored or configured name on every render path (file version, override, override-failure fallback, editor) with a rate-limited warning | +| T-35-45 | Denial of service | an inlined result failing the safety check stopping the message (WR-05) | medium | mitigate | the already-checked un-inlined HTML is sent with its style block and the rate-limited inline: warning (TestMailSafetySmoke/inline_unsafe_output) | +| T-35-46 | Tampering | site name parsed as Markdown in the footer: a `[x](https://evil.example)` link or lost text in every mail (WR-01) | medium | mitigate | the built-in layouts pass the copyright line as the footer's text argument, printed through html/template (TestMailSafetySmoke/literal_footer) | +| T-35-47 | Elevation of privilege | an event-handler attribute without leading whitespace (``) missed by the raw regex | medium | mitigate | the tokenizer walk refuses every attribute whose name starts with on (planner addition) | +| T-35-48 | Information disclosure | warnings about a dropped site name | low | accept | the warning names the source (branding or mail.from) only, never the value, and is rate-limited per minute per key | +| T-35-SC | Tampering | npm/pip/cargo installs | high | accept | this plan installs no npm, pip or cargo package and adds no Go module (golang.org/x/net/html is already a direct requirement; go.mod and go.sum unchanged) | + + + +- `go vet ./... && go test -short ./...`, `go test ./modules/postcard ./modules/cabana` (Docker) and `cd examples/hello && go test ./...` green after every code commit. +- `bash scripts/check-phase35.sh --consumers` passes with both sibling trees clean; `bash scripts/check-phase35.sh --additive` passes (UnsafeText is the only exported addition). +- `go test ./cmd/summer -run 'TestCommandsDocumented|TestDocsTree'` and `go run ./cmd/summer docs:build --check` pass. +- go.mod, go.sum, modules/pact, admin/ and modules/boardwalk/dist have no commits since 0aa38db8. +- The full `bash scripts/check-phase35.sh --all` is run in 35-09 after the new tests are required by name. + + + +- Sends on the default and system layouts succeed with mail.from "Metadata: Weekly" and with Branding Site name "Big Data: Summit". +- An unsafe site name is refused on the Branding form (422 on site_name, en/pl text) and, when stored or configured anyway, is left out of the mail with a warning while the send succeeds. +- URL schemes are checked in decoded attribute values and CSS, never in text; entity-encoded schemes are refused with inlining on and off. +- An inlined result that fails the check is sent as its style-block version; the README and docs/services/mail.md agree. +- The footer prints the site name literally. +- Decision note, READMEs, docs and UI-SPEC describe what ships; nothing pushed or tagged; no sibling repository changed. + + + +Create `.planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md` when done. List the exact names 35-09 tests: `postcard.UnsafeText`, `unsafeMarkup`, `hasDangerousScheme`, `urlAttributes`, `urlListAttributes`, `scriptURLText`, `siteNameFrom`, `layoutSiteName`, the warning keys and messages, the footer `text` argument, the copy key, the smoke subtests, the fixtures changed in Task 1 and why, and any deviation (including a RED run without a separate commit). + + +## Artifacts this phase produces + +| Kind | Name | Where | +|------|------|-------| +| File (new) | `.planning/notes/2026-11-14-mail-url-scheme-check.md` | decision note (Task 1, first commit) | +| File (new) | `modules/postcard/safety.go` | Task 1, extended in Task 2 | +| Exported function | `postcard.UnsafeText(s string) bool` | modules/postcard/safety.go (Task 2) | +| Unexported function | `unsafeMarkup(doc string) error` | modules/postcard/safety.go (Task 1) | +| Unexported function | `hasDangerousScheme(val string) bool` | modules/postcard/safety.go (Task 1) | +| Unexported vars | `urlAttributes`, `urlListAttributes`, `scriptURLText` | modules/postcard/safety.go (Tasks 1, 2) | +| Changed function | `validateHTML` (scheme check through `unsafeMarkup`; tag and handler regexes unchanged) | modules/postcard/templates.go (Task 1) | +| Changed function | `inlineHTML` (an inlined result failing the check is sent un-inlined with a warning) | modules/postcard/templates.go (Task 3) | +| Changed function | `(*Editor).renderLayout` (draft CSS checked as a style element), `(*Editor).renderBrand` (uses `layoutSiteName`) | modules/postcard/editor.go (Tasks 1, 2) | +| Unexported function | `siteNameFrom(brand *Brand, from string) (name, skipped string)` | modules/postcard/mailer.go (Task 2) | +| Unexported method | `(*mailer).layoutSiteName(brand *Brand) string` | modules/postcard/mailer.go (Task 2) | +| Kept function | `siteName(brand *Brand, from string) string` (same signature, now skips unsafe candidates) | modules/postcard/mailer.go (Task 2) | +| Warning keys / messages | `site_name:branding`, `site_name:mail.from` — "postcard: site name left out of the layouts, it fails the mail safety check"; `inline:` — "postcard: inlined CSS failed the safety check, sending the style block only" | modules/postcard (Tasks 2, 3) | +| Partial argument | `footer` partial `text` (plain, escaped); `body` stays Markdown | modules/postcard/assets/partials/footer.htm (Task 3) | +| Layout change | default and system layouts pass the copyright line as `text` | modules/postcard/assets/default.htm, system.htm (Task 3) | +| Validation rule | `MailBrandSetting.BeforeValidate` refuses `postcard.UnsafeText` names on `site_name` | modules/cabana/mail_admin.go (Task 2) | +| Message key | `mail.brand.site_name_unsafe` (`backend::lang.mail.brand.site_name_unsafe`), en and pl | modules/phrasebook/backend/lang/{en,pl}/lang.yaml (Task 2) | +| Smoke test | `TestMailSafetySmoke` with subtests `prose_site_name`, `encoded_scheme` (Task 1), `unsafe_site_name` (Task 2), `inline_unsafe_output`, `literal_footer` (Task 3) | modules/postcard/safety_smoke_test.go (new) | +| Smoke subtest | `TestMailBrandSiteName/unsafe_name_refused` | modules/cabana/mail_brand_layout_postgres_test.go (Task 2) | +| Removed subtest | `TestMailBrandSiteName/unsafe_name_current_behaviour` (pinned the old behaviour in 35-07) | modules/cabana/mail_brand_layout_postgres_test.go (Task 1) | +| Changed fixtures | editor_smoke_test.go "body scheme" row → "layout scheme" row plus the prose body as a valid draft; `TestFallback/unsafe_override`; `TestMailPartialsSmoke/errors` `unsafe_html`; `TestMailOverrideSmoke/fallback` `unsafe` | modules/postcard (Task 1) | +| Docs | postcard README (Features, CSS inlining, partials table, layouts, Branding, Editing drafts, API reference, Dependencies), cabana README (Branding), docs/services/mail.md (Sending, CSS inlining, Partials, Built-in layouts, Branding) | Tasks 1-3 | +| Planning docs | 35-UI-SPEC.md Branding copy row, C15 row, state row for the unsafe site name | Task 2, second commit | + +## Follow-ups outside this plan (not planned here) + +- 35-09: regression and unit tests for everything above, the new names required by `scripts/check-phase35.sh`, and the 35-VALIDATION.md rows. +- The remaining advisory findings of 35-REVIEW.md (WR-02, WR-03, WR-04, IN-01, IN-02, IN-04) are not in the user's scope for this gap closure; the unanchored `\son[a-z]+\s*=` handler regex (prose such as " online = " still fails) is unchanged. diff --git a/.planning/phases/35-mail-templates-and-layouts-editor/35-09-PLAN.md b/.planning/phases/35-mail-templates-and-layouts-editor/35-09-PLAN.md new file mode 100644 index 00000000..9951acfa --- /dev/null +++ b/.planning/phases/35-mail-templates-and-layouts-editor/35-09-PLAN.md @@ -0,0 +1,333 @@ +--- +phase: 35-mail-templates-and-layouts-editor +plan: 09 +type: execute +wave: 9 +depends_on: ["35-08"] +gap_closure: true +gap_ids: [CR-01] +files_modified: + - modules/postcard/sitename_test.go + - modules/postcard/safety_test.go + - modules/cabana/mail_site_name_postgres_test.go + - scripts/check-phase35.sh + - .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md +autonomous: true +requirements: [CR-01, WR-01, WR-05, D-13, D-14, D-21] + +estimate: + tokens: 95000 + raw_tokens: 95000 + tasks: 3 + confidence: low + +must_haves: + truths: + - "Mail that already works keeps working: an application that sends mail today keeps sending it after upgrading, and no admin-saved Branding value can stop mail on the built-in layouts; one gate command (check-phase35.sh --all) proves it (CR-01, D-21)" + - "Named Docker-free unit tests prove: sends on the default and system layouts succeed with mail.from \"Metadata: Weekly\" and with Branding SiteName 'Big Data: Summit'; an unsafe site name (javascript:alert(1)) is dropped at render time with one rate-limited warning and the send succeeds on the file-version path, the override path and the override-failure fallback; Editor validation under an unsafe stored name succeeds (D-14)" + - "A cabana Postgres test proves a Branding save of an unsafe name is a 422 on site_name with the en and the pl text and stores nothing, prose names save, and a template save, a layout save and a send under a previously stored unsafe name are not refused (D-13)" + - "The 35-07 subtest that pinned an unsafe site name as saved and refused by the preview is gone, replaced by tests of the new behaviour" + - "Unit tests prove the anchored, decoded scheme check: body text 'metadata:' passes; href=\"javascript:...\", src=\"data:...\", entity-encoded href=\"javascript:...\" and its :, :, j and tab-split forms are refused, through a send with inlining on and with it off; an inlined result that fails the check is sent as its style-block version with one warning (WR-05)" + - "Unit tests prove the footer of the default and system layouts prints *Acme*, Acme and [x](url) literally and escaped, with no em element, no HTML comment and no link (WR-01)" + - "scripts/check-phase35.sh requires every new test by name; its self-test compares the planted consumer's go.mod with a copy taken before the run (IN-03); 35-VALIDATION.md maps CR-01, WR-01 and WR-05 and records the site-name open item as closed" + prohibitions: + - statement: "No production code changes except fixes for defects the new tests expose, each in its own fix commit and recorded as a deviation in the SUMMARY." + status: unresolved + verification: judgment + - statement: "Tests and the gate never write a sibling repository (git status --porcelain of sm-user-plugin and sm-paymentgateway-plugin stays empty) and never reach the network beyond localhost, httptest servers and testcontainers." + status: unresolved + verification: automated + - statement: "No new dependency: go.mod and go.sum are unchanged." + status: unresolved + verification: automated + - statement: "Nothing is pushed or tagged (tag only at phase completion, on the default branch, after Jakub's go-ahead)." + status: unresolved + verification: judgment + artifacts: + - path: "modules/postcard/sitename_test.go" + provides: "site-name send regressions, the render-time drop, UnsafeText rules, the literal footer" + contains: "func TestUnsafeSiteNameDropped" + - path: "modules/postcard/safety_test.go" + provides: "anchored and decoded URL-scheme check, unsafe inlined output" + contains: "func TestURLSchemeCheck" + - path: "modules/cabana/mail_site_name_postgres_test.go" + provides: "Branding refusal and stored-unsafe-name saves and sends" + contains: "func TestMailSiteNameSafety" + - path: "scripts/check-phase35.sh" + provides: "phase gate requiring the new names" + contains: "TestMailSiteNameSafety" + key_links: + - from: "scripts/check-phase35.sh" + to: "modules/postcard/sitename_test.go" + via: "GO_TESTS requires TestSiteNameSend, TestUnsafeSiteNameDropped, TestUnsafeText and TestFooterSiteNameLiteral by name" + pattern: "TestUnsafeSiteNameDropped" + - from: "scripts/check-phase35.sh" + to: "modules/cabana/mail_site_name_postgres_test.go" + via: "DOCKER_TESTS requires TestMailSiteNameSafety by name" + pattern: "TestMailSiteNameSafety" + - from: "modules/postcard/safety_test.go" + to: "modules/postcard/safety.go" + via: "validateHTML and sends through layout overrides exercise unsafeMarkup" + pattern: "TestURLSchemeCheck" +--- + +## Phase Goal + +ROADMAP Goal (not in user-story format; no story is invented): administrators edit every mail the application sends from the admin panel, and mail that already works keeps working. Project rule 2 puts unit tests in the last plan of the phase; this plan is the last plan of the CR-01 gap closure and proves 35-08 with regression and unit tests and the extended phase gate (D-21). + +Gap truth (35-VERIFICATION.md): "Mail that already works keeps working: an application that sends mail today keeps sending it after upgrading, and no admin-saved Branding value can stop mail on the built-in layouts." + +Spec-less probe fallback: skipped, the phase has no requirement IDs to probe (visible skip). + + +- postcard Docker-free tests for the verifier's regressions: prose site names on the default and system layouts (mail.from and Branding), the render-time drop of an unsafe name on every path, `postcard.UnsafeText`, the anchored and decoded scheme check with inlining on and off, the unsafe inlined result, the literal footer. +- A cabana Postgres test for the Branding 422 (en and pl), prose names, and template/layout saves and sends under a previously stored unsafe name. +- `scripts/check-phase35.sh` requires every new name; the IN-03 self-test assertion compares the planted consumer's go.mod; `--all` passes. +- 35-VALIDATION.md maps CR-01, WR-01 and WR-05 and closes the site-name open item. + +Purpose: D-21's "unit tests last" for the CR-01 gap closure; the gate is what `/msd-verify-work 35` re-runs before the pending human items. + +Output: test and gate-script commits in this repository and one planning-docs commit for 35-VALIDATION.md. No sibling repository is changed; nothing is pushed or tagged. + + + +@~/.claude/msd-core/workflows/execute-plan.md +@~/.claude/msd-core/templates/summary.md + + + +@.planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-08-PLAN.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-VERIFICATION.md +@.planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md +@CLAUDE.md + + +- Names under test come from 35-08-SUMMARY.md (where it differs from this plan, the SUMMARY wins): `postcard.UnsafeText`, unexported `unsafeMarkup`, `hasDangerousScheme`, `urlAttributes`, `urlListAttributes`, `scriptURLText`, `siteNameFrom`, `(*mailer).layoutSiteName`, `siteName`; warning keys `site_name:branding`, `site_name:mail.from`, `inline:`; footer partial argument `text`; copy key `backend::lang.mail.brand.site_name_unsafe`; smoke test `TestMailSafetySmoke` (subtests prose_site_name, encoded_scheme, unsafe_site_name, inline_unsafe_output, literal_footer) and `TestMailBrandSiteName/unsafe_name_refused`. +- postcard test helpers (package postcard): partials_smoke_test.go `fakeOverrides{ov}`, `partialsMailer(t, opts, ov)`, `sendTemplate(t, m, drv, name, vars)`, `copyright()`; override_test.go `assertFileFallback(t, cat, file, opts, wantLog)`, `acmeBlog`, `fileWelcome(t)`; layouts_test.go `brandedSend(t, brand, from, template)`, `headerCell(html)`, `footerText(t, html)`, `logoSpan`, `htmlTags`/`withClass`; inline_test.go `noInline`, `buttonStyle`, `styleBlock`, `defaultLayoutWithCSS(css, optOut)`; editor_smoke_test.go `newEditor(t, ov)`; mailer fields `log` (a `*slog.Logger` to capture warnings) and `inline` (inliner seam). +- cabana test helpers (package cabana_test, Postgres, skip under -short like the other mail Postgres tests): mail_screens_smoke_test.go `newMailScreensEnv(t, mutate func(*compass.Config))`, `newMailScreensEnvWith(t, mailEnvOptions{files, keep, mutate, writer})`, `env.admin(t, name, superuser, roles)`, `env.expect`, `env.call`, `env.gdb`, `env.mailRowID`; administrators_harness_test.go `env.expectFieldRefusal(t, status, method, path, token, body, field, want, inMessage)`, `errorEnvelope`, `detailHas`; mail_locale_postgres_test.go `getInLanguage` (Accept-Language pattern), `sendGrace(t, env, name)`; mail_brand_layout_postgres_test.go `brandPreview`, `headerSpan`, `mailBrandPath`, `templateBody`, `mailTemplatesPath`; `postcard.BrandTable`, `postcard.TemplatesTable`, `postcard.LayoutsTable`; fixture template `blogWelcome`. +- scripts/check-phase35.sh: `GO_TESTS` (Docker-free names, never skip under -short, ~74-100), `DOCKER_TESTS` (~103-122), `go_pkg_named` anchors names; `self_test_consumers` (~569-616) holds the IN-03 assertion (~611) in the workspace-modfile case; `run_go` prints "phase35 go passed"; `run_all` prints "Phase 35 gate passed". +- Existing test names that must not be reused: TestSiteName, TestBuiltinLayoutsLogo, TestHeaderFooterPartials, TestButtonPartial, TestInlineCSS, TestInlineCSSOptOut, TestInlineFailure, TestMailSafetySmoke, TestMailBrandSiteName, TestMailLayoutInlineOptOut, TestOverride, TestFallback, TestValidateDraft and the *Smoke tests. + + + +## Execution units and resume points + +- Before each task run `git status --short modules/postcard modules/cabana scripts .planning/phases/35-mail-templates-and-layouts-editor` and stop if another session holds uncommitted edits in files this task touches. Never stage `examples/hello/plugins.gen.go`, `.planning/G15OFFICE.md`, `.planning/state.json` or `.planning/phases/35-mail-templates-and-layouts-editor/deferred-items.md`. +- Stage by explicit path; no co-author tags. Tests are written against the shipped 35-08 code; a defect a test exposes gets its own `fix(): ...` commit before the test commit, recorded as a deviation. `go vet ./...` and `go test ./...` green at every commit. Docker-backed tests run without `-short` (through `sudo -u golem` if the Docker socket is denied). +- Each test task adds its new names to the gate's required arrays in the same commit as the tests, so the gate never requires a test that does not exist yet. +- Tests pin shipped behaviour, so a first green run is expected; show they are not vacuous with mutation runs (break the rule under test temporarily, see the test fail, restore with `git checkout -- `), as 35-07 did, and record them in the SUMMARY. +- Resume check: `git log --format=%s -F --grep=''`. + +| Task | Commit subject | Resume point | +|------|----------------|--------------| +| 1 | `test(postcard): site names on the built-in layouts never stop a send` | `--go` passes with TestSiteNameSend, TestUnsafeSiteNameDropped, TestUnsafeText, TestMailSafetySmoke required | +| 2 | `test(postcard): decoded URL scheme check, unsafe inlined output and the literal footer` | `--go` passes with TestURLSchemeCheck, TestInlineUnsafeOutput, TestFooterSiteNameLiteral required | +| 3 | `test(cabana): unsafe Branding site names refused at save, stored ones never block saves or sends`, `test(35): self-test compares the planted consumer's go.mod`, then `docs(35): validation map for the site name safety gap` | `bash scripts/check-phase35.sh --all` passes | + + + + + Task 1: End-to-end "one gate command proves mail keeps sending with prose and unsafe site names on the built-in layouts" — the site-name tests and their gate entries only + 35-08 is complete: `.planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md` exists and `git log --format=%s -F --grep='fix(postcard,cabana): unsafe site names never stop a send'` prints one line + modules/postcard/sitename_test.go, scripts/check-phase35.sh + + - TestSiteNameSend: an fstest.MapFS catalog with one template on layout default and one on system; with Options.From "\"Metadata: Weekly\" " and no Branding, and again with fakeOverrides Brand SiteName "Big Data: Summit", Send returns nil for both layouts; the header span and the footer text (copyright() plus the name) carry the name and the text part holds it; this holds on the file-version path (Brand only), on the override path (a template override present) and on the override-failure fallback (an override reading a field of a variable the caller does not pass falls back to the file version, which carries the name); a body holding "See the metadata: field." sends and keeps that text + - TestUnsafeSiteNameDropped: Branding SiteName "javascript:alert(1)" with Options.From "Acme " sends on both layouts with Acme in header and footer, and neither the HTML nor the text part holds "javascript:"; two sends within a minute log exactly one warning, carrying source=branding and not the value; with Branding "javascript: Acme" and From "\"vbscript:x\" " the send succeeds with no header row and a footer holding only the year; "Shop onclick=x" as the Branding name is dropped the same way; all three render paths (file version, override, override-failure fallback) succeed without the unsafe name; Editor.Validate of a template draft and of a layout draft under the unsafe Branding returns nil; Editor.Preview of a Branding draft with SiteName "javascript: Acme" renders without the name and without an error + - TestUnsafeText: safe for "", "Acme", "Big Data: Summit", "Metadata: Weekly", "Metadata:Weekly", "Data: Summit", "Acme ", "*Acme*", "[x](https://example.com)"; unsafe for "javascript:alert(1)", "javascript: Acme", "JAVASCRIPT:x", "Go vbscript:msgbox(1)", "data:text/html,x", "Shop data:x", "Shop onclick=x", "x onload = 1" + + + - .planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md (exact names, warning texts, deviations) + - modules/postcard/safety.go, modules/postcard/mailer.go (render, options, siteNameFrom, layoutSiteName, warn), modules/postcard/editor.go (render, renderBrand) + - modules/postcard/safety_smoke_test.go (what the smoke test already covers; extend, do not duplicate) + - modules/postcard/layouts_test.go (helpers and TestSiteName), modules/postcard/partials_smoke_test.go (~78-140 helpers), modules/postcard/override_test.go (~140-230 assertFileFallback), modules/postcard/inline_test.go (~190-230, warning capture through mailer.log) + - scripts/check-phase35.sh (~70-125 arrays, ~300-345 go_named/go_pkg_named, ~666-674 run_go) + + + Per D-21 (unit tests last) and D-14 (mail never stops over a failing override, extended by 35-08 to the site name): + - New file modules/postcard/sitename_test.go in package postcard, with `TestSiteNameSend`, `TestUnsafeSiteNameDropped` and `TestUnsafeText` for the behavior list above. + - Docker-free: never call t.Skip, use small fstest.MapFS catalogs, and compare HTML by tag and attribute (the inliner re-serializes markup), never by whole-document equality. Capture warnings by setting the mailer's `log` field to a text handler over a buffer, then count the lines that hold the 35-08 warning text. + - Use table subtests named after the layout and the path (for example `default/file_version`, `system/override_fallback`), so a failure names its case. + - In the same commit add `./modules/postcard:TestMailSafetySmoke`, `./modules/postcard:TestSiteNameSend`, `./modules/postcard:TestUnsafeSiteNameDropped` and `./modules/postcard:TestUnsafeText` to `GO_TESTS` in scripts/check-phase35.sh. + Commit as listed in Execution units. + + + go test -short ./modules/postcard -count=1 -run '^(TestSiteNameSend|TestUnsafeSiteNameDropped|TestUnsafeText|TestMailSafetySmoke)$' -v 2>&1 | grep -E '^(--- |FAIL|ok|PASS)' | tail -12 + a "FAIL" or "--- SKIP" line, or fewer than four "--- PASS" lines + go vet ./... && go test -short ./... && bash scripts/check-phase35.sh --go 2>&1 | tail -4 + non-zero exit, a "refuse:" or "FAIL" line, or no "phase35 go passed" line + + + - `grep -c "^func Test\(SiteNameSend\|UnsafeSiteNameDropped\|UnsafeText\)(" modules/postcard/sitename_test.go` prints 3 + - `grep -n "t.Skip" modules/postcard/sitename_test.go` prints nothing + - `grep -n "Metadata: Weekly\|Big Data: Summit" modules/postcard/sitename_test.go` prints at least two lines + - `grep -n "TestSiteNameSend\|TestUnsafeSiteNameDropped\|TestUnsafeText\|TestMailSafetySmoke" scripts/check-phase35.sh` prints at least four lines + + The verifier's send-path regressions (prose names from mail.from and from Branding, an unsafe name on every render path) are pinned by named tests the gate's go stage requires. + + + + Task 2: Unit tests for the anchored, decoded scheme check, the unsafe inlined result and the literal footer + modules/postcard/safety_test.go, modules/postcard/sitename_test.go, scripts/check-phase35.sh + + - TestURLSchemeCheck accepts (validateHTML returns nil): a paragraph "See the metadata: field", a paragraph "Big Data: Summit", an img with alt "Data: Summit" and an https src, a td with title "javascript: tips", an anchor whose https href holds "javascript:x" in its query string + - TestURLSchemeCheck refuses with "dangerous URL scheme": href javascript:alert(1); href " JavaScript:alert(1)"; src data:image/png;base64,AAAA; href vbscript:msgbox(1); form action, button formaction, table background and video poster with javascript:x; an svg anchor with xlink:href javascript:x; img srcset "a.png 1x, javascript:x 2x"; a style attribute with url(javascript:x) and with url("javascript:x"); a style element holding url(data:image/png;base64,AA); a meta refresh whose content holds url=javascript:x; the encoded hrefs javascript:alert(1), javascript:alert(1), javascript:alert(1), javascript:alert(1), java script:alert(1) and java script:alert(1) + - TestURLSchemeCheck refuses with "event handlers": an img whose src is followed by onerror with no whitespace in between + - TestURLSchemeCheck, send path: a layout override whose HTML holds an anchor with href javascript:alert(1) makes the send fall back to the file version (assertFileFallback), with DisableAutoInlineCSS false and with it true, and the encoded form never reaches the driver + - TestURLSchemeCheck, editor: that layout draft fails Editor.Validate on content_html with rule unsafe for both opt-out values; a layout draft whose CSS holds url(javascript:x) fails on content_css with rule unsafe; a template draft whose body is "See the metadata: field." validates + - TestInlineUnsafeOutput: with the mailer's inline seam returning HTML that holds an anchor with a javascript: href, Send returns nil; the sent HTML has a style element, no inlined style attribute on the button and no "javascript:"; one warning keyed inline: is logged across two sends within a minute; the text part equals the text part of the same message sent with noInline + - TestFooterSiteNameLiteral: for the default and the system layout with Branding SiteName `*Acme*`, `Acme ` and `[x](https://example.com)`, footerText equals copyright() plus a space plus the name; the footer table holds no em element, no "raw HTML omitted" comment and no anchor; the header span shows the same text; the text part's footer line holds the name verbatim; the footer partial called with body only still renders Markdown (a `*b*` body gives an em element) + + + - .planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md + - modules/postcard/safety.go, modules/postcard/templates.go (validateHTML, inlineHTML), modules/postcard/editor.go (renderLayout, draftErrorFor) + - modules/postcard/assets/partials/footer.htm, assets/default.htm, assets/system.htm (as left by 35-08) + - modules/postcard/inline_test.go (TestInlineCSS, TestInlineFailure helpers), modules/postcard/editor_smoke_test.go (DraftError field and rule assertions), modules/postcard/layouts_test.go (footerText, headerCell) + - modules/postcard/sitename_test.go (as left by Task 1) + + + Per D-21 and D-13 (the safety checks D-13 names still refuse javascript:/vbscript:/data: URLs, now read from decoded attribute values), for WR-05 and WR-01: + - New file modules/postcard/safety_test.go (package postcard) with `TestURLSchemeCheck` (table subtests for the accept and refuse lists, then send-path and editor subtests) and `TestInlineUnsafeOutput`. + - Add `TestFooterSiteNameLiteral` to modules/postcard/sitename_test.go. + - The refuse table checks the error text (the unsafeError message) and that the snippet points at the offending markup, as `DraftError.Message` shows it. + - Docker-free, no t.Skip; assert by tag and attribute. + - In the same commit add `./modules/postcard:TestURLSchemeCheck`, `./modules/postcard:TestInlineUnsafeOutput` and `./modules/postcard:TestFooterSiteNameLiteral` to `GO_TESTS`. + - If a case exposes a defect in 35-08's code (for example an attribute missing from `urlAttributes`), fix it in its own `fix(postcard): ...` commit first, with the README and docs line it affects, and record the deviation. + Commit as listed in Execution units. + + + go test -short ./modules/postcard -count=1 -run '^(TestURLSchemeCheck|TestInlineUnsafeOutput|TestFooterSiteNameLiteral)$' -v 2>&1 | grep -E '^(--- |FAIL|ok|PASS)' | tail -10 + a "FAIL" or "--- SKIP" line, or fewer than three "--- PASS" lines + go vet ./... && go test -short ./... && go test ./modules/postcard -count=1 2>&1 | tail -3 && bash scripts/check-phase35.sh --go 2>&1 | tail -4 + non-zero exit, a "refuse:" or "FAIL" line, or no "phase35 go passed" line + + + - `grep -c "^func Test\(URLSchemeCheck\|InlineUnsafeOutput\)(" modules/postcard/safety_test.go` prints 2 and `grep -c "^func TestFooterSiteNameLiteral(" modules/postcard/sitename_test.go` prints 1 + - `grep -n "t.Skip" modules/postcard/safety_test.go modules/postcard/sitename_test.go` prints nothing + - `grep -c ":\|:\|:\|j" modules/postcard/safety_test.go` prints at least 4 + - `grep -n "TestURLSchemeCheck\|TestInlineUnsafeOutput\|TestFooterSiteNameLiteral" scripts/check-phase35.sh` prints at least three lines + + The scheme check's new boundaries (prose passes, every encoded form and every URL-bearing attribute is refused, inlining on or off), the style-block fallback for an unsafe inlined result and the literal footer are pinned by named tests in the fast loop. + + + + Task 3: cabana Postgres test for the Branding refusal and stored unsafe names; IN-03 self-test fix; gate --all; validation map + modules/cabana/mail_site_name_postgres_test.go, scripts/check-phase35.sh, .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md + + - TestMailSiteNameSafety/refused_on_save: PUT of the Branding settings with site_name "javascript: Acme" is a 422 whose Details.site_name holds the en text ("cannot be shown in mail"), and the same request with Accept-Language pl holds the pl text ("nie można pokazać"); the stored row keeps its previous site_name + - TestMailSiteNameSafety/prose_names_saved: "Big Data: Summit" and "Metadata: Weekly" each save with 200 and are stored as typed + - TestMailSiteNameSafety/preview_drops_unsafe_name: POST /mail/preview mode branding with site_name "javascript: Acme" answers 200 and its HTML holds no "javascript:" and no header span with that text + - TestMailSiteNameSafety/stored_unsafe_name_saves: with "javascript: Acme" written straight into the branding row (as data saved before the fix would be), a PUT of the welcome template moved to the default layout answers 200, and a PUT of the default layout's override answers 200 + - TestMailSiteNameSafety/stored_unsafe_name_send: with that stored name, a send of the welcome template on the default layout succeeds and its HTML holds no "javascript:" + - TestMailSiteNameSafety/mail_from_prose_name: with mail.from set to "\"Metadata: Weekly\" " in the environment's configuration and no Branding name, sends of the welcome template on the default and on the system layout succeed and the header span reads "Metadata: Weekly" + - check-phase35.sh --self-test still prints "PASS self-test workspace-modfile", now proving the planted consumer's go.mod is byte-identical before and after the modfile run + + + - .planning/phases/35-mail-templates-and-layouts-editor/35-08-SUMMARY.md + - modules/cabana/mail_brand_layout_postgres_test.go (style, helpers, the unsafe_name_refused smoke subtest from 35-08) and modules/cabana/mail_screens_smoke_test.go (~126-200 env construction, mutate) + - modules/cabana/mail_locale_postgres_test.go (~54-80 getInLanguage, sendGrace), modules/cabana/administrators_harness_test.go (~458-482) + - modules/cabana/mail_admin.go MailBrandSetting.BeforeValidate (as left by 35-08) + - scripts/check-phase35.sh `self_test_consumers` (~569-616) and DOCKER_TESTS (~103-122) + - .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md (whole file) + + + Per D-21 and D-13: + - New file modules/cabana/mail_site_name_postgres_test.go (package cabana_test) with `TestMailSiteNameSafety` and the six subtests above. + - It is a Postgres test that skips under -short like the other mail Postgres tests and reuses `newMailScreensEnv`. + - Write the stored unsafe name through `env.gdb` on `postcard.BrandTable` (the form refuses it now). + - Build the mail.from case in its own environment through the `mutate` hook. + - Use the Accept-Language pattern of `getInLanguage` for the pl request. + - In the same commit add `./modules/cabana:TestMailSiteNameSafety` to `DOCKER_TESTS`, with the first Task 3 subject. + - Separate commit (IN-03, second subject): in `self_test_consumers`' workspace-modfile case, copy the planted consumer's go.mod to the scratch area before the modfile run and compare it after with `cmp -s`. Keep the replace-line grep, and drop the git-status clause on the dirty-sibling fixture repository (it asserted against the wrong repository). The case keeps its PASS line and its refuse text. + - Run `bash scripts/check-phase35.sh --all` on a Docker host. Use PHASE35_ALLOW_NO_DOCKER only when no daemon answers, and then state it in the SUMMARY. + - Planning-docs commit for 35-VALIDATION.md: + - CR-01 rows: site names on the send path (postcard unit: TestSiteNameSend, TestUnsafeSiteNameDropped, TestUnsafeText, TestMailSafetySmoke); the anchored and decoded scheme check and the unsafe inlined result (postcard unit: TestURLSchemeCheck, TestInlineUnsafeOutput); the admin side (cabana Postgres: TestMailSiteNameSafety, TestMailBrandSiteName). + - A WR-01 row (TestFooterSiteNameLiteral) and a WR-05 row (TestURLSchemeCheck send and editor subtests, TestInlineUnsafeOutput), each with its exact `go test` command. + - Replace the paragraph that records the Branding site name as an open item with a "CR-01 status" line: closed by 35-08 and 35-09, decision note `.planning/notes/2026-11-14-mail-url-scheme-check.md`. + - Add a Manual-Only row: on sm-demo-app, typing "javascript: Acme" as the Branding Site name and saving shows the refusal line under the field, and "Big Data: Summit" saves and shows in the preview header and footer. + - Extend the Wave 0 list with the three new test files. + Commit as listed in Execution units. + + + go test ./modules/cabana -count=1 -run '^TestMailSiteNameSafety$' -v 2>&1 | grep -E '^\s*(--- |FAIL|ok)' | tail -12 + a "FAIL" or "--- SKIP" line, or no "--- PASS: TestMailSiteNameSafety" line, or fewer than six subtest "--- PASS" lines + bash scripts/check-phase35.sh --self-test 2>&1 | tail -5 + non-zero exit, a "refuse:" line, or no "PASS self-test workspace-modfile" line in the full output + bash scripts/check-phase35.sh --all 2>&1 | tail -15; git -C ../sm-user-plugin status --porcelain; git -C ../sm-paymentgateway-plugin status --porcelain + a "refuse:" or "FAIL" line, no "Phase 35 gate passed" line, or any porcelain output + + + - `grep -c "^func TestMailSiteNameSafety(" modules/cabana/mail_site_name_postgres_test.go` prints 1 + - `grep -rhn 'unsafe_name_current_behaviour' modules/cabana | grep -vE '^[0-9]+:\s*//'` prints nothing + - `grep -n "TestMailSiteNameSafety" scripts/check-phase35.sh` prints at least one line + - `sed -n '/^self_test_consumers()/,/^}/p' scripts/check-phase35.sh | grep -v '^\s*#' | grep -c 'status --porcelain -- go.mod'` prints 0 and `sed -n '/^self_test_consumers()/,/^}/p' scripts/check-phase35.sh | grep -c "cmp -s"` prints at least 1 + - `grep -c "CR-01" .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md` prints at least 3, and `grep -n "WR-01\|WR-05" .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md` prints at least two lines + - `grep -n "CR-01 status" .planning/phases/35-mail-templates-and-layouts-editor/35-VALIDATION.md` prints one line + - `git status --porcelain -- go.mod go.sum` prints nothing + + The admin side of CR-01 is pinned by a named Postgres test, one command proves the whole gap closure plus the unchanged core plugins, the self-test checks the right file, and the validation map records how. + + + + + +## Trust Boundaries + +| Boundary | Description | +|----------|-------------| +| gate script → sibling repositories | the consumers stage builds and tests code in repositories this phase must not change | +| tests → Docker | Postgres tests start containers on the local daemon | +| tests → stored Branding row | a test writes an unsafe name straight into the database to model data saved before the fix | + +## STRIDE Threat Register + +| Threat ID | Category | Component | Severity | Disposition | Mitigation Plan | +|-----------|----------|-----------|----------|-------------|-----------------| +| T-35-49 | Repudiation | regression tests that skip, match nothing or go missing while the gate passes | medium | mitigate | every new name is required in GO_TESTS or DOCKER_TESTS; detect_go refuses skips, zero matches and missing names (existing rules); Docker-free files contain no t.Skip (acceptance criteria) | +| T-35-50 | Tampering | the gate self-test asserting against the wrong repository, so a write to the planted consumer's go.mod passes (IN-03) | low | mitigate | cmp -s of the planted consumer's go.mod against a copy taken before the modfile run | +| T-35-51 | Tampering | tests or the gate writing a sibling repository | medium | mitigate | consumers stage stays read-only through scratch modfiles; git status --porcelain of both siblings checked before and after (verify) | +| T-35-52 | Tampering | the direct write of an unsafe name leaking into other tests on the shared database | low | mitigate | newMailScreensEnv empties the mail tables per environment; the test clears site_name at the end of the subtests that set it | +| T-35-SC | Tampering | npm/pip/cargo installs | high | accept | this plan installs no package and adds no Go module | + + + +- `go vet ./... && go test ./...` green (Docker), and `go test -short ./...` green. +- `bash scripts/check-phase35.sh --all` passes; sibling working trees unchanged. +- 35-VALIDATION.md maps CR-01, WR-01 and WR-05; the site-name open item is recorded as closed. +- go.mod and go.sum unchanged; no production file changed except recorded `fix(...)` deviations. + + + +- Named tests pin the verifier's regressions: prose site names send on the default and system layouts (mail.from and Branding), an unsafe name is dropped with a warning on every render path, a Branding save of an unsafe name is a 422 on site_name, and a template or layout save under a stored unsafe name is not refused. +- The scheme check, the unsafe inlined result and the literal footer are pinned with inlining on and off. +- The gate requires every new name, its self-test checks the planted consumer's go.mod, and `--all` passes. +- Ready for `/msd-verify-work 35`: re-verify the CR-01 gap, then run the pending human items in 35-VERIFICATION.md (UAT test 1 re-run, scoped UAT test 8 re-run, real-inbox check, judgment-tier prohibitions) and the new Manual-Only row. Nothing pushed or tagged. + + + +Create `.planning/phases/35-mail-templates-and-layouts-editor/35-09-SUMMARY.md` when done, with the gate output summary, the list of required test names, the mutation runs that stand in for RED, and any fix commits recorded as deviations. + + +## Artifacts this phase produces + +| Kind | Name | Where | +|------|------|-------| +| File (new) | `modules/postcard/sitename_test.go` | Tasks 1, 2 | +| Test | `TestSiteNameSend` | modules/postcard/sitename_test.go (Task 1) | +| Test | `TestUnsafeSiteNameDropped` | modules/postcard/sitename_test.go (Task 1) | +| Test | `TestUnsafeText` | modules/postcard/sitename_test.go (Task 1) | +| Test | `TestFooterSiteNameLiteral` | modules/postcard/sitename_test.go (Task 2) | +| File (new) | `modules/postcard/safety_test.go` | Task 2 | +| Test | `TestURLSchemeCheck` | modules/postcard/safety_test.go (Task 2) | +| Test | `TestInlineUnsafeOutput` | modules/postcard/safety_test.go (Task 2) | +| File (new) | `modules/cabana/mail_site_name_postgres_test.go` | Task 3 | +| Test | `TestMailSiteNameSafety` with subtests `refused_on_save`, `prose_names_saved`, `preview_drops_unsafe_name`, `stored_unsafe_name_saves`, `stored_unsafe_name_send`, `mail_from_prose_name` | modules/cabana/mail_site_name_postgres_test.go (Task 3) | +| Gate entries | GO_TESTS: `./modules/postcard:` TestMailSafetySmoke, TestSiteNameSend, TestUnsafeSiteNameDropped, TestUnsafeText, TestURLSchemeCheck, TestInlineUnsafeOutput, TestFooterSiteNameLiteral; DOCKER_TESTS: `./modules/cabana:TestMailSiteNameSafety` | scripts/check-phase35.sh (Tasks 1-3) | +| Gate fix | `self_test_consumers` workspace-modfile case compares the planted consumer's go.mod with `cmp -s` (IN-03) | scripts/check-phase35.sh (Task 3) | +| Planning doc | 35-VALIDATION.md CR-01, WR-01, WR-05 rows, "CR-01 status" line, Manual-Only row for the Branding refusal, Wave 0 entries | Task 3, last commit | + +## Follow-ups outside this plan (not planned here) + +- `/msd-verify-work 35`: re-verification of the CR-01 gap, then the pending human items of 35-VERIFICATION.md. +- Plugin follow-up after the framework tag (sm-user-plugin, sm-paymentgateway-plugin), unchanged from 35-06/35-07. +- 35-REVIEW.md advisories WR-02, WR-03, WR-04, IN-01, IN-02, IN-04 stay outside this gap closure.