@@ -1176,6 +1176,13 @@ sub esc_url {
11761176 return $str ;
11771177}
11781178
1179+ # quote unsafe characters in HTML attributes
1180+ sub esc_attr {
1181+
1182+ # for XHTML conformance escaping '"' to '"' is not enough
1183+ return esc_html(@_ );
1184+ }
1185+
11791186# replace invalid utf8 character with SUBSTITUTION sequence
11801187sub esc_html {
11811188 my $str = shift ;
@@ -1577,7 +1584,7 @@ sub format_ref_marker {
15771584 hash => $dest
15781585 )}, $name );
15791586
1580- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1587+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
15811588 $link . " </span>" ;
15821589 }
15831590 }
@@ -1661,7 +1668,7 @@ sub git_get_avatar {
16611668 return $pre_white .
16621669 " <img width=\" $size \" " .
16631670 " class=\" avatar\" " .
1664- " src=\" $url \" " .
1671+ " src=\" " .esc_url( $url ). " \" " .
16651672 " alt=\"\" " .
16661673 " />" . $post_white ;
16671674 } else {
@@ -2372,7 +2379,7 @@ sub git_show_project_tagcloud {
23722379 } else {
23732380 my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
23742381 return ' <p align="center">' . join (' , ' , map {
2375- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2382+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
23762383 } splice (@tags , 0, $count )) . ' </p>' ;
23772384 }
23782385}
@@ -3203,11 +3210,11 @@ sub git_header_html {
32033210 # print out each stylesheet that exist, providing backwards capability
32043211 # for those people who defined $stylesheet in a config file
32053212 if (defined $stylesheet ) {
3206- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3213+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
32073214 } else {
32083215 foreach my $stylesheet (@stylesheets ) {
32093216 next unless $stylesheet ;
3210- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3217+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
32113218 }
32123219 }
32133220 if (defined $project ) {
@@ -3220,7 +3227,7 @@ sub git_header_html {
32203227 my $type = lc ($format );
32213228 my %link_attr = (
32223229 ' -rel' => ' alternate' ,
3223- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3230+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
32243231 ' -type' => " application/$type +xml"
32253232 );
32263233
@@ -3247,13 +3254,13 @@ sub git_header_html {
32473254 } else {
32483255 printf (' <link rel="alternate" title="%s projects list" ' .
32493256 ' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3250- $site_name , href(project => undef , action => " project_index" ));
3257+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
32513258 printf (' <link rel="alternate" title="%s projects feeds" ' .
32523259 ' href="%s" type="text/x-opml" />' ." \n " ,
3253- $site_name , href(project => undef , action => " opml" ));
3260+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
32543261 }
32553262 if (defined $favicon ) {
3256- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3263+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
32573264 }
32583265
32593266 print " </head>\n " .
@@ -3266,7 +3273,7 @@ sub git_header_html {
32663273 print " <div class=\" page_header\" >\n " .
32673274 $cgi -> a({-href => esc_url($logo_url ),
32683275 -title => $logo_label },
3269- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3276+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
32703277 print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
32713278 if (defined $project ) {
32723279 print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3364,7 +3371,7 @@ sub git_footer_html {
33643371 insert_file($site_footer );
33653372 }
33663373
3367- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3374+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
33683375 if (defined $action &&
33693376 $action eq ' blame_incremental' ) {
33703377 print qq! <script type="text/javascript">\n ! .
@@ -5376,14 +5383,14 @@ sub git_blob {
53765383 } else {
53775384 print " <div class=\" page_nav\" >\n " .
53785385 " <br/><br/></div>\n " .
5379- " <div class=\" title\" >$hash </div>\n " ;
5386+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
53805387 }
53815388 git_print_page_path($file_name , " blob" , $hash_base );
53825389 print " <div class=\" page_body\" >\n " ;
53835390 if ($mimetype =~ m ! ^image/! ) {
5384- print qq! <img type="$mimetype "! ;
5391+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
53855392 if ($file_name ) {
5386- print qq! alt="$file_name " title="$file_name "! ;
5393+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
53875394 }
53885395 print qq! src="! .
53895396 href(action => " blob_plain" , hash => $hash ,
@@ -5395,7 +5402,8 @@ sub git_blob {
53955402 chomp $line ;
53965403 $nr ++;
53975404 $line = untabify($line );
5398- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5405+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5406+ . esc_attr(href(-replay => 1))
53995407 . " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
54005408 $nr , $nr , $nr , esc_html($line , -nbsp => 1);
54015409 }
@@ -5459,7 +5467,7 @@ sub git_tree {
54595467 undef $hash_base ;
54605468 print " <div class=\" page_nav\" >\n " ;
54615469 print " <br/><br/></div>\n " ;
5462- print " <div class=\" title\" >$hash </div>\n " ;
5470+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
54635471 }
54645472 if (defined $file_name ) {
54655473 $basedir = $file_name ;
@@ -5927,7 +5935,7 @@ sub git_blobdiff {
59275935 git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
59285936 } else {
59295937 print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5930- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5938+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
59315939 }
59325940 if (defined $file_name ) {
59335941 git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments