]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/Restrict_formats_allowed_for_comments.mdwn
Review request
[ikiwiki.git] / doc / todo / Restrict_formats_allowed_for_comments.mdwn
1 I want to write my blog posts in a convenient format (Emacs org mode)
2 but do not want commenters to be able to use this format for security
3 reasons. This patch allows to configure which formats are allowed for
4 writing comments.
5
6 Effectively, it restricts the formats enabled with add_plugin to those
7 mentioned in comments_allowformats. If this is empty, all formats are
8 allowed, which is the behavior without this patch.
9
10 The patch can be pulled from my repo ([gitweb](https://rtime.felk.cvut.cz/gitweb/sojka/ikiwiki.git/commitdiff/c42fd7d7580d081f3e3f624fd74219b0435230f6?hp=bfc9dc93c9f64a9acfff4683b69995d5a0edb0ea))
11
12     git pull git://rtime.felk.cvut.cz/sojka/ikiwiki.git restrict-comment-formats
13 ---
14
15 <pre>
16 From c42fd7d7580d081f3e3f624fd74219b0435230f6 Mon Sep 17 00:00:00 2001
17 From: Michal Sojka <sojkam1@fel.cvut.cz>
18 Date: Tue, 5 Mar 2013 10:54:51 +0100
19 Subject: [PATCH] Add configuration to restrict the formats allowed for
20  comments
21
22 I want to write my blog posts in a convenient format (Emacs org mode)
23 but do not want commenters to be able to use this format for security
24 reasons. This patch allows to configure which formats are allowed for
25 writing comments.
26
27 Effectively, it restricts the formats enabled with add_plugin to those
28 mentioned in comments_allowformats. If this is empty, all formats are
29 allowed, which is the behavior without this patch.
30 ---
31  IkiWiki/Plugin/comments.pm |   21 +++++++++++++++++++--
32  1 file changed, 19 insertions(+), 2 deletions(-)
33
34 diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
35 index 285013e..151e839 100644
36 --- a/IkiWiki/Plugin/comments.pm
37 +++ b/IkiWiki/Plugin/comments.pm
38 @@ -90,6 +90,15 @@ sub getsetup () {
39                         safe => 0,
40                         rebuild => 0,
41                 },
42 +               comments_allowformats => {
43 +                       type => 'string',
44 +                       default => '',
45 +                       example => 'mdwn txt',
46 +                       description => 'Restrict formats for comments to (no restriction if empty)',
47 +                       safe => 1,
48 +                       rebuild => 0,
49 +               },
50 +
51  }
52  
53  sub checkconfig () {
54 @@ -101,6 +110,8 @@ sub checkconfig () {
55                 unless defined $config{comments_closed_pagespec};
56         $config{comments_pagename} = 'comment_'
57                 unless defined $config{comments_pagename};
58 +       $config{comments_allowformats} = ''
59 +               unless defined $config{comments_allowformats};
60  }
61  
62  sub htmlize {
63 @@ -128,12 +139,18 @@ sub safeurl ($) {
64         }
65  }
66  
67 +sub isallowed ($) {
68 +    my $format = shift;
69 +    return ! $config{comments_allowformats} || $config{comments_allowformats} =~ /\b$format\b/;
70 +}
71 +
72  sub preprocess {
73         my %params = @_;
74         my $page = $params{page};
75  
76         my $format = $params{format};
77 -       if (defined $format && ! exists $IkiWiki::hooks{htmlize}{$format}) {
78 +       if (defined $format && (! exists $IkiWiki::hooks{htmlize}{$format} ||
79 +                               ! isallowed($format))) {
80                 error(sprintf(gettext("unsupported page format %s"), $format));
81         }
82  
83 @@ -332,7 +349,7 @@ sub editcomment ($$) {
84  
85         my @page_types;
86         if (exists $IkiWiki::hooks{htmlize}) {
87 -               foreach my $key (grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}) {
88 +               foreach my $key (grep { !/^_/ && isallowed($_) } keys %{$IkiWiki::hooks{htmlize}}) {
89                         push @page_types, [$key, $IkiWiki::hooks{htmlize}{$key}{longname} || $key];
90                 }
91         }
92 -- 
93 1.7.10.4
94
95 </pre>
96
97 [[!tag patch]]
98
99 > [[done]] --[[Joey]]