@@ -1332,6 +1332,13 @@ sub esc_url {
13321332 return $str ;
13331333}
13341334
1335+ # quote unsafe characters in HTML attributes
1336+ sub esc_attr {
1337+
1338+ # for XHTML conformance escaping '"' to '"' is not enough
1339+ return esc_html(@_ );
1340+ }
1341+
13351342# replace invalid utf8 character with SUBSTITUTION sequence
13361343sub esc_html {
13371344 my $str = shift ;
@@ -1737,7 +1744,7 @@ sub format_ref_marker {
17371744 hash => $dest
17381745 )}, $name );
17391746
1740- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1747+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
17411748 $link . " </span>" ;
17421749 }
17431750 }
@@ -1821,7 +1828,7 @@ sub git_get_avatar {
18211828 return $pre_white .
18221829 " <img width=\" $size \" " .
18231830 " class=\" avatar\" " .
1824- " src=\" $url \" " .
1831+ " src=\" " .esc_url( $url ). " \" " .
18251832 " alt=\"\" " .
18261833 " />" . $post_white ;
18271834 } else {
@@ -2532,7 +2539,7 @@ sub git_show_project_tagcloud {
25322539 } else {
25332540 my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
25342541 return ' <p align="center">' . join (' , ' , map {
2535- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2542+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
25362543 } splice (@tags , 0, $count )) . ' </p>' ;
25372544 }
25382545}
@@ -3429,11 +3436,11 @@ sub git_header_html {
34293436 # print out each stylesheet that exist, providing backwards capability
34303437 # for those people who defined $stylesheet in a config file
34313438 if (defined $stylesheet ) {
3432- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3439+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
34333440 } else {
34343441 foreach my $stylesheet (@stylesheets ) {
34353442 next unless $stylesheet ;
3436- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3443+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
34373444 }
34383445 }
34393446 if (defined $project ) {
@@ -3446,7 +3453,7 @@ sub git_header_html {
34463453 my $type = lc ($format );
34473454 my %link_attr = (
34483455 ' -rel' => ' alternate' ,
3449- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3456+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
34503457 ' -type' => " application/$type +xml"
34513458 );
34523459
@@ -3473,13 +3480,13 @@ sub git_header_html {
34733480 } else {
34743481 printf (' <link rel="alternate" title="%s projects list" ' .
34753482 ' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3476- $site_name , href(project => undef , action => " project_index" ));
3483+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
34773484 printf (' <link rel="alternate" title="%s projects feeds" ' .
34783485 ' href="%s" type="text/x-opml" />' ." \n " ,
3479- $site_name , href(project => undef , action => " opml" ));
3486+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
34803487 }
34813488 if (defined $favicon ) {
3482- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3489+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
34833490 }
34843491
34853492 print " </head>\n " .
@@ -3492,7 +3499,7 @@ sub git_header_html {
34923499 print " <div class=\" page_header\" >\n " .
34933500 $cgi -> a({-href => esc_url($logo_url ),
34943501 -title => $logo_label },
3495- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3502+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
34963503 print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
34973504 if (defined $project ) {
34983505 print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3590,7 +3597,7 @@ sub git_footer_html {
35903597 insert_file($site_footer );
35913598 }
35923599
3593- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3600+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
35943601 if (defined $action &&
35953602 $action eq ' blame_incremental' ) {
35963603 print qq! <script type="text/javascript">\n ! .
@@ -5610,14 +5617,14 @@ sub git_blob {
56105617 } else {
56115618 print " <div class=\" page_nav\" >\n " .
56125619 " <br/><br/></div>\n " .
5613- " <div class=\" title\" >$hash </div>\n " ;
5620+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
56145621 }
56155622 git_print_page_path($file_name , " blob" , $hash_base );
56165623 print " <div class=\" page_body\" >\n " ;
56175624 if ($mimetype =~ m ! ^image/! ) {
5618- print qq! <img type="$mimetype "! ;
5625+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
56195626 if ($file_name ) {
5620- print qq! alt="$file_name " title="$file_name "! ;
5627+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
56215628 }
56225629 print qq! src="! .
56235630 href(action => " blob_plain" , hash => $hash ,
@@ -5630,7 +5637,7 @@ sub git_blob {
56305637 $nr ++;
56315638 $line = untabify($line );
56325639 printf qq! <div class="pre"><a id="l%i " href="%s #l%i " class="linenr">%4i</a> %s </div>\n ! ,
5633- $nr , href(-replay => 1), $nr , $nr , $syntax ? $line : esc_html($line , -nbsp => 1);
5640+ $nr , esc_attr( href(-replay => 1) ), $nr , $nr , $syntax ? $line : esc_html($line , -nbsp => 1);
56345641 }
56355642 }
56365643 close $fd
@@ -5692,7 +5699,7 @@ sub git_tree {
56925699 undef $hash_base ;
56935700 print " <div class=\" page_nav\" >\n " ;
56945701 print " <br/><br/></div>\n " ;
5695- print " <div class=\" title\" >$hash </div>\n " ;
5702+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
56965703 }
56975704 if (defined $file_name ) {
56985705 $basedir = $file_name ;
@@ -6160,7 +6167,7 @@ sub git_blobdiff {
61606167 git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
61616168 } else {
61626169 print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
6163- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
6170+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
61646171 }
61656172 if (defined $file_name ) {
61666173 git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments