]> Lady’s Gitweb - Gitweb/commit
gitweb: Sanitize title attribute in format_subject_html
authorJakub Narebski <redacted>
Fri, 22 May 2009 15:35:46 +0000 (17:35 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:50:38 +0000 (00:50 -0400)
commitc0530d1d0ce339e5aec27c6e72198ec3b6fcad45377f2736b800c84f8792858e
tree9fd606a4cfd716063d5b7779892f9f4267c11935a5e30f5d68dff38cc5e0e553
parentee50efd3c8a59da6863bfc9983eca8ccdd046d9e85aaf858dffc0a575d3e03a1
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 <redacted>
Signed-off-by: Jakub Narebski <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl
This page took 0.178492 seconds and 4 git commands to generate.