@@ -1084,6 +1084,13 @@ sub esc_url {
1084
1084
return $str ;
1085
1085
}
1086
1086
1087
+ # quote unsafe characters in HTML attributes
1088
+ sub esc_attr {
1089
+
1090
+ # for XHTML conformance escaping '"' to '"' is not enough
1091
+ return esc_html(@_ );
1092
+ }
1093
+
1087
1094
# replace invalid utf8 character with SUBSTITUTION sequence
1088
1095
sub esc_html {
1089
1096
my $str = shift ;
@@ -1489,7 +1496,7 @@ sub format_ref_marker {
1489
1496
hash => $dest
1490
1497
)}, $name );
1491
1498
1492
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1499
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1493
1500
$link . " </span>" ;
1494
1501
}
1495
1502
}
@@ -1573,7 +1580,7 @@ sub git_get_avatar {
1573
1580
return $pre_white .
1574
1581
" <img width=\" $size \" " .
1575
1582
" class=\" avatar\" " .
1576
- " src=\" $url \" " .
1583
+ " src=\" " .esc_url( $url ). " \" " .
1577
1584
" alt=\"\" " .
1578
1585
" />" . $post_white ;
1579
1586
} else {
@@ -2245,7 +2252,7 @@ sub git_show_project_tagcloud {
2245
2252
} else {
2246
2253
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2247
2254
return ' <p align="center">' . join (' , ' , map {
2248
- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2255
+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
2249
2256
} splice (@tags , 0, $count )) . ' </p>' ;
2250
2257
}
2251
2258
}
@@ -3061,11 +3068,11 @@ sub git_header_html {
3061
3068
# print out each stylesheet that exist, providing backwards capability
3062
3069
# for those people who defined $stylesheet in a config file
3063
3070
if (defined $stylesheet ) {
3064
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3071
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3065
3072
} else {
3066
3073
foreach my $stylesheet (@stylesheets ) {
3067
3074
next unless $stylesheet ;
3068
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3075
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3069
3076
}
3070
3077
}
3071
3078
if (defined $project ) {
@@ -3078,7 +3085,7 @@ sub git_header_html {
3078
3085
my $type = lc ($format );
3079
3086
my %link_attr = (
3080
3087
' -rel' => ' alternate' ,
3081
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3088
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3082
3089
' -type' => " application/$type +xml"
3083
3090
);
3084
3091
@@ -3105,13 +3112,13 @@ sub git_header_html {
3105
3112
} else {
3106
3113
printf (' <link rel="alternate" title="%s projects list" ' .
3107
3114
' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3108
- $site_name , href(project => undef , action => " project_index" ));
3115
+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
3109
3116
printf (' <link rel="alternate" title="%s projects feeds" ' .
3110
3117
' href="%s" type="text/x-opml" />' ." \n " ,
3111
- $site_name , href(project => undef , action => " opml" ));
3118
+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
3112
3119
}
3113
3120
if (defined $favicon ) {
3114
- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3121
+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
3115
3122
}
3116
3123
3117
3124
print " </head>\n " .
@@ -3124,7 +3131,7 @@ sub git_header_html {
3124
3131
print " <div class=\" page_header\" >\n " .
3125
3132
$cgi -> a({-href => esc_url($logo_url ),
3126
3133
-title => $logo_label },
3127
- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3134
+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
3128
3135
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3129
3136
if (defined $project ) {
3130
3137
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -5016,14 +5023,14 @@ sub git_blob {
5016
5023
} else {
5017
5024
print " <div class=\" page_nav\" >\n " .
5018
5025
" <br/><br/></div>\n " .
5019
- " <div class=\" title\" >$hash </div>\n " ;
5026
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5020
5027
}
5021
5028
git_print_page_path($file_name , " blob" , $hash_base );
5022
5029
print " <div class=\" page_body\" >\n " ;
5023
5030
if ($mimetype =~ m ! ^image/! ) {
5024
- print qq! <img type="$mimetype "! ;
5031
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5025
5032
if ($file_name ) {
5026
- print qq! alt="$file_name " title="$file_name "! ;
5033
+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
5027
5034
}
5028
5035
print qq! src="! .
5029
5036
href(action => " blob_plain" , hash => $hash ,
@@ -5094,7 +5101,7 @@ sub git_tree {
5094
5101
undef $hash_base ;
5095
5102
print " <div class=\" page_nav\" >\n " ;
5096
5103
print " <br/><br/></div>\n " ;
5097
- print " <div class=\" title\" >$hash </div>\n " ;
5104
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5098
5105
}
5099
5106
if (defined $file_name ) {
5100
5107
$basedir = $file_name ;
@@ -5511,7 +5518,7 @@ sub git_blobdiff {
5511
5518
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
5512
5519
} else {
5513
5520
print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5514
- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5521
+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
5515
5522
}
5516
5523
if (defined $file_name ) {
5517
5524
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments