@@ -1137,6 +1137,13 @@ sub esc_url {
11371137 return $str ;
11381138}
11391139
1140+ # quote unsafe characters in HTML attributes
1141+ sub esc_attr {
1142+
1143+ # for XHTML conformance escaping '"' to '"' is not enough
1144+ return esc_html(@_ );
1145+ }
1146+
11401147# replace invalid utf8 character with SUBSTITUTION sequence
11411148sub esc_html {
11421149 my $str = shift ;
@@ -1542,7 +1549,7 @@ sub format_ref_marker {
15421549 hash => $dest
15431550 )}, $name );
15441551
1545- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1552+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
15461553 $link . " </span>" ;
15471554 }
15481555 }
@@ -1626,7 +1633,7 @@ sub git_get_avatar {
16261633 return $pre_white .
16271634 " <img width=\" $size \" " .
16281635 " class=\" avatar\" " .
1629- " src=\" $url \" " .
1636+ " src=\" " .esc_url( $url ). " \" " .
16301637 " alt=\"\" " .
16311638 " />" . $post_white ;
16321639 } else {
@@ -2335,7 +2342,7 @@ sub git_show_project_tagcloud {
23352342 } else {
23362343 my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
23372344 return ' <p align="center">' . join (' , ' , map {
2338- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2345+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
23392346 } splice (@tags , 0, $count )) . ' </p>' ;
23402347 }
23412348}
@@ -3166,11 +3173,11 @@ sub git_header_html {
31663173 # print out each stylesheet that exist, providing backwards capability
31673174 # for those people who defined $stylesheet in a config file
31683175 if (defined $stylesheet ) {
3169- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3176+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
31703177 } else {
31713178 foreach my $stylesheet (@stylesheets ) {
31723179 next unless $stylesheet ;
3173- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3180+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
31743181 }
31753182 }
31763183 if (defined $project ) {
@@ -3183,7 +3190,7 @@ sub git_header_html {
31833190 my $type = lc ($format );
31843191 my %link_attr = (
31853192 ' -rel' => ' alternate' ,
3186- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3193+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
31873194 ' -type' => " application/$type +xml"
31883195 );
31893196
@@ -3210,13 +3217,13 @@ sub git_header_html {
32103217 } else {
32113218 printf (' <link rel="alternate" title="%s projects list" ' .
32123219 ' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3213- $site_name , href(project => undef , action => " project_index" ));
3220+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
32143221 printf (' <link rel="alternate" title="%s projects feeds" ' .
32153222 ' href="%s" type="text/x-opml" />' ." \n " ,
3216- $site_name , href(project => undef , action => " opml" ));
3223+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
32173224 }
32183225 if (defined $favicon ) {
3219- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3226+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
32203227 }
32213228
32223229 print " </head>\n " .
@@ -3229,7 +3236,7 @@ sub git_header_html {
32293236 print " <div class=\" page_header\" >\n " .
32303237 $cgi -> a({-href => esc_url($logo_url ),
32313238 -title => $logo_label },
3232- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3239+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
32333240 print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
32343241 if (defined $project ) {
32353242 print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3327,7 +3334,7 @@ sub git_footer_html {
33273334 insert_file($site_footer );
33283335 }
33293336
3330- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3337+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
33313338 if ($action eq ' blame_incremental' ) {
33323339 print qq! <script type="text/javascript">\n ! .
33333340 qq! startBlame("! . href(action => " blame_data" , -replay => 1) .qq! ",\n ! .
@@ -5313,14 +5320,14 @@ sub git_blob {
53135320 } else {
53145321 print " <div class=\" page_nav\" >\n " .
53155322 " <br/><br/></div>\n " .
5316- " <div class=\" title\" >$hash </div>\n " ;
5323+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
53175324 }
53185325 git_print_page_path($file_name , " blob" , $hash_base );
53195326 print " <div class=\" page_body\" >\n " ;
53205327 if ($mimetype =~ m ! ^image/! ) {
5321- print qq! <img type="$mimetype "! ;
5328+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
53225329 if ($file_name ) {
5323- print qq! alt="$file_name " title="$file_name "! ;
5330+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
53245331 }
53255332 print qq! src="! .
53265333 href(action => " blob_plain" , hash => $hash ,
@@ -5332,7 +5339,8 @@ sub git_blob {
53325339 chomp $line ;
53335340 $nr ++;
53345341 $line = untabify($line );
5335- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5342+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5343+ . esc_attr(href(-replay => 1))
53365344 . " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
53375345 $nr , $nr , $nr , esc_html($line , -nbsp => 1);
53385346 }
@@ -5396,7 +5404,7 @@ sub git_tree {
53965404 undef $hash_base ;
53975405 print " <div class=\" page_nav\" >\n " ;
53985406 print " <br/><br/></div>\n " ;
5399- print " <div class=\" title\" >$hash </div>\n " ;
5407+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
54005408 }
54015409 if (defined $file_name ) {
54025410 $basedir = $file_name ;
@@ -5864,7 +5872,7 @@ sub git_blobdiff {
58645872 git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
58655873 } else {
58665874 print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5867- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5875+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
58685876 }
58695877 if (defined $file_name ) {
58705878 git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments