fix(postcard): check URL schemes in decoded attribute values, not in text
- validateHTML keeps the raw tag and handler regexes and reads the rest through unsafeMarkup: x/net/html tokenizer, decoded attribute values, prefix check on URL attributes, whole-value check on CSS, list attributes, meta content and comments; any on* attribute is refused - text is not a URL: "Metadata: Weekly" or "Big Data: Summit" as a site name or body text no longer stops a send (CR-01) - entity-encoded javascript: is refused whether or not the layout opts out of inlining (WR-05) - draft layout CSS is checked as a style element - fixtures that pinned prose as unsafe now carry markup-level URLs; the 35-07 subtest pinning an unsafe stored name is removed - TestMailSafetySmoke prose_site_name and encoded_scheme
This commit is contained in:
@@ -153,7 +153,7 @@ fmt.Println(err != nil, len(driver.Messages()))
|
||||
|
||||
postcard does not pick a locale: the caller passes the full name. A per-language version of a template is a file named after the template, a dash and the locale (`welcome-en.htm`, sent as `acme.blog::mail.welcome-en`). A name with its own file always renders that file. A name the catalog does not hold, of the form `<template>-<locale>` where `<template>` is registered and `<locale>` is a locale tag (two letters, optionally followed by `-` or `_` and a 2 to 8 character subtag, such as `de` or `pt-BR`), sends the default-locale version: the locale's own version when an administrator customized it, else the customized template, else the template's file. Any other unknown name fails with `postcard: unknown template <name>`. So a plugin can pass `<template>-<locale>` for every locale it serves, and a locale without a file still sends mail, in the default language until someone writes that locale's version in the admin.
|
||||
|
||||
Before a driver sees a message, postcard refuses a subject or address with a line break, parses every address with `net/mail`, and rejects rendered HTML that contains script, iframe, object or embed tags, inline event handlers, or `javascript:`, `vbscript:` or `data:` URLs. Variables are escaped by Go's `html/template`.
|
||||
Before a driver sees a message, postcard refuses a subject or address with a line break, parses every address with `net/mail`, and rejects rendered HTML that contains script, iframe, object or embed tags, inline event handlers, or `javascript:`, `vbscript:` or `data:` URLs. URLs are looked for where a mail client reads one: URL-bearing attributes such as `href` and `src`, `style` attributes, style elements, comments and `meta` content, after character references are decoded, so `href="javascript:..."` is refused. Text is not a URL: a body or a site name such as `metadata:` or `Big Data: Summit` is sent. Variables are escaped by Go's `html/template`.
|
||||
|
||||
`postcard.Mailer.Send` delivers before it returns. To keep a request fast, send from a queued job, and send after the write that triggered the mail has committed; see [Queued jobs](jobs.md) and [Transactions](../database/transactions.md).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user