Skip to content

Commit 86afbd0

Browse files
jnarebgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bee6ea1 commit 86afbd0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gitweb/gitweb.perl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4752,7 +4752,15 @@ sub git_blob_plain {
47524752
# want to be sure not to break that by serving the image as an
47534753
# attachment (though Firefox 3 doesn't seem to care).
47544754
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+
}
47564764

47574765
print $cgi->header(
47584766
-type => $type,

0 commit comments

Comments
 (0)