@@ -1176,6 +1176,13 @@ sub esc_url {
1176
1176
return $str ;
1177
1177
}
1178
1178
1179
+ # quote unsafe characters in HTML attributes
1180
+ sub esc_attr {
1181
+
1182
+ # for XHTML conformance escaping '"' to '"' is not enough
1183
+ return esc_html(@_ );
1184
+ }
1185
+
1179
1186
# replace invalid utf8 character with SUBSTITUTION sequence
1180
1187
sub esc_html {
1181
1188
my $str = shift ;
@@ -1577,7 +1584,7 @@ sub format_ref_marker {
1577
1584
hash => $dest
1578
1585
)}, $name );
1579
1586
1580
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1587
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1581
1588
$link . " </span>" ;
1582
1589
}
1583
1590
}
@@ -1661,7 +1668,7 @@ sub git_get_avatar {
1661
1668
return $pre_white .
1662
1669
" <img width=\" $size \" " .
1663
1670
" class=\" avatar\" " .
1664
- " src=\" $url \" " .
1671
+ " src=\" " .esc_url( $url ). " \" " .
1665
1672
" alt=\"\" " .
1666
1673
" />" . $post_white ;
1667
1674
} else {
@@ -2372,7 +2379,7 @@ sub git_show_project_tagcloud {
2372
2379
} else {
2373
2380
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2374
2381
return ' <p align="center">' . join (' , ' , map {
2375
- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2382
+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
2376
2383
} splice (@tags , 0, $count )) . ' </p>' ;
2377
2384
}
2378
2385
}
@@ -3203,11 +3210,11 @@ sub git_header_html {
3203
3210
# print out each stylesheet that exist, providing backwards capability
3204
3211
# for those people who defined $stylesheet in a config file
3205
3212
if (defined $stylesheet ) {
3206
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3213
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3207
3214
} else {
3208
3215
foreach my $stylesheet (@stylesheets ) {
3209
3216
next unless $stylesheet ;
3210
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3217
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3211
3218
}
3212
3219
}
3213
3220
if (defined $project ) {
@@ -3220,7 +3227,7 @@ sub git_header_html {
3220
3227
my $type = lc ($format );
3221
3228
my %link_attr = (
3222
3229
' -rel' => ' alternate' ,
3223
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3230
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3224
3231
' -type' => " application/$type +xml"
3225
3232
);
3226
3233
@@ -3247,13 +3254,13 @@ sub git_header_html {
3247
3254
} else {
3248
3255
printf (' <link rel="alternate" title="%s projects list" ' .
3249
3256
' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3250
- $site_name , href(project => undef , action => " project_index" ));
3257
+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
3251
3258
printf (' <link rel="alternate" title="%s projects feeds" ' .
3252
3259
' href="%s" type="text/x-opml" />' ." \n " ,
3253
- $site_name , href(project => undef , action => " opml" ));
3260
+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
3254
3261
}
3255
3262
if (defined $favicon ) {
3256
- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3263
+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
3257
3264
}
3258
3265
3259
3266
print " </head>\n " .
@@ -3266,7 +3273,7 @@ sub git_header_html {
3266
3273
print " <div class=\" page_header\" >\n " .
3267
3274
$cgi -> a({-href => esc_url($logo_url ),
3268
3275
-title => $logo_label },
3269
- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3276
+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
3270
3277
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3271
3278
if (defined $project ) {
3272
3279
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3364,7 +3371,7 @@ sub git_footer_html {
3364
3371
insert_file($site_footer );
3365
3372
}
3366
3373
3367
- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3374
+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
3368
3375
if (defined $action &&
3369
3376
$action eq ' blame_incremental' ) {
3370
3377
print qq! <script type="text/javascript">\n ! .
@@ -5376,14 +5383,14 @@ sub git_blob {
5376
5383
} else {
5377
5384
print " <div class=\" page_nav\" >\n " .
5378
5385
" <br/><br/></div>\n " .
5379
- " <div class=\" title\" >$hash </div>\n " ;
5386
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5380
5387
}
5381
5388
git_print_page_path($file_name , " blob" , $hash_base );
5382
5389
print " <div class=\" page_body\" >\n " ;
5383
5390
if ($mimetype =~ m ! ^image/! ) {
5384
- print qq! <img type="$mimetype "! ;
5391
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5385
5392
if ($file_name ) {
5386
- print qq! alt="$file_name " title="$file_name "! ;
5393
+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
5387
5394
}
5388
5395
print qq! src="! .
5389
5396
href(action => " blob_plain" , hash => $hash ,
@@ -5395,7 +5402,8 @@ sub git_blob {
5395
5402
chomp $line ;
5396
5403
$nr ++;
5397
5404
$line = untabify($line );
5398
- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5405
+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5406
+ . esc_attr(href(-replay => 1))
5399
5407
. " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
5400
5408
$nr , $nr , $nr , esc_html($line , -nbsp => 1);
5401
5409
}
@@ -5459,7 +5467,7 @@ sub git_tree {
5459
5467
undef $hash_base ;
5460
5468
print " <div class=\" page_nav\" >\n " ;
5461
5469
print " <br/><br/></div>\n " ;
5462
- print " <div class=\" title\" >$hash </div>\n " ;
5470
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5463
5471
}
5464
5472
if (defined $file_name ) {
5465
5473
$basedir = $file_name ;
@@ -5927,7 +5935,7 @@ sub git_blobdiff {
5927
5935
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
5928
5936
} else {
5929
5937
print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5930
- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5938
+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
5931
5939
}
5932
5940
if (defined $file_name ) {
5933
5941
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments