Skip to content

Commit 14afe77

Browse files
jnarebgitster
authored andcommitted
gitweb: Sanitize title attribute in format_subject_html
Replace control characters with question mark '?' (like in chop_and_esc_str). A little background: some web browsers turn on strict (and unforgiving) XML validating mode for XHTML documents served using application/xhtml+xml content type. This means among others that control characters are forbidden to appear in gitweb output. CGI.pm does by default slight escaping (using simple_escape subroutine from CGI::Util) of all _attribute_ values (depending on the value of autoEscape, by default on). This escaping, at least in CGI.pm version 3.10 (most current version at CPAN is 3.43), is minimal: only '"', '&', '<' and '>' are escaped using named HTML entity references (&quot;, &amp;, &lt; and &gt; respectively). But simple_escape does not do escaping of control characters such as ^X which are invalid in XHTML (in strict mode). If by some accident commit message do contain some control character in first 50 characters (more or less) of first line of commit message, and this line is longer than 50 characters (so gitweb shortens it for display), then gitweb would put this control character in title attribute (and CGI.pm would not remove them). The tag _contents_ is safe because it is escaped using esc_html() explicitly, and it replaces control characters by their printable representation. While at it: chop_and_escape_str doesn't need capturing group. Noticed-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a80aad7 commit 14afe77

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

gitweb/gitweb.perl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ sub chop_and_escape_str {
12351235
if ($chopped eq $str) {
12361236
return esc_html($chopped);
12371237
} else {
1238-
$str =~ s/([[:cntrl:]])/?/g;
1238+
$str =~ s/[[:cntrl:]]/?/g;
12391239
return $cgi->span({-title=>$str}, esc_html($chopped));
12401240
}
12411241
}
@@ -1458,6 +1458,7 @@ sub format_subject_html {
14581458
$extra = '' unless defined($extra);
14591459

14601460
if (length($short) < length($long)) {
1461+
$long =~ s/[[:cntrl:]]/?/g;
14611462
return $cgi->a({-href => $href, -class => "list subject",
14621463
-title => to_utf8($long)},
14631464
esc_html($short) . $extra);

0 commit comments

Comments
 (0)