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 0e39097 commit 58b92d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Bugzilla/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,18 @@ sub create {
my ($data) = @_;
return encode_base64($data);
},

# Strips out control characters excepting whitespace
strip_control_chars => sub {
my ($data) = @_;
state $use_utf8 = Bugzilla->params->{'utf8'};
# Only run for utf8 to avoid issues with other multibyte encodings
# that may be reassigning meaning to ascii characters.
if ($use_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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ sub html_quote {
state $use_utf8 = Bugzilla->params->{'utf8'};

if ($use_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
Original file line number Diff line number Diff line change
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 %]

[% IF referenced_bugs.size %]
Expand Down
2 changes: 1 addition & 1 deletion template/en/default/email/flagmail.txt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Attachment [% attidsummary %]
[%-# .defined is necessary to avoid a taint issue, 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 58b92d3

Please sign in to comment.