Karta. Mail. SafeHTML
(Karta v1.0.0)
The HTML of a message, made safe to show in the admin interface: nothing in the result runs, and nothing in it is loaded from anywhere else.
The admin interface shows the result in a sandboxed frame under a strict content security policy; this module is the first line, so that nothing remote is even requested and the frame's other defences are never needed.
The document is parsed as a browser parses it (LazyHTML, an HTML5
parser), then written again from what is kept:
- Elements on a list of harmless ones (text, tables, lists,
headings,
img,style, ...) are kept. Elements that run, load, embed or submit something (script,iframe,object,link,meta,base,formcontrols,svg,math,template, media, ...) are removed with their content. Any other element (form,noscript, vendor tags such aso:p, custom elements) is replaced by its content. Comments are removed. - Attributes on a list of harmless ones are kept (
style,class,align,width,bgcolor,alt,title, ...); all others, event handlers included, are removed.background,srcset,posterand every other attribute that names a resource are not on the list. - Links do not navigate: an
hrefofhttp:,https:ormailto:becomes the link'stitle, so that it can still be read; everyhrefis removed. - Images keep
srconly fordata:URIs of PNG, GIF, JPEG and WebP images, and forcid:references to the message's own images, whichinlineturns intodata:URIs (at most 2 MiB of them in all). Any othersrcis removed. - CSS (
styleattributes and elements) loses its comments, its backslash escapes and every<;@importis removed,url()keeps onlydata:URIs of the image types above, andimage(),image-set(),cross-fade(),element(),src()andexpression()are made invalid.
The result is a whole document (<!DOCTYPE html>, UTF-8).
Summary
Functions
CSS made unable to load anything: comments, backslash escapes, < and
@import removed, url() kept only for data: images, other functions
that load images made invalid.
The safe document for html; inline finds the images cid: URLs name.
Types
Functions
CSS made unable to load anything: comments, backslash escapes, < and
@import removed, url() kept only for data: images, other functions
that load images made invalid.
The safe document for html; inline finds the images cid: URLs name.