docs(35): re-review gap closure - CR-01 residual and scheme-check bypass found
This commit is contained in:
@@ -1,201 +1,176 @@
|
||||
---
|
||||
phase: 35-mail-templates-and-layouts-editor
|
||||
reviewed: 2026-11-13T18:30:00Z
|
||||
reviewed: 2026-11-14T15:16:46Z
|
||||
depth: standard
|
||||
scope: incremental (gap closure 35-05, 35-06, 35-07; diff 593f99ac..HEAD)
|
||||
files_reviewed: 52
|
||||
scope: re-review of gap closure 35-08 / 35-09 (diff 75669b34..HEAD), fixes for CR-01, WR-01, WR-05 of the previous report
|
||||
files_reviewed: 25
|
||||
files_reviewed_list:
|
||||
- admin/openapi/admin.json
|
||||
- admin/src/api/schema.d.ts
|
||||
- admin/src/components/form/LocaleVariantSwitcher.vue
|
||||
- admin/src/views/FormView.vue
|
||||
- admin/tests/form/FormViewMail.test.ts
|
||||
- admin/tests/form/LocaleVariantSwitcher.test.ts
|
||||
- docs/backend/forms.md
|
||||
- docs/services/mail.md
|
||||
- go.mod
|
||||
- go.sum
|
||||
- modules/cabana/README.md
|
||||
- modules/cabana/backendscreens/controllers/mailtemplates/_info.htm
|
||||
- modules/cabana/backendscreens/controllers/mailtemplates/config_filter.yaml
|
||||
- modules/cabana/backendscreens/models/mailbrandsetting/fields.yaml
|
||||
- modules/cabana/backendscreens/models/maillayout/fields.yaml
|
||||
- modules/cabana/backendscreens/models/mailtemplate/columns.yaml
|
||||
- modules/cabana/crud.go
|
||||
- modules/cabana/mail_admin.go
|
||||
- modules/cabana/mail_brand_layout_postgres_test.go
|
||||
- modules/cabana/mail_lifecycle_postgres_test.go
|
||||
- modules/cabana/mail_locale_postgres_test.go
|
||||
- modules/cabana/mail_routes.go
|
||||
- modules/cabana/mail_screens_smoke_test.go
|
||||
- modules/cabana/mail_unit_test.go
|
||||
- modules/cabana/relation_field.go
|
||||
- modules/cabana/mail_site_name_postgres_test.go
|
||||
- modules/cabana/settings.go
|
||||
- modules/phrasebook/backend/lang/en/lang.yaml
|
||||
- modules/phrasebook/backend/lang/pl/lang.yaml
|
||||
- modules/postcard/README.md
|
||||
- modules/postcard/assets/brand.css.tmpl
|
||||
- modules/postcard/assets/default.htm
|
||||
- modules/postcard/assets/minimal.htm
|
||||
- modules/postcard/assets/partials/footer.htm
|
||||
- modules/postcard/assets/partials/header.htm
|
||||
- modules/postcard/assets/system.htm
|
||||
- modules/postcard/brand.go
|
||||
- modules/postcard/brand_smoke_test.go
|
||||
- modules/postcard/brand_test.go
|
||||
- modules/postcard/editor.go
|
||||
- modules/postcard/editor_smoke_test.go
|
||||
- modules/postcard/inline.go
|
||||
- modules/postcard/inline_test.go
|
||||
- modules/postcard/layouts_test.go
|
||||
- modules/postcard/locale_postgres_test.go
|
||||
- modules/postcard/locale_test.go
|
||||
- modules/postcard/mailer.go
|
||||
- modules/postcard/mailer_test.go
|
||||
- modules/postcard/override_smoke_test.go
|
||||
- modules/postcard/override_test.go
|
||||
- modules/postcard/partials_smoke_test.go
|
||||
- modules/postcard/store.go
|
||||
- modules/postcard/safety.go
|
||||
- modules/postcard/safety_smoke_test.go
|
||||
- modules/postcard/safety_test.go
|
||||
- modules/postcard/sitename_test.go
|
||||
- modules/postcard/templates.go
|
||||
- scripts/check-phase35.sh
|
||||
findings:
|
||||
critical: 1
|
||||
warning: 5
|
||||
info: 4
|
||||
total: 10
|
||||
critical: 2
|
||||
warning: 3
|
||||
info: 3
|
||||
total: 8
|
||||
status: issues_found
|
||||
---
|
||||
|
||||
# Phase 35: Code Review Report (gap closure 35-05 / 35-06 / 35-07)
|
||||
# Phase 35: Code Review Report (re-review of gap closure 35-08 / 35-09)
|
||||
|
||||
**Reviewed:** 2026-11-13T18:30:00Z
|
||||
**Reviewed:** 2026-11-14T15:16:46Z
|
||||
**Depth:** standard
|
||||
**Files Reviewed:** 52
|
||||
**Files Reviewed:** 25
|
||||
**Status:** issues_found
|
||||
|
||||
This report supersedes the earlier 35-REVIEW.md (2026-11-13T13:39:18Z, plans 35-01..35-04). It reviews the incremental scope `593f99ac..HEAD`: one admin record per mail template with a locale switcher (postcard `TemplateFor`, `EnsureLocaleRows`, the `base_code` migration, cabana grouping, the switcher), the WinterCMS default layout with header/footer partials, `Brand.SiteName`, CSS inlining via go-premailer with a per-layout opt-out, and the 35-07 tests and `check-phase35.sh` consumer stage. Earlier findings for files outside this diff are not re-stated here.
|
||||
This report replaces the 2026-11-13 report (still in git history at `75669b34:.planning/phases/35-mail-templates-and-layouts-editor/35-REVIEW.md`). It re-reviews the gap-closure diff `75669b34..HEAD`:
|
||||
- the tokenizer-based URL-scheme check (`modules/postcard/safety.go`),
|
||||
- `postcard.UnsafeText` and the drop of unsafe site names at render time,
|
||||
- the Branding save rule,
|
||||
- the literal footer `text` argument,
|
||||
- the inliner fallback,
|
||||
- the 35-09 tests and `check-phase35.sh` gate entries.
|
||||
|
||||
Findings from the previous report for code outside this diff (WR-02, WR-03, WR-04, IN-01, IN-02, IN-04) were not part of the gap closure and are not repeated here. Spot checks show they are still open (for example `scopeTemplates` at `modules/cabana/mail_admin.go:520`, and `mailLocales` still calling `w.EnabledLocales(ctx, db)` on the request transaction at line 188).
|
||||
|
||||
Every claim below was confirmed by probe tests run through `go test -overlay` (scratch test files mapped into `modules/postcard`). No source file was changed. `go test -short ./modules/postcard ./modules/cabana` passes.
|
||||
|
||||
## Summary
|
||||
|
||||
The locale-group model is mostly consistent. Send resolution, the admin's `base_code` grouping, reset, drift stamping and the switcher agree on what a fallback-locale row is. Inlining is wrapped with panic recovery and degrades to the style block on inliner errors. The vue switcher reverts correctly on a refused navigation, and FormView is remounted per path, so variants never go stale.
|
||||
**CR-01 is only partly resolved.** The colon case is fixed: `Big Data: Summit` and `Metadata: Weekly` now render and send. Unsafe names are dropped at render, and the Branding form refuses them. But `UnsafeText` checks the name on its own, while the footer prints it after `© <year> `. A name starting with `on<letters>=`, such as `Online=Shop` or `onboarding=team`, passes `UnsafeText` and is saved. In the footer it then matches the whitespace-prefixed `eventHandler` regex, and every send on the default and system layouts fails, as in the original CR-01. This happens for a Branding name and for a `mail.from` display name alike (CR-01 below).
|
||||
|
||||
The main defect is the known site-name item. Its impact is wider than recorded. The check that fails is the unanchored `dangerousScheme` regex, so ordinary names such as "Big Data: Summit" or "Metadata: Weekly" fail it. The same name taken from `mail.from` breaks every built-in-layout send after an upgrade, with no admin action. It also blocks saving any template or layout in the admin. I confirmed this with a probe test run through a `go test -overlay` that changed no source. Other issues: the site name is rendered as Markdown in the footer. Lock ordering in the show and save transactions can deadlock. A swallowed error inside a Postgres transaction leaves it aborted. The fallback rule silently accepts typos while rejecting real 3-letter locales. The safety check runs before entity decoding, which the new opt-out now exposes.
|
||||
**The URL-scheme check can still be bypassed, without any encoding.** `x/net/html`'s tokenizer, used on its own, reads `noscript`, `title`, `textarea`, `xmp`, `noembed`, `noframes`, `plaintext` (and `style`) contents as raw text. `unsafeMarkup` only inspects raw text inside `style`. A mail client renders with scripting off, so it parses `<noscript>` content as markup. `<svg><title>` and `<svg><textarea>` are foreign elements whose children are markup. As a result:
|
||||
- `<noscript><a href="javascript:alert(1)">`, `<noscript><img src="x"/onerror=alert(1)>` and `<svg><title><a href="javascript:alert(1)">` pass `validateHTML` and are sent, with inlining on and off.
|
||||
- `values="java	script:..."` and `meta content="0;url=java	script:..."` pass, because the list, meta and CSS checks use the unstripped `dangerousScheme` (CR-02, WR-01).
|
||||
|
||||
**Ordinary text still blocks a send.** The raw `\son[a-z]+\s*=` regex still runs over the whole document. A template variable such as `Ada, buy one = get one free` fails `Send` with "rendered HTML contains event handlers". The decision note accepts this as a residual risk. The docs, however, say only event-handler attributes are refused, and the same regex is what makes CR-01 reachable (WR-02).
|
||||
|
||||
The rest of the gap closure is sound:
|
||||
- The footer `text` argument prints the name literally (WR-01 of the previous report is resolved).
|
||||
- The inliner no longer stops mail (the WR-05 contradiction is resolved).
|
||||
- The Branding refusal is localized through `localizeControllerError`.
|
||||
- The `check-phase35.sh` self-test now compares the planted consumer's `go.mod` with `cmp` (previous IN-03 resolved).
|
||||
- Every newly gated test name exists.
|
||||
|
||||
## Narrative Findings (AI reviewer)
|
||||
|
||||
## Critical Issues
|
||||
|
||||
### CR-01: Site name (Branding or mail.from display name) can stop every send on the built-in layouts and block template/layout saves
|
||||
### CR-01: A site name that `UnsafeText` accepts still stops every default/system-layout send (CR-01 residual)
|
||||
|
||||
**File:** `modules/cabana/mail_admin.go:1781-1806`, `modules/postcard/mailer.go:124,154-198`, `modules/postcard/templates.go:45`, `modules/postcard/assets/default.htm:10,28`, `modules/postcard/assets/system.htm` (same lines), `modules/postcard/assets/partials/header.htm`
|
||||
**Issue:** This confirms and widens the known open item. `siteName` is inserted into the rendered HTML (header `<span>`/`alt`, footer line). The rendered HTML then goes through `validateHTML`, whose `dangerousScheme` is `(?i)(?:javascript|vbscript|data):` with no word boundary and no attribute context. Any site name containing `data:` as a substring fails it. Verified with a probe (overlay test, no source change):
|
||||
- Branding `SiteName: "Big Data: Summit"`: `Send` of a default-layout template fails with `error calling partial: postcard: rendered HTML contains a dangerous URL scheme`.
|
||||
- No Branding, `mail.from = "\"Metadata: Weekly\" <x@example.com>"`, which is a valid address: the same failure. An application whose sender name contains `data:` stops sending all default/system-layout mail after upgrading to this phase, without anyone touching the admin.
|
||||
- With that Branding saved, `Editor.Validate` of an ordinary template draft returns `postcard: draft layout: unsafe: ...<span>Big Data: Summit</span>...`. `FormAfterUpdate` runs this validation, so every template on default/system and every layout save is refused, and the error is blamed on the Layout field.
|
||||
**File:** `modules/postcard/safety.go:25-27`, `modules/postcard/assets/default.htm:5,34`, `modules/postcard/assets/system.htm:9,39`, `modules/postcard/assets/partials/footer.htm:11`, `modules/postcard/templates.go:49,830-832`, `modules/cabana/mail_admin.go:1810`
|
||||
**Issue:** `UnsafeText(s)` runs `validateHTML(html.EscapeString(s))` on the name by itself. The only check that can fire on escaped plain text is the raw `eventHandler` regex `(?i)\son[a-z]+\s*=`, which needs whitespace before `on`. The name is trimmed (`siteNameFrom`, `BeforeValidate`), so a name that begins with `on<letters>=` has no whitespace before it and passes. The built-in layouts, however, print it as `© <year> <name>`, which adds the missing space, so the rendered footer `<p>© 2026 Online=Shop</p>` matches the regex. Probe results:
|
||||
- `UnsafeText("Online=Shop") == false`, and the same for `"onboarding=team"`. `MailBrandSetting.BeforeValidate` therefore saves the name.
|
||||
- Branding `SiteName: "Online=Shop"`: `Send` of `acme.blog::mail.welcome` (default layout) and of `acme.blog::mail.auto` (system layout) fails with `error calling partial: postcard: rendered HTML contains event handlers`. Nothing is sent.
|
||||
- No Branding, `mail.from = "\"Online=Shop\" <x@example.com>"` (a valid address): the same failure on both layouts.
|
||||
|
||||
Nothing catches this when the name is saved. `MailBrandSetting.Rules` has `site_name: nullable|max:255`, `BeforeValidate` only trims, and the Branding settings form never calls `editor.Validate`. Nothing catches it when mail is sent either. `mailer.render` builds the "file version" fallback with `m.options(ov.Brand)`, which carries the same site name, so the override-to-file fallback fails too and `Send` returns the error. Password-reset and other system mail stop.
|
||||
**Fix:** Check the name in both places. When it is saved, refuse it on the field. When mail is sent, never let a site name fail the render:
|
||||
`layoutSiteName` returns the name unchanged because `UnsafeText` accepted it. The file version and the override-failure fallback carry the same name, so the fallback fails too. All password-reset and system mail stops. The trigger can be configuration alone, with no admin action, which is exactly what CR-01 was about. The documented guarantee ("never stops a send", README Branding section; docs/services/mail.md) is false for this class of names. No test covers a name whose risk depends on where it is printed. `TestUnsafeText` only checks `"Shop onclick=x"` and `"x onload = 1"`, which already contain the space.
|
||||
**Fix:** Check the name in the context the layouts print it in, not on its own:
|
||||
```go
|
||||
// postcard: export the check so cabana can reuse it
|
||||
func UnsafeText(s string) bool { return validateHTML(html.EscapeString(s)) != nil }
|
||||
|
||||
// postcard/mailer.go siteName(): drop a name that would fail the safety check
|
||||
name := ...
|
||||
if UnsafeText(name) {
|
||||
// log once via m.warn, fall back to ""
|
||||
return ""
|
||||
}
|
||||
|
||||
// cabana MailBrandSetting.BeforeValidate
|
||||
if postcard.UnsafeText(b.SiteName) {
|
||||
details["site_name"] = []string{"backend::lang.mail.brand.site_name_unsafe"}
|
||||
func UnsafeText(s string) bool {
|
||||
esc := html.EscapeString(s)
|
||||
// The footer prints "© <year> <name>"; the header prints it in a span and an alt attribute.
|
||||
return validateHTML("<p>x "+esc+"</p><img alt=\""+esc+"\">") != nil || scriptURLText.MatchString(s)
|
||||
}
|
||||
```
|
||||
Also consider anchoring `dangerousScheme` to URL-bearing attribute values (`href|src|action|style|background`) instead of the whole document. Today any body text or variable containing `metadata:` breaks the send as well. That part predates this phase, but the site name makes it reachable from configuration alone.
|
||||
A better fix is to remove the cause (see WR-02). The tokenizer walk already refuses every attribute whose name starts with `on`, so the raw regex is redundant once raw-text elements are re-tokenized (CR-02). Dropping it makes text never match. Add `"Online=Shop"` and `"onboarding=team"` cases to `TestSiteNameSend` and `TestUnsafeSiteNameDropped`, through both a Branding name and a `mail.from` display name.
|
||||
|
||||
### CR-02: Scheme and handler checks are skipped inside raw-text elements: `<noscript>`, and `<title>`/`<textarea>`/`<style>` in SVG/MathML
|
||||
|
||||
**File:** `modules/postcard/safety.go:98-145` (only `inStyle` text is inspected, lines 128-138), `modules/postcard/templates.go:826-833`
|
||||
**Issue:** `unsafeMarkup` uses `xhtml.NewTokenizer` on its own, without the parser. The tokenizer switches to raw-text or RCDATA mode after any `iframe`, `noembed`, `noframes`, `noscript`, `plaintext`, `script`, `style`, `textarea`, `title` or `xmp` start tag (`readStartTag`). The parser would undo this for foreign content and for `noscript` with scripting off by calling `NextIsNotRawText`, but nothing calls it here. Everything inside those elements becomes one `TextToken`. Apart from `style`, that text is not checked at all, and even `style` text is checked only with the undecoded `dangerousScheme`. Mail clients parse differently:
|
||||
- They render with scripting disabled, so `<noscript>` content is parsed as ordinary markup.
|
||||
- In `<svg>`/`<math>`, `title`, `textarea`, `style`, `xmp` and similar are foreign elements, and their children are markup.
|
||||
|
||||
Probe results (each one returns `validateHTML(...) == nil`):
|
||||
- `<noscript><a href="javascript:alert(1)">x</a></noscript>` (no encoding at all)
|
||||
- `<noscript><img src="x"/onerror=alert(1)></noscript>` (the handler is not whitespace-prefixed, so the raw regex misses it, and the tokenizer never sees the attribute)
|
||||
- `<svg><title><a href="javascript:alert(1)">x</a></title></svg>`
|
||||
- `<svg><textarea><a href="javascript:alert(1)">x</a></textarea></svg>`
|
||||
- `<svg><style><a href="javascript:alert(1)">x</a></style></svg>` (the entity is not decoded in raw text)
|
||||
|
||||
A layout override whose HTML contains the `noscript` or `svg title` payload is **sent** with `javascript:alert` intact, both with `DisableAutoInlineCSS` and with inlining on. go-premailer re-serializes the raw text as is, and the post-inline check has the same blind spot. This is the WR-05 bypass again, in a simpler form, and it contradicts decision D-13 as restated in the 35-08 note ("`javascript:`, `vbscript:` and `data:` URLs are still refused at save and at send").
|
||||
**Fix:** Do not let the tokenizer hide markup:
|
||||
```go
|
||||
case xhtml.StartTagToken:
|
||||
switch t.Data {
|
||||
case "style":
|
||||
inStyle = true
|
||||
case "noscript", "title", "textarea", "xmp", "noembed", "noframes", "plaintext":
|
||||
// A mail client may parse this content as markup (scripting off, foreign content).
|
||||
z.NextIsNotRawText()
|
||||
}
|
||||
```
|
||||
`style` can be the same: call `NextIsNotRawText()` and check its CSS as text. Or re-run `unsafeMarkup` recursively on the raw text of any such element, which also covers `<svg><style>`. Alternatively, refuse `noscript`, `plaintext` and `xmp` outright in `rawUnsafeTag`, since none of them belongs in mail. Add the five payloads above to `TestURLSchemeCheck`'s `refuses` list.
|
||||
|
||||
## Warnings
|
||||
|
||||
### WR-01: Site name is interpreted as Markdown in the footer (but printed literally in the header)
|
||||
### WR-01: List-valued, `meta` content, `style` and comment checks do not strip whitespace, so `java	script:` passes
|
||||
|
||||
**File:** `modules/postcard/assets/partials/footer.htm:11`, `modules/postcard/assets/default.htm:28`, `modules/postcard/assets/system.htm` (footer call), `modules/postcard/README.md:290`
|
||||
**Issue:** The layouts build `$copy := "© <year> <siteName>"` and pass it as `body` to the `footer` partial, which renders `{{ markdown .body }}`. A probe confirmed:
|
||||
- `*Acme* Shop` becomes `© 2026 <em>Acme</em> Shop`.
|
||||
- `Acme <Studio>` becomes `© 2026 Acme <!-- raw HTML omitted -->`. The name is lost and an HTML comment is shipped in the mail.
|
||||
- `[Acme](https://evil.example)` becomes a live link in every mail.
|
||||
**File:** `modules/postcard/safety.go:122-124,136,140`
|
||||
**Issue:** Single-URL attributes go through `hasDangerousScheme`, which removes ASCII whitespace and control characters the way the URL parser does. The other URL-bearing places use `dangerousScheme.MatchString(a.Val)` on the decoded value, which does not. Probe results:
|
||||
- `<svg><a><animate attributeName="href" values="java	script:alert(1)"/>...` passes. SVG animation `values` that sets `href` is a known script-URL vector, and that is exactly why `values` is in `urlListAttributes`. A URL parser strips the tab.
|
||||
- `<meta http-equiv="refresh" content="0;url=java	script:alert(1)">` passes, although the meta case is listed as covered.
|
||||
|
||||
The header prints the same value escaped and literal, so header and footer disagree. The README states "The name is HTML-escaped by `html/template` wherever a layout prints it", which is false for the footer. The source is admin-controlled, but Markdown is not the documented contract for this field.
|
||||
**Fix:** Escape Markdown metacharacters before building `$copy`, or give the footer partial a plain-text argument for the built-in layouts. For example, add a `text` key that the partial prints as `<p>{{ .text }}</p>` and keep `markdown .body` for callers that pass Markdown on purpose. Alternatively, render the copyright `<p>` directly in the layout.
|
||||
The `from`/`to`/`by` attributes of the same animation elements are stripped and are refused, so `values` is the inconsistent one.
|
||||
**Fix:** For the list, meta and CSS cases, run `dangerousScheme` on a whitespace- and control-stripped copy of the decoded value. Factor the stripping loop out of `hasDangerousScheme` as `stripURLSpace(val string) string`, and use `dangerousScheme.MatchString(stripURLSpace(a.Val))`. This over-matches prose only in places where prose does not belong (CSS, lists, meta). Add the two payloads to the `refuses` table.
|
||||
|
||||
### WR-02: Lock-order inversion between show/save transactions and the index sync (global advisory lock taken inside request transactions)
|
||||
### WR-02: Ordinary text still blocks a send through the whole-document `eventHandler` regex
|
||||
|
||||
**File:** `modules/cabana/crud.go:562-567` (ShowRecord), `modules/cabana/crud.go:1000-1003` (save), `modules/cabana/mail_admin.go:1960-1977`, `modules/postcard/store.go:520-582`
|
||||
**Issue:** `recordLocaleVariants` runs `postcard.EnsureLocaleRows` inside the ShowRecord transaction and inside the save transaction, after the row write. `EnsureLocaleRows` takes `pg_advisory_xact_lock(syncLockKey)` and holds it until the outer request transaction ends. The savepoint does not release it. It then upserts every fallback row of the template with `ON CONFLICT DO UPDATE ... WHERE`, which row-locks each conflicting row even when nothing changes. `rows` is built from the catalog alone, so this runs on every show of a template that has a locale without a file.
|
||||
- Save tx A updates row `welcome-pl` (row lock), then waits for the advisory lock.
|
||||
- Show tx B for `welcome-de`, or `SyncIndex` from `ensureSynced`, holds the advisory lock and upserts `welcome-pl`, so it waits on A's row lock.
|
||||
**File:** `modules/postcard/templates.go:49,830-832`; docs `modules/postcard/README.md` (Features, "Safety checks"), `docs/services/mail.md` (security paragraph)
|
||||
**Issue:** `validateHTML` still runs `(?i)\son[a-z]+\s*=` over the raw document, text content included. Probe: `Send` of `acme.blog::mail.welcome` with `Name: "Ada, buy one = get one free"` returns `postcard: rendered HTML contains event handlers`, and nothing is sent. The same happens for `<p>Status: online = yes</p>`. html/template does not escape `=` in text, so any variable (order lines, user-entered names, contact-form text, code snippets with `online=1`) can stop its own message. A user who registers with such a display name never receives a password reset. The decision note lists this as an accepted residual ("out of the user's scope"). The shipped docs say something else: the README now defines handlers as "any attribute whose name starts with `on`", and docs/services/mail.md says "Text is not a URL: a body ... is sent". Neither mentions that text can be refused. This regex is also what makes CR-01 reachable.
|
||||
**Fix:** The tokenizer walk already refuses every `on*` attribute (`safety.go:119`), including the forms the regex was meant to catch. Once CR-02 is fixed and raw-text elements are tokenized, delete the raw `eventHandler` check from `validateHTML`. `editor.go` does not use it separately. If the regex must stay for now, document in both pages that text containing ` on<word>=` is refused, and add a test that pins that behaviour.
|
||||
|
||||
Postgres detects the deadlock after `deadlock_timeout`. One side's savepoint absorbs it with only a warning, or the sync fails, so it self-heals. The cost is about 1s stalls and spurious warnings. In addition, every show of a mail template, a GET, serializes on one global lock, row-locks sibling rows, and performs writes for users who only have read access.
|
||||
**Fix:** Move `EnsureLocaleRows` out of the request transaction. Run it before `ShowRecord` opens its transaction, on `m.db()`, or only from `ensureSynced`. At minimum, check for missing rows with a plain `SELECT code ... WHERE code IN ?` and call `EnsureLocaleRows` only when some are absent. Drop it from the save path entirely, because the saved row already exists there.
|
||||
### WR-03: The new `UnsafeText` rule refuses ordinary names that the docs promise are accepted
|
||||
|
||||
### WR-03: `mailLocales` swallows TranslationWriter errors while running inside a Postgres transaction
|
||||
|
||||
**File:** `modules/cabana/mail_admin.go:173-201`, called with the show/save `tx` from `mail_admin.go:1965` and through `localeInfo` (`requestDB(ctx)`, line 764 onward)
|
||||
**Issue:** The function is written as "warn and continue" (`moduleLog.WarnContext(ctx, "cabana: mail locales: enabled locales", ...)`). When `db` is a request transaction, a failing `EnabledLocales` or `DefaultLocale` SQL statement puts the whole transaction into the aborted state. Every later statement fails with "current transaction is aborted": the `EnsureLocaleRows` savepoint, then the `localeVariants` query, which returns its error. The mail template show then fails with a 500. Opening a template therefore depends on an optional plugin's tables being healthy, which is exactly the failure the code tried to tolerate.
|
||||
**Fix:** Call the writer through its own savepoint so a failure is really contained:
|
||||
```go
|
||||
_ = db.Transaction(func(sp *gorm.DB) error {
|
||||
codes, err := w.EnabledLocales(ctx, sp)
|
||||
if err != nil { return err } // rolls back to the savepoint only
|
||||
add(codes...)
|
||||
return nil
|
||||
})
|
||||
```
|
||||
Alternatively, pass `m.db()` instead of the request transaction. The value is not transactional.
|
||||
|
||||
### WR-04: Fallback-locale rule silently resolves typos, yet rejects real locales the admin offers
|
||||
|
||||
**File:** `modules/postcard/templates.go:249` (`localeTag`), `templates.go:271-291` (`fallbackLocked`), `modules/postcard/store.go:556-561`
|
||||
**Issue:** `localeTag` accepts any two letters with an optional 2-8 character subtag, independent of the application's locales. A probe confirmed:
|
||||
- `acme.blog::mail.order-ok` resolves to `order`.
|
||||
- `acme.blog::mail.order-xx-confirm` resolves to `order`, because `xx-confirm` matches.
|
||||
|
||||
A mistyped or removed template name of that shape now sends the wrong mail instead of failing with `unknown template`, and nothing is logged. In the other direction, the admin's locale set (translator plus translate plugin) can contain 3-letter ISO 639 codes (`fil`, `haw`) or multi-subtag tags (`zh-Hant-TW`). For those, `TemplateFor` fails, so `EnsureLocaleRows` silently skips them (the `!ok` branch at 559) and sends of `<template>-fil` still fail with `unknown template`. The admin gives no hint why such a locale has no version.
|
||||
**Fix:** Widen the tag to BCP 47 shape (`^[A-Za-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})*$`) so every real locale falls back. Log a rate-limited Info/Warn through `m.warn` when a send takes the fallback path, so typos are visible. Optionally, let the app register its locale list on the catalog and restrict the fallback to it.
|
||||
|
||||
### WR-05: Safety check runs on undecoded markup; the new opt-out ships what the inlined path would reject
|
||||
|
||||
**File:** `modules/postcard/templates.go:701-713` (pre-inline `validateHTML`, then `inlineHTML`), `templates.go:731-751`, `modules/postcard/README.md` (CSS inlining section), `docs/services/mail.md` ("mail is never stopped by it")
|
||||
**Issue:** go-premailer re-serializes through `x/net/html`, which decodes character references. The probe showed `javascript:x` became `javascript:x` after `inlineCSS`. As a result:
|
||||
1. The same layout or partial override that contains `href="javascript:..."` (layout HTML and partial HTML are raw template text, not escaped by html/template) passes `validateHTML` and is sent as is when `disable_auto_inline_css` is on. With inlining on, it fails the post-inline check. The new switch is effectively a bypass of the scheme check.
|
||||
2. With inlining on, the post-inline `validateHTML` failure is returned as a render error and stops the message. That contradicts the docs ("If the inliner fails on a message, that message is sent with its style block only ...; mail is never stopped by it") and turns content that passed the first check into a send failure.
|
||||
**Fix:** Validate the decoded form once, regardless of inlining. Parse with `x/net/html` (or `html.UnescapeString` on attribute values) and run the scheme and handler checks on the decoded attributes before the inline step. Keep the post-inline check only as a guard. Update both docs to say a post-inline safety failure fails the render.
|
||||
**File:** `modules/postcard/safety.go:16`, `docs/services/mail.md` (Branding paragraph), `modules/phrasebook/backend/lang/en/lang.yaml:706`
|
||||
**Issue:** `scriptURLText` treats `data:` followed by any non-space character, at a scheme boundary, as a data URL. Probe: `UnsafeText("Data:Lab")`, `UnsafeText("Big Data:Summit")` and `UnsafeText("data:Science")` are all `true`. `"JavaScript: The Good Parts Club"` is `true` as well, although a following space means it cannot be a URL (`javascript:` is matched without the `\S` requirement). The Branding save rejects these names, and an existing `mail.from` display name of this shape is silently dropped from every mail. The docs say "Ordinary text with a colon, such as `Big Data: Summit`, is accepted", and the refusal text tells the admin to "remove addresses", which these names are not. This is not a security issue: the scheme check no longer reads text, so such a name is harmless in the header and footer.
|
||||
**Fix:** Since the layouts only print the name as escaped text, which is never a URL, `scriptURLText` only guards against a name that looks like a script link to a human reader. Either drop it, or require URL shape: `data:` followed by a MIME-type-like token (`data:[a-z]+/[a-z0-9.+-]+[;,]`), and `javascript:`/`vbscript:` not followed by whitespace. Pin `"Data:Lab"` as safe in `TestUnsafeText`.
|
||||
|
||||
## Info
|
||||
|
||||
### IN-01: `scopeTemplates` is dead code after the switch to `scopeTemplateVersions`
|
||||
### IN-01: The footer partial's Markdown `body` branch is never previewed or validated in the partial editor
|
||||
|
||||
**File:** `modules/cabana/mail_admin.go:518-525`
|
||||
**Issue:** `mailTemplatesAdmin.scopeTemplates` has no callers left, in tests or otherwise. `ListExtendQuery` now uses representatives and `FormExtendQuery` uses `scopeTemplateVersions`.
|
||||
**Fix:** Delete it.
|
||||
**File:** `modules/postcard/assets/partials/footer.htm:4,11`, `modules/postcard/editor.go:293-305`
|
||||
**Issue:** `renderPartial` gives every argument the draft reads (`text` and `body`) a non-empty placeholder. With the new `{{ if .text }}...{{ else }}{{ markdown .body }}{{ end }}`, the preview and `Editor.Validate` only ever exercise the `text` branch. A broken or unsafe `markdown .body` branch in a footer override passes the save and fails only at send, for plugin layouts that still call `partial "footer" "body" ...`. Also, a footer override written against the previous contract (`{{ markdown .body }}` only) now shows an empty copyright line on the built-in layouts. That is unreleased behaviour (not in v0.6.4) and probably acceptable, but it is not called out in the README.
|
||||
**Fix:** Render the partial preview twice in the editor, once with `text` empty, or validate both branches. Mention in the README partial table that the built-in layouts pass `text`.
|
||||
|
||||
### IN-02: Fallback info line claims "Until you customize it, the default version is sent" on customized rows
|
||||
### IN-02: `settings.go` now localizes every settings model's `BeforeValidate` error
|
||||
|
||||
**File:** `modules/cabana/mail_admin.go:778-785`
|
||||
**Issue:** `localeInfo` sets `LocaleFallback` for every fallback-locale row whether or not `t.IsCustom` is set. On a customized row, the line tells the admin the default version is sent, which is false.
|
||||
**Fix:** Guard with `!t.IsCustom`, or use a second phrase for customized fallback rows ("Locale :locale has no file; your version is sent").
|
||||
**File:** `modules/cabana/settings.go:265-270`
|
||||
**Issue:** The change is right for the Branding refusal, but it changes the error of every plugin settings model. Any `ValidationError` or `ForbiddenError` detail that happens to be a phrase key is now translated, and the response is rebuilt as a new error. Behaviour for plain strings is unchanged, but the change is not mentioned in the cabana README. Core plugins (user, blog, pages, payment) depend on settings saves.
|
||||
**Fix:** Add a line to the cabana README settings section ("`BeforeValidate` refusals are localized as on a controller save") and a test with a non-mail settings model.
|
||||
|
||||
### IN-03: check-phase35.sh self-test asserts against the wrong repository
|
||||
### IN-03: CSS escape sequences bypass the CSS `data:`/`javascript:` checks (accepted residual, undocumented to users)
|
||||
|
||||
**File:** `scripts/check-phase35.sh:611`
|
||||
**Issue:** The "the modfile run wrote the planted consumer's go.mod" assertion runs `git -C "$repo" status --porcelain -- go.mod`. `$repo` is the dirty-sibling fixture, not `$consumer`, which is not a git repository at all. Only the `grep '=> ../framework' "$consumer/go.mod"` half checks anything, so a write that kept the replace line, such as an added `require`, would pass.
|
||||
**Fix:** Compare `$consumer/go.mod` against a copy taken before the run (`cmp -s`), and drop the `git -C "$repo"` clause.
|
||||
|
||||
### IN-04: Case handling differs between `EnsureLocaleRows` and send resolution; doc comment reflow
|
||||
|
||||
**File:** `modules/postcard/store.go:534,554` vs `modules/postcard/templates.go:257-268`; `modules/postcard/store.go:409`
|
||||
**Issue:** `EnsureLocaleRows` treats a file as present case-insensitively (`have[strings.ToLower(...)]`), but `resolveTemplate` looks names up case-sensitively. Take a plugin that ships `welcome-PL.htm` in an app whose locale is `pl`. No `welcome-pl` row is created because the file "exists", yet a send of `...welcome-pl` falls back to the base file instead of the PL file. Separately, the `SyncIndex` doc comment at line 409 was not reflowed and runs well past the line width.
|
||||
**Fix:** Use exact-case matching in `have` to mirror `resolveTemplate`, or make `resolveTemplate` case-insensitive for the locale suffix. Reflow the comment.
|
||||
**File:** `modules/postcard/safety.go:123,136`
|
||||
**Issue:** `<div style="background:url(d\61ta:image/png;base64,AA)">` passes. The decision note accepts this ("mail clients do not run script URLs from CSS"), but the README and docs state flatly that `data:` URLs in `style` attributes and style elements are refused.
|
||||
**Fix:** Either decode CSS escapes (`\[0-9a-f]{1,6}\s?` and `\.`) before matching, or qualify the docs sentence.
|
||||
|
||||
---
|
||||
|
||||
_Reviewed: 2026-11-13T18:30:00Z_
|
||||
_Reviewed: 2026-11-14T15:16:46Z_
|
||||
_Reviewer: Claude (msd-code-reviewer)_
|
||||
_Depth: standard_
|
||||
|
||||
Reference in New Issue
Block a user