@@ -1097,6 +1097,13 @@ sub esc_url {
10971097 return $str ;
10981098}
10991099
1100+ # quote unsafe characters in HTML attributes
1101+ sub esc_attr {
1102+
1103+ # for XHTML conformance escaping '"' to '"' is not enough
1104+ return esc_html(@_ );
1105+ }
1106+
11001107# replace invalid utf8 character with SUBSTITUTION sequence
11011108sub esc_html {
11021109 my $str = shift ;
@@ -1502,7 +1509,7 @@ sub format_ref_marker {
15021509 hash => $dest
15031510 )}, $name );
15041511
1505- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1512+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
15061513 $link . " </span>" ;
15071514 }
15081515 }
@@ -1586,7 +1593,7 @@ sub git_get_avatar {
15861593 return $pre_white .
15871594 " <img width=\" $size \" " .
15881595 " class=\" avatar\" " .
1589- " src=\" $url \" " .
1596+ " src=\" " .esc_url( $url ). " \" " .
15901597 " alt=\"\" " .
15911598 " />" . $post_white ;
15921599 } else {
@@ -2258,7 +2265,7 @@ sub git_show_project_tagcloud {
22582265 } else {
22592266 my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
22602267 return ' <p align="center">' . join (' , ' , map {
2261- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2268+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
22622269 } splice (@tags , 0, $count )) . ' </p>' ;
22632270 }
22642271}
@@ -3074,11 +3081,11 @@ sub git_header_html {
30743081 # print out each stylesheet that exist, providing backwards capability
30753082 # for those people who defined $stylesheet in a config file
30763083 if (defined $stylesheet ) {
3077- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3084+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
30783085 } else {
30793086 foreach my $stylesheet (@stylesheets ) {
30803087 next unless $stylesheet ;
3081- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3088+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
30823089 }
30833090 }
30843091 if (defined $project ) {
@@ -3091,7 +3098,7 @@ sub git_header_html {
30913098 my $type = lc ($format );
30923099 my %link_attr = (
30933100 ' -rel' => ' alternate' ,
3094- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3101+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
30953102 ' -type' => " application/$type +xml"
30963103 );
30973104
@@ -3118,13 +3125,13 @@ sub git_header_html {
31183125 } else {
31193126 printf (' <link rel="alternate" title="%s projects list" ' .
31203127 ' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3121- $site_name , href(project => undef , action => " project_index" ));
3128+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
31223129 printf (' <link rel="alternate" title="%s projects feeds" ' .
31233130 ' href="%s" type="text/x-opml" />' ." \n " ,
3124- $site_name , href(project => undef , action => " opml" ));
3131+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
31253132 }
31263133 if (defined $favicon ) {
3127- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3134+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
31283135 }
31293136
31303137 print " </head>\n " .
@@ -3137,7 +3144,7 @@ sub git_header_html {
31373144 print " <div class=\" page_header\" >\n " .
31383145 $cgi -> a({-href => esc_url($logo_url ),
31393146 -title => $logo_label },
3140- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3147+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
31413148 print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
31423149 if (defined $project ) {
31433150 print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -5045,14 +5052,14 @@ sub git_blob {
50455052 } else {
50465053 print " <div class=\" page_nav\" >\n " .
50475054 " <br/><br/></div>\n " .
5048- " <div class=\" title\" >$hash </div>\n " ;
5055+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
50495056 }
50505057 git_print_page_path($file_name , " blob" , $hash_base );
50515058 print " <div class=\" page_body\" >\n " ;
50525059 if ($mimetype =~ m ! ^image/! ) {
5053- print qq! <img type="$mimetype "! ;
5060+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
50545061 if ($file_name ) {
5055- print qq! alt="$file_name " title="$file_name "! ;
5062+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
50565063 }
50575064 print qq! src="! .
50585065 href(action => " blob_plain" , hash => $hash ,
@@ -5064,7 +5071,8 @@ sub git_blob {
50645071 chomp $line ;
50655072 $nr ++;
50665073 $line = untabify($line );
5067- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5074+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5075+ . esc_attr(href(-replay => 1))
50685076 . " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
50695077 $nr , $nr , $nr , esc_html($line , -nbsp => 1);
50705078 }
@@ -5124,7 +5132,7 @@ sub git_tree {
51245132 undef $hash_base ;
51255133 print " <div class=\" page_nav\" >\n " ;
51265134 print " <br/><br/></div>\n " ;
5127- print " <div class=\" title\" >$hash </div>\n " ;
5135+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
51285136 }
51295137 if (defined $file_name ) {
51305138 $basedir = $file_name ;
@@ -5543,7 +5551,7 @@ sub git_blobdiff {
55435551 git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
55445552 } else {
55455553 print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5546- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5554+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
55475555 }
55485556 if (defined $file_name ) {
55495557 git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments