@@ -1178,6 +1178,13 @@ sub esc_url {
1178
1178
return $str ;
1179
1179
}
1180
1180
1181
+ # quote unsafe characters in HTML attributes
1182
+ sub esc_attr {
1183
+
1184
+ # for XHTML conformance escaping '"' to '"' is not enough
1185
+ return esc_html(@_ );
1186
+ }
1187
+
1181
1188
# replace invalid utf8 character with SUBSTITUTION sequence
1182
1189
sub esc_html {
1183
1190
my $str = shift ;
@@ -1583,7 +1590,7 @@ sub format_ref_marker {
1583
1590
hash => $dest
1584
1591
)}, $name );
1585
1592
1586
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1593
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1587
1594
$link . " </span>" ;
1588
1595
}
1589
1596
}
@@ -1667,7 +1674,7 @@ sub git_get_avatar {
1667
1674
return $pre_white .
1668
1675
" <img width=\" $size \" " .
1669
1676
" class=\" avatar\" " .
1670
- " src=\" $url \" " .
1677
+ " src=\" " .esc_url( $url ). " \" " .
1671
1678
" alt=\"\" " .
1672
1679
" />" . $post_white ;
1673
1680
} else {
@@ -2378,7 +2385,7 @@ sub git_show_project_tagcloud {
2378
2385
} else {
2379
2386
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2380
2387
return ' <p align="center">' . join (' , ' , map {
2381
- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2388
+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
2382
2389
} splice (@tags , 0, $count )) . ' </p>' ;
2383
2390
}
2384
2391
}
@@ -3209,11 +3216,11 @@ sub git_header_html {
3209
3216
# print out each stylesheet that exist, providing backwards capability
3210
3217
# for those people who defined $stylesheet in a config file
3211
3218
if (defined $stylesheet ) {
3212
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3219
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3213
3220
} else {
3214
3221
foreach my $stylesheet (@stylesheets ) {
3215
3222
next unless $stylesheet ;
3216
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3223
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3217
3224
}
3218
3225
}
3219
3226
if (defined $project ) {
@@ -3226,7 +3233,7 @@ sub git_header_html {
3226
3233
my $type = lc ($format );
3227
3234
my %link_attr = (
3228
3235
' -rel' => ' alternate' ,
3229
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3236
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3230
3237
' -type' => " application/$type +xml"
3231
3238
);
3232
3239
@@ -3253,13 +3260,13 @@ sub git_header_html {
3253
3260
} else {
3254
3261
printf (' <link rel="alternate" title="%s projects list" ' .
3255
3262
' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3256
- $site_name , href(project => undef , action => " project_index" ));
3263
+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
3257
3264
printf (' <link rel="alternate" title="%s projects feeds" ' .
3258
3265
' href="%s" type="text/x-opml" />' ." \n " ,
3259
- $site_name , href(project => undef , action => " opml" ));
3266
+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
3260
3267
}
3261
3268
if (defined $favicon ) {
3262
- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3269
+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
3263
3270
}
3264
3271
3265
3272
print " </head>\n " .
@@ -3272,7 +3279,7 @@ sub git_header_html {
3272
3279
print " <div class=\" page_header\" >\n " .
3273
3280
$cgi -> a({-href => esc_url($logo_url ),
3274
3281
-title => $logo_label },
3275
- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3282
+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
3276
3283
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3277
3284
if (defined $project ) {
3278
3285
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3370,7 +3377,7 @@ sub git_footer_html {
3370
3377
insert_file($site_footer );
3371
3378
}
3372
3379
3373
- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3380
+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
3374
3381
if (defined $action &&
3375
3382
$action eq ' blame_incremental' ) {
3376
3383
print qq! <script type="text/javascript">\n ! .
@@ -5382,14 +5389,14 @@ sub git_blob {
5382
5389
} else {
5383
5390
print " <div class=\" page_nav\" >\n " .
5384
5391
" <br/><br/></div>\n " .
5385
- " <div class=\" title\" >$hash </div>\n " ;
5392
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5386
5393
}
5387
5394
git_print_page_path($file_name , " blob" , $hash_base );
5388
5395
print " <div class=\" page_body\" >\n " ;
5389
5396
if ($mimetype =~ m ! ^image/! ) {
5390
- print qq! <img type="$mimetype "! ;
5397
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5391
5398
if ($file_name ) {
5392
- print qq! alt="$file_name " title="$file_name "! ;
5399
+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
5393
5400
}
5394
5401
print qq! src="! .
5395
5402
href(action => " blob_plain" , hash => $hash ,
@@ -5401,7 +5408,8 @@ sub git_blob {
5401
5408
chomp $line ;
5402
5409
$nr ++;
5403
5410
$line = untabify($line );
5404
- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5411
+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5412
+ . esc_attr(href(-replay => 1))
5405
5413
. " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
5406
5414
$nr , $nr , $nr , esc_html($line , -nbsp => 1);
5407
5415
}
@@ -5465,7 +5473,7 @@ sub git_tree {
5465
5473
undef $hash_base ;
5466
5474
print " <div class=\" page_nav\" >\n " ;
5467
5475
print " <br/><br/></div>\n " ;
5468
- print " <div class=\" title\" >$hash </div>\n " ;
5476
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5469
5477
}
5470
5478
if (defined $file_name ) {
5471
5479
$basedir = $file_name ;
@@ -5933,7 +5941,7 @@ sub git_blobdiff {
5933
5941
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
5934
5942
} else {
5935
5943
print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5936
- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5944
+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
5937
5945
}
5938
5946
if (defined $file_name ) {
5939
5947
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments