]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Serve text/* 'blob_plain' as text/plain with $prevent_xss
authorJakub Narebski <redacted>
Thu, 30 Jun 2011 09:39:20 +0000 (11:39 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:31 +0000 (00:51 -0400)
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 8c8c293301f4a9f2ee6a4da049880e256d5dead157c17239a6de10eb11997f5b..7f36502356047aaa2f11e7aad8ac3acd22f728ae0befc59604d8e711ba74f01b 100755 (executable)
@@ -6359,7 +6359,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,
This page took 0.332896 seconds and 4 git commands to generate.