@@ -1137,6 +1137,13 @@ sub esc_url {
1137
1137
return $str ;
1138
1138
}
1139
1139
1140
+ # quote unsafe characters in HTML attributes
1141
+ sub esc_attr {
1142
+
1143
+ # for XHTML conformance escaping '"' to '"' is not enough
1144
+ return esc_html(@_ );
1145
+ }
1146
+
1140
1147
# replace invalid utf8 character with SUBSTITUTION sequence
1141
1148
sub esc_html {
1142
1149
my $str = shift ;
@@ -1542,7 +1549,7 @@ sub format_ref_marker {
1542
1549
hash => $dest
1543
1550
)}, $name );
1544
1551
1545
- $markers .= " <span class=\" $class \" title=\" $ref \" >" .
1552
+ $markers .= " <span class=\" " .esc_attr( $class ). " \" title=\" " .esc_attr( $ref ). " \" >" .
1546
1553
$link . " </span>" ;
1547
1554
}
1548
1555
}
@@ -1626,7 +1633,7 @@ sub git_get_avatar {
1626
1633
return $pre_white .
1627
1634
" <img width=\" $size \" " .
1628
1635
" class=\" avatar\" " .
1629
- " src=\" $url \" " .
1636
+ " src=\" " .esc_url( $url ). " \" " .
1630
1637
" alt=\"\" " .
1631
1638
" />" . $post_white ;
1632
1639
} else {
@@ -2335,7 +2342,7 @@ sub git_show_project_tagcloud {
2335
2342
} else {
2336
2343
my @tags = sort { $cloud -> {$a }-> {count } <=> $cloud -> {$b }-> {count } } keys %$cloud ;
2337
2344
return ' <p align="center">' . join (' , ' , map {
2338
- " <a href=\ "$home_link ?by_tag=$_ \" > $cloud ->{$_ }->{topname}</a> "
2345
+ $cgi -> a({- href => " $home_link ?by_tag=$_ " }, $cloud -> {$_ }-> {topname })
2339
2346
} splice (@tags , 0, $count )) . ' </p>' ;
2340
2347
}
2341
2348
}
@@ -3166,11 +3173,11 @@ sub git_header_html {
3166
3173
# print out each stylesheet that exist, providing backwards capability
3167
3174
# for those people who defined $stylesheet in a config file
3168
3175
if (defined $stylesheet ) {
3169
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3176
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3170
3177
} else {
3171
3178
foreach my $stylesheet (@stylesheets ) {
3172
3179
next unless $stylesheet ;
3173
- print ' <link rel="stylesheet" type="text/css" href="' .$stylesheet .' "/>' ." \n " ;
3180
+ print ' <link rel="stylesheet" type="text/css" href="' .esc_url( $stylesheet ) .' "/>' ." \n " ;
3174
3181
}
3175
3182
}
3176
3183
if (defined $project ) {
@@ -3183,7 +3190,7 @@ sub git_header_html {
3183
3190
my $type = lc ($format );
3184
3191
my %link_attr = (
3185
3192
' -rel' => ' alternate' ,
3186
- ' -title' => " $project - $href_params {'-title'} - $format feed" ,
3193
+ ' -title' => esc_attr( " $project - $href_params {'-title'} - $format feed" ) ,
3187
3194
' -type' => " application/$type +xml"
3188
3195
);
3189
3196
@@ -3210,13 +3217,13 @@ sub git_header_html {
3210
3217
} else {
3211
3218
printf (' <link rel="alternate" title="%s projects list" ' .
3212
3219
' href="%s" type="text/plain; charset=utf-8" />' ." \n " ,
3213
- $site_name , href(project => undef , action => " project_index" ));
3220
+ esc_attr( $site_name ) , href(project => undef , action => " project_index" ));
3214
3221
printf (' <link rel="alternate" title="%s projects feeds" ' .
3215
3222
' href="%s" type="text/x-opml" />' ." \n " ,
3216
- $site_name , href(project => undef , action => " opml" ));
3223
+ esc_attr( $site_name ) , href(project => undef , action => " opml" ));
3217
3224
}
3218
3225
if (defined $favicon ) {
3219
- print qq( <link rel="shortcut icon" href="$favicon " type="image/png" />\n ) ;
3226
+ print qq( <link rel="shortcut icon" href=") .esc_url( $favicon ). qq( " type="image/png" />\n ) ;
3220
3227
}
3221
3228
3222
3229
print " </head>\n " .
@@ -3229,7 +3236,7 @@ sub git_header_html {
3229
3236
print " <div class=\" page_header\" >\n " .
3230
3237
$cgi -> a({-href => esc_url($logo_url ),
3231
3238
-title => $logo_label },
3232
- qq( <img src="$logo " width="72" height="27" alt="git" class="logo"/>) );
3239
+ qq( <img src=") .esc_url( $logo ). qq( " width="72" height="27" alt="git" class="logo"/>) );
3233
3240
print $cgi -> a({-href => esc_url($home_link )}, $home_link_str ) . " / " ;
3234
3241
if (defined $project ) {
3235
3242
print $cgi -> a({-href => href(action => " summary" )}, esc_html($project ));
@@ -3327,7 +3334,7 @@ sub git_footer_html {
3327
3334
insert_file($site_footer );
3328
3335
}
3329
3336
3330
- print qq! <script type="text/javascript" src="$javascript "></script>\n ! ;
3337
+ print qq! <script type="text/javascript" src="! .esc_url( $javascript ). qq! "></script>\n ! ;
3331
3338
if ($action eq ' blame_incremental' ) {
3332
3339
print qq! <script type="text/javascript">\n ! .
3333
3340
qq! startBlame("! . href(action => " blame_data" , -replay => 1) .qq! ",\n ! .
@@ -5313,14 +5320,14 @@ sub git_blob {
5313
5320
} else {
5314
5321
print " <div class=\" page_nav\" >\n " .
5315
5322
" <br/><br/></div>\n " .
5316
- " <div class=\" title\" >$hash </div>\n " ;
5323
+ " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5317
5324
}
5318
5325
git_print_page_path($file_name , " blob" , $hash_base );
5319
5326
print " <div class=\" page_body\" >\n " ;
5320
5327
if ($mimetype =~ m ! ^image/! ) {
5321
- print qq! <img type="$mimetype "! ;
5328
+ print qq! <img type="! .esc_attr( $mimetype ). qq! "! ;
5322
5329
if ($file_name ) {
5323
- print qq! alt="$file_name " title="$file_name "! ;
5330
+ print qq! alt="! .esc_attr( $file_name ). qq! " title="! .esc_attr( $file_name ). qq! "! ;
5324
5331
}
5325
5332
print qq! src="! .
5326
5333
href(action => " blob_plain" , hash => $hash ,
@@ -5332,7 +5339,8 @@ sub git_blob {
5332
5339
chomp $line ;
5333
5340
$nr ++;
5334
5341
$line = untabify($line );
5335
- printf " <div class=\" pre\" ><a id=\" l%i \" href=\" " . href(-replay => 1)
5342
+ printf " <div class=\" pre\" ><a id=\" l%i \" href=\" "
5343
+ . esc_attr(href(-replay => 1))
5336
5344
. " #l%i \" class=\" linenr\" >%4i</a> %s </div>\n " ,
5337
5345
$nr , $nr , $nr , esc_html($line , -nbsp => 1);
5338
5346
}
@@ -5396,7 +5404,7 @@ sub git_tree {
5396
5404
undef $hash_base ;
5397
5405
print " <div class=\" page_nav\" >\n " ;
5398
5406
print " <br/><br/></div>\n " ;
5399
- print " <div class=\" title\" >$hash </div>\n " ;
5407
+ print " <div class=\" title\" >" .esc_html( $hash ). " </div>\n " ;
5400
5408
}
5401
5409
if (defined $file_name ) {
5402
5410
$basedir = $file_name ;
@@ -5864,7 +5872,7 @@ sub git_blobdiff {
5864
5872
git_print_header_div(' commit' , esc_html($co {' title' }), $hash_base );
5865
5873
} else {
5866
5874
print " <div class=\" page_nav\" ><br/>$formats_nav <br/></div>\n " ;
5867
- print " <div class=\" title\" >$hash vs $hash_parent </div>\n " ;
5875
+ print " <div class=\" title\" >" .esc_html( " $hash vs $hash_parent " ). " </div>\n " ;
5868
5876
}
5869
5877
if (defined $file_name ) {
5870
5878
git_print_page_path($file_name , " blob" , $hash_base );
0 commit comments