2 package IkiWiki::Plugin::htmlscrubber;
9 hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize);
12 sub sanitize (@) { #{{{
14 return scrubber()->scrub($params{content});
19 return $_scrubber if defined $_scrubber;
21 # Only known uri schemes are allowed to avoid all the ways of
22 # embedding javascrpt.
23 # List at http://en.wikipedia.org/wiki/URI_scheme
24 my $uri_schemes=join("|",
25 # IANA registered schemes
26 "http", "https", "ftp", "mailto", "file", "telnet", "gopher",
27 "aaa", "aaas", "acap", "cap", "cid", "crid",
28 "dav", "dict", "dns", "fax", "go", "h323", "im", "imap",
29 "ldap", "mid", "news", "nfs", "nntp", "pop", "pres",
30 "sip", "sips", "snmp", "tel", "urn", "wais", "xmpp",
32 # Selected unofficial schemes
33 "about", "aim", "callto", "cvs", "ed2k", "feed", "fish", "gg",
34 "irc", "ircs", "lastfm", "ldaps", "magnet", "mms",
35 "msnim", "notes", "rsync", "secondlife", "skype", "ssh",
36 "sftp", "sms", "steam", "webcal", "ymsgr",
38 # data is a special case. Allow data:image/*, but
39 # disallow data:text/javascript and everything else.
40 my $link=qr/^(?:$uri_schemes:|data:image\/|[^:]+$)/i;
42 eval q{use HTML::Scrubber};
44 # Lists based on http://feedparser.org/docs/html-sanitization.html
45 $_scrubber = HTML::Scrubber->new(
47 a abbr acronym address area b big blockquote br
48 button caption center cite code col colgroup dd del
49 dfn dir div dl dt em fieldset font form h1 h2 h3 h4
50 h5 h6 hr i img input ins kbd label legend li map
51 menu ol optgroup option p pre q s samp select small
52 span strike strong sub sup table tbody td textarea
53 tfoot th thead tr tt u ul var
55 default => [undef, { ( map { $_ => 1 } qw{
56 abbr accept accept-charset accesskey
57 align alt axis border cellpadding cellspacing
58 char charoff charset checked cite class
59 clear cols colspan color compact coords
60 datetime dir disabled enctype for frame
61 headers height hreflang hspace id ismap
62 label lang longdesc maxlength media method
63 multiple name nohref noshade nowrap prompt
64 readonly rel rev rows rowspan rules scope
65 selected shape size span start summary
66 tabindex target title type usemap valign
69 "/" => 1, # emit proper <hr /> XHTML