Skip to content

Commit

Permalink
Bug 968576: [SECURITY] Dangerous control characters allowed in Bugzil…
Browse files Browse the repository at this point in the history
…la text

r=glob a=justdave
  • Loading branch information
Manishearth authored and LpSolit committed Apr 17, 2014
1 parent 2f385c1 commit d3d080f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Bugzilla/Template.pm
Expand Up @@ -645,6 +645,17 @@ sub create {
my ($data) = @_;
return encode_base64($data);
},

# Strips out control characters excepting whitespace
strip_control_chars => sub {
my ($data) = @_;
# Only run for utf8 to avoid issues with other multibyte encodings
# that may be reassigning meaning to ascii characters.
if (Bugzilla->params->{'utf8'}) {
$data =~ s/(?![\t\r\n])[[:cntrl:]]//g;
}
return $data;
},

# HTML collapses newlines in element attributes to a single space,
# so form elements which may have whitespace (ie comments) need
Expand Down
4 changes: 4 additions & 0 deletions Bugzilla/Util.pm
Expand Up @@ -68,6 +68,10 @@ sub html_quote {
# Obscure '@'.
$var =~ s/\@/\@/g;
if (Bugzilla->params->{'utf8'}) {
# Remove control characters if the encoding is utf8.
# Other multibyte encodings may be using this range; so ignore if not utf8.
$var =~ s/(?![\t\r\n])[[:cntrl:]]//g;

# Remove the following characters because they're
# influencing BiDi:
# --------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion template/en/default/email/bugmail.txt.tmpl
Expand Up @@ -19,7 +19,7 @@
[%- IF comment.count %]
--- Comment #[% comment.count %] from [% comment.author.identity %] ---
[% END %]
[%+ comment.body_full({ is_bugmail => 1, wrap => 1 }) %]
[%+ comment.body_full({ is_bugmail => 1, wrap => 1 }) FILTER strip_control_chars %]
[% END %]

-- [%# Protect the trailing space of the signature marker %]
Expand Down
2 changes: 1 addition & 1 deletion template/en/default/email/flagmail.txt.tmpl
Expand Up @@ -68,7 +68,7 @@ Attachment [% attidsummary %]
[%-# .defined is necessary to avoid a taint issue in Perl < 5.10.1, see bug 509794. %]
[% IF Bugzilla.cgi.param("comment").defined && Bugzilla.cgi.param("comment").length > 0 %]
------- Additional Comments from [% user.identity %]
[%+ Bugzilla.cgi.param("comment") %]
[%+ Bugzilla.cgi.param("comment") FILTER strip_control_chars %]
[% END %]

[%- END %]

0 comments on commit d3d080f

Please sign in to comment.