@@ -132,6 +132,10 @@ BEGIN
132132# - one might want to include '-B' option, e.g. '-B', '-M'
133133our @diff_opts = (' -M' ); # taken from git_commit
134134
135+ # Disables features that would allow repository owners to inject script into
136+ # the gitweb domain.
137+ our $prevent_xss = 0;
138+
135139# information about snapshot formats that gitweb is capable of serving
136140our %known_snapshot_formats = (
137141 # name => {
@@ -4503,7 +4507,9 @@ sub git_summary {
45034507
45044508 print " </table>\n " ;
45054509
4506- if (-s " $projectroot /$project /README.html" ) {
4510+ # If XSS prevention is on, we don't include README.html.
4511+ # TODO: Allow a readme in some safe format.
4512+ if (!$prevent_xss && -s " $projectroot /$project /README.html" ) {
45074513 print " <div class=\" title\" >readme</div>\n " .
45084514 " <div class=\" readme\" >\n " ;
45094515 insert_file(" $projectroot /$project /README.html" );
@@ -4764,10 +4770,21 @@ sub git_blob_plain {
47644770 $save_as .= ' .txt' ;
47654771 }
47664772
4773+ # With XSS prevention on, blobs of all types except a few known safe
4774+ # ones are served with "Content-Disposition: attachment" to make sure
4775+ # they don't run in our security domain. For certain image types,
4776+ # blob view writes an <img> tag referring to blob_plain view, and we
4777+ # want to be sure not to break that by serving the image as an
4778+ # attachment (though Firefox 3 doesn't seem to care).
4779+ my $sandbox = $prevent_xss &&
4780+ $type !~ m ! ^(?:text/plain|image/(?:gif|png|jpeg))$ ! ;
4781+
47674782 print $cgi -> header(
47684783 -type => $type ,
47694784 -expires => $expires ,
4770- -content_disposition => ' inline; filename="' . $save_as . ' "' );
4785+ -content_disposition =>
4786+ ($sandbox ? ' attachment' : ' inline' )
4787+ . ' ; filename="' . $save_as . ' "' );
47714788 undef $/ ;
47724789 binmode STDOUT , ' :raw' ;
47734790 print <$fd >;
0 commit comments