@@ -1097,6 +1097,13 @@ sub esc_url {
1097
1097
return $str ;
1098
1098
}
1099
1099
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
+
1100
1107
# replace invalid utf8 character with SUBSTITUTION sequence
1101
1108
sub esc_html {
1102
1109
my $str = shift ;
@@ -1502,7 +1509,7 @@ sub format_ref_marker {
1502
1509
hash => $dest
1503
1510
)}, $name );
1504
1511
1505
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1512
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1506
1513
$link . " </span>" ;
1507
1514
}
1508
1515
}
@@ -1586,7 +1593,7 @@ sub git_get_avatar {
1586
1593
return $pre_white .
1587
1594
" <img width=\" $size \" " .
1588
1595
" class=\" avatar\" " .
1589
- " src=\" $url \" " .
1596
+ " src=\" " .esc_url( $url ). " \" " .
1590
1597
" alt=\"\" " .
1591
1598
" />" . $post_white ;
1592
1599
} else {
@@ -2258,7 +2265,7 @@ sub git_show_project_tagcloud {
2258
2265
} else {
2259
2266
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2260
2267
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 })
2262
2269
} splice (@tags , 0, $count )) . ' </p>' ;
2263
2270
}
2264
2271
}
@@ -3074,11 +3081,11 @@ sub git_header_html {
3074
3081
# print out each stylesheet that exist, providing backwards capability
3075
3082
# for those people who defined $stylesheet in a config file
3076
3083
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 " ;
3078
3085
} else {
3079
3086
foreach my $stylesheet (@stylesheets ) {
3080
3087
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 " ;
3082
3089
}
3083
3090
}
3084
3091
if (defined $project ) {
@@ -3091,7 +3098,7 @@ sub git_header_html {
3091
3098
my $type = lc ($format );
3092
3099
my %link_attr = (
3093
3100
' -rel' => ' alternate' ,
3094
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3101
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3095
3102
' -type' => " application/$type +xml"
3096
3103
);
3097
3104
@@ -3118,13 +3125,13 @@ sub git_header_html {
3118
3125
} else {
3119
3126
printf (' <link rel="alternate" title="%s projects list" ' .
3120
3127
' 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" ));
3122
3129
printf (' <link rel="alternate" title="%s projects feeds" ' .
3123
3130
' 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" ));
3125
3132
}
3126
3133
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 ) ;
3128
3135
}
3129
3136
3130
3137
print " </head>\n " .
@@ -3137,7 +3144,7 @@ sub git_header_html {
3137
3144
print " <div class=\" page_header\" >\n " .
3138
3145
$cgi -> a({-href => esc_url($logo_url ),
3139
3146
-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"/>) );
3141
3148
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3142
3149
if (defined $project ) {
3143
3150
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -5045,14 +5052,14 @@ sub git_blob {
5045
5052
} else {
5046
5053
print " <div class=\" page_nav\" >\n " .
5047
5054
" <br/><br/></div>\n " .
5048
- " <div class=\" title\" >$hash </div>\n " ;
5055
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5049
5056
}
5050
5057
git_print_page_path($file_name , " blob" , $hash_base );
5051
5058
print " <div class=\" page_body\" >\n " ;
5052
5059
if ($mimetype =~ m ! ^image/! ) {
5053
- print qq! <img type="$mimetype "! ;
5060
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5054
5061
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! "! ;
5056
5063
}
5057
5064
print qq! src="! .
5058
5065
href(action => " blob_plain" , hash => $hash ,
@@ -5064,7 +5071,8 @@ sub git_blob {
5064
5071
chomp $line ;
5065
5072
$nr ++;
5066
5073
$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))
5068
5076
. " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
5069
5077
$nr , $nr , $nr , esc_html($line , -nbsp => 1);
5070
5078
}
@@ -5124,7 +5132,7 @@ sub git_tree {
5124
5132
undef $hash_base ;
5125
5133
print " <div class=\" page_nav\" >\n " ;
5126
5134
print " <br/><br/></div>\n " ;
5127
- print " <div class=\" title\" >$hash </div>\n " ;
5135
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5128
5136
}
5129
5137
if (defined $file_name ) {
5130
5138
$basedir = $file_name ;
@@ -5543,7 +5551,7 @@ sub git_blobdiff {
5543
5551
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
5544
5552
} else {
5545
5553
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 " ;
5547
5555
}
5548
5556
if (defined $file_name ) {
5549
5557
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments