gitweb: Serve text/* 'blob_plain' as text/plain with $prevent_xss
One of mechanism enabled by setting $prevent_xss to true is 'blob_plain' view protection. With XSS prevention on, blobs of all types except a few known safe ones are served with "Content-Disposition: attachment" to make sure they don't run in our security domain. Instead of serving text/* type files, except text/plain (and including text/html), as attachements, downgrade it to text/plain. This way HTML pages in 'blob_plain' (raw) view would be displayed in browser, but safely as a source, and not asked to be saved. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jakub Narebski committed
Jun 30, 2011 at 11:39 UTC
86afbd02c890eca08424174b7d6e583af38b0363
1 file changed
+9
-1
gitweb/gitweb.perl
+9
-1
@@ -4752,7 +4752,15 @@ sub git_blob_plain {
4752
# want to be sure not to break that by serving the image as an
4753
# attachment (though Firefox 3 doesn't seem to care).
4754
my $sandbox = $prevent_xss &&
4755
- $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))(?:[ ;]|$)!;
4755
+ $type !~ m!^(?:text/[a-z]+|image/(?:gif|png|jpeg))(?:[ ;]|$)!;
4756
+
4757
+ # serve text/* as text/plain
4758
+ if ($prevent_xss &&
4759
+ $type =~ m!^text/[a-z]+\b(.*)$!) {
4760
+ my $rest = $1;
4761
+ $rest = defined $rest ? $rest : '';
4762
+ $type = "text/plain$rest";
4763
+ }
4764
4765
print $cgi->header(
4766
-type => $type,