@@ -1332,6 +1332,13 @@ sub esc_url {
1332
1332
return $str ;
1333
1333
}
1334
1334
1335
+ # quote unsafe characters in HTML attributes
1336
+ sub esc_attr {
1337
+
1338
+ # for XHTML conformance escaping '"' to '"' is not enough
1339
+ return esc_html(@_ );
1340
+ }
1341
+
1335
1342
# replace invalid utf8 character with SUBSTITUTION sequence
1336
1343
sub esc_html {
1337
1344
my $str = shift ;
@@ -1737,7 +1744,7 @@ sub format_ref_marker {
1737
1744
hash => $dest
1738
1745
)}, $name );
1739
1746
1740
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1747
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1741
1748
$link . " </span>" ;
1742
1749
}
1743
1750
}
@@ -1821,7 +1828,7 @@ sub git_get_avatar {
1821
1828
return $pre_white .
1822
1829
" <img width=\" $size \" " .
1823
1830
" class=\" avatar\" " .
1824
- " src=\" $url \" " .
1831
+ " src=\" " .esc_url( $url ). " \" " .
1825
1832
" alt=\"\" " .
1826
1833
" />" . $post_white ;
1827
1834
} else {
@@ -2532,7 +2539,7 @@ sub git_show_project_tagcloud {
2532
2539
} else {
2533
2540
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2534
2541
return ' <p align="center">' . join (' , ' , map {
2535
- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2542
+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
2536
2543
} splice (@tags , 0, $count )) . ' </p>' ;
2537
2544
}
2538
2545
}
@@ -3429,11 +3436,11 @@ sub git_header_html {
3429
3436
# print out each stylesheet that exist, providing backwards capability
3430
3437
# for those people who defined $stylesheet in a config file
3431
3438
if (defined $stylesheet ) {
3432
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3439
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3433
3440
} else {
3434
3441
foreach my $stylesheet (@stylesheets ) {
3435
3442
next unless $stylesheet ;
3436
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3443
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3437
3444
}
3438
3445
}
3439
3446
if (defined $project ) {
@@ -3446,7 +3453,7 @@ sub git_header_html {
3446
3453
my $type = lc ($format );
3447
3454
my %link_attr = (
3448
3455
' -rel' => ' alternate' ,
3449
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3456
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3450
3457
' -type' => " application/$type +xml"
3451
3458
);
3452
3459
@@ -3473,13 +3480,13 @@ sub git_header_html {
3473
3480
} else {
3474
3481
printf (' <link rel="alternate" title="%s projects list" ' .
3475
3482
' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3476
- $site_name , href(project => undef , action => " project_index" ));
3483
+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
3477
3484
printf (' <link rel="alternate" title="%s projects feeds" ' .
3478
3485
' href="%s" type="text/x-opml" />' ." \n " ,
3479
- $site_name , href(project => undef , action => " opml" ));
3486
+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
3480
3487
}
3481
3488
if (defined $favicon ) {
3482
- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3489
+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
3483
3490
}
3484
3491
3485
3492
print " </head>\n " .
@@ -3492,7 +3499,7 @@ sub git_header_html {
3492
3499
print " <div class=\" page_header\" >\n " .
3493
3500
$cgi -> a({-href => esc_url($logo_url ),
3494
3501
-title => $logo_label },
3495
- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3502
+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
3496
3503
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3497
3504
if (defined $project ) {
3498
3505
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3590,7 +3597,7 @@ sub git_footer_html {
3590
3597
insert_file($site_footer );
3591
3598
}
3592
3599
3593
- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3600
+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
3594
3601
if (defined $action &&
3595
3602
$action eq ' blame_incremental' ) {
3596
3603
print qq! <script type="text/javascript">\n ! .
@@ -5610,14 +5617,14 @@ sub git_blob {
5610
5617
} else {
5611
5618
print " <div class=\" page_nav\" >\n " .
5612
5619
" <br/><br/></div>\n " .
5613
- " <div class=\" title\" >$hash </div>\n " ;
5620
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5614
5621
}
5615
5622
git_print_page_path($file_name , " blob" , $hash_base );
5616
5623
print " <div class=\" page_body\" >\n " ;
5617
5624
if ($mimetype =~ m ! ^image/! ) {
5618
- print qq! <img type="$mimetype "! ;
5625
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5619
5626
if ($file_name ) {
5620
- print qq! alt="$file_name " title="$file_name "! ;
5627
+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
5621
5628
}
5622
5629
print qq! src="! .
5623
5630
href(action => " blob_plain" , hash => $hash ,
@@ -5630,7 +5637,7 @@ sub git_blob {
5630
5637
$nr ++;
5631
5638
$line = untabify($line );
5632
5639
printf qq! <div class="pre"><a id="l%i " href="%s #l%i " class="linenr">%4i</a> %s </div>\n ! ,
5633
- $nr , href(-replay => 1), $nr , $nr , $syntax ? $line : esc_html($line , -nbsp => 1);
5640
+ $nr , esc_attr( href(-replay => 1) ), $nr , $nr , $syntax ? $line : esc_html($line , -nbsp => 1);
5634
5641
}
5635
5642
}
5636
5643
close $fd
@@ -5692,7 +5699,7 @@ sub git_tree {
5692
5699
undef $hash_base ;
5693
5700
print " <div class=\" page_nav\" >\n " ;
5694
5701
print " <br/><br/></div>\n " ;
5695
- print " <div class=\" title\" >$hash </div>\n " ;
5702
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5696
5703
}
5697
5704
if (defined $file_name ) {
5698
5705
$basedir = $file_name ;
@@ -6160,7 +6167,7 @@ sub git_blobdiff {
6160
6167
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
6161
6168
} else {
6162
6169
print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
6163
- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
6170
+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
6164
6171
}
6165
6172
if (defined $file_name ) {
6166
6173
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments