gitweb: Serve text/* 'blob_plain' as text/plain with $prevent_xss
[gitweb.git] / gitweb / gitweb.perl
index c5548875ffd6e7d1afd7567688427c00580c3ef2..1b97172ca8800413097b3079cf357e9c327dc53f 100755 (executable)
@@ -4752,7 +4752,15 @@ sub git_blob_plain {
        # want to be sure not to break that by serving the image as an
        # attachment (though Firefox 3 doesn't seem to care).
        my $sandbox = $prevent_xss &&
-               $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))(?:[ ;]|$)!;
+               $type !~ m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;
+
+       # serve text/* as text/plain
+       if ($prevent_xss &&
+           $type =~ m!^text/[a-z]+\b(.*)$!) {
+               my $rest = $1;
+               $rest = defined $rest ? $rest : '';
+               $type = "text/plain$rest";
+       }
 
        print $cgi->header(
                -type => $type,