Skip to content

Commit df487ba

Browse files
committed
Merge branch 'maint'
* maint: gitweb: add $prevent_xss option to prevent XSS by repository content rev-list: fix showing distance when using --bisect-all
2 parents a9ee90d + 7e1100e commit df487ba

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

builtin-rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
608608
if (!strcmp(arg, "--bisect-all")) {
609609
bisect_list = 1;
610610
bisect_find_all = 1;
611+
revs.show_decorations = 1;
611612
continue;
612613
}
613614
if (!strcmp(arg, "--bisect-vars")) {

gitweb/README

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ not include variables usually directly set during build):
212212
Rename detection options for git-diff and git-diff-tree. By default
213213
('-M'); set it to ('-C') or ('-C', '-C') to also detect copies, or
214214
set it to () if you don't want to have renames detection.
215+
* $prevent_xss
216+
If true, some gitweb features are disabled to prevent content in
217+
repositories from launching cross-site scripting (XSS) attacks. Set this
218+
to true if you don't trust the content of your repositories. The default
219+
is false.
215220

216221

217222
Projects list file format
@@ -258,7 +263,9 @@ You can use the following files in repository:
258263
A .html file (HTML fragment) which is included on the gitweb project
259264
summary page inside <div> block element. You can use it for longer
260265
description of a project, to provide links (for example to project's
261-
homepage), etc.
266+
homepage), etc. This is recognized only if XSS prevention is off
267+
($prevent_xss is false); a way to include a readme safely when XSS
268+
prevention is on may be worked out in the future.
262269
* description (or gitweb.description)
263270
Short (shortened by default to 25 characters in the projects list page)
264271
single line description of a project (of a repository). Plain text file;

gitweb/gitweb.perl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ BEGIN
132132
# - one might want to include '-B' option, e.g. '-B', '-M'
133133
our @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
136140
our %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

Comments
 (0)