@matheusbsbs / matheus-bagliano / commits / a2f3db2f5d
Fork 0

gitweb: Consolidate escaping/validation of query string

Consider: http://repo.or.cz/?p=glibc-cvs.git;a=tree;h=2609cb0411389325f4ee2854cc7159756eb0671e;hb=2609cb0411389325f4ee2854cc7159756eb0671e (click on the funny =__ify file) We ought to handle anything in filenames and I actually see no reason why we don't, modulo very little missing escaping that this patch hopefully also fixes. I have also made esc_param() escape [?=&;]. Not escaping [&;] was downright buggy and [?=] just feels better escaped. ;-) YMMV. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Sep 24, 2006 at 00:18 UTC a2f3db2f5de2a3667b0e038aa65e3e097e642e7d
1 file changed +11 -21
gitweb/gitweb.perl
+11 -21
@@ -212,19 +212,9 @@ if (defined $project) {
212 }
213 }
214
215 +# We have to handle those containing any characters:
216 our $file_name = $cgi->param('f');
216 -if (defined $file_name) {
217 - if (!validate_input($file_name)) {
218 - die_error(undef, "Invalid file parameter");
219 - }
220 -}
221 -
217 our $file_parent = $cgi->param('fp');
223 -if (defined $file_parent) {
224 - if (!validate_input($file_parent)) {
225 - die_error(undef, "Invalid file parent parameter");
226 - }
227 -}
218
219 our $hash = $cgi->param('h');
220 if (defined $hash) {
@@ -305,7 +295,7 @@ sub evaluate_path_info {
295 $action ||= "blob_plain";
296 }
297 $hash_base ||= validate_input($refname);
308 - $file_name ||= validate_input($pathname);
298 + $file_name ||= $pathname;
299 } elsif (defined $refname) {
300 # we got "project.git/branch"
301 $action ||= "shortlog";
@@ -416,7 +406,7 @@ sub validate_input {
406 # correct, but quoted slashes look too horrible in bookmarks
407 sub esc_param {
408 my $str = shift;
419 - $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
409 + $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf("%%%02X", ord($1))/eg;
410 $str =~ s/\+/%2B/g;
411 $str =~ s/ /\+/g;
412 return $str;
@@ -1282,7 +1272,7 @@ sub git_header_html {
1272 if (defined $action) {
1273 $title .= "/$action";
1274 if (defined $file_name) {
1285 - $title .= " - $file_name";
1275 + $title .= " - " . esc_html($file_name);
1276 if ($action eq "tree" && $file_name !~ m|/$|) {
1277 $title .= "/";
1278 }
@@ -2430,7 +2420,7 @@ sub git_blame2 {
2420 if ($ftype !~ "blob") {
2421 die_error("400 Bad Request", "Object is not a blob");
2422 }
2433 - open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base)
2423 + open ($fd, "-|", git_cmd(), "blame", '-l', '--', $file_name, $hash_base)
2424 or die_error(undef, "Open git-blame failed");
2425 git_header_html();
2426 my $formats_nav =
@@ -3072,12 +3062,12 @@ sub git_blobdiff {
3062 if (defined $file_name) {
3063 if (defined $file_parent) {
3064 $diffinfo{'status'} = '2';
3075 - $diffinfo{'from_file'} = $file_parent;
3076 - $diffinfo{'to_file'} = $file_name;
3065 + $diffinfo{'from_file'} = esc_html($file_parent);
3066 + $diffinfo{'to_file'} = esc_html($file_name);
3067 } else { # assume not renamed
3068 $diffinfo{'status'} = '1';
3079 - $diffinfo{'from_file'} = $file_name;
3080 - $diffinfo{'to_file'} = $file_name;
3069 + $diffinfo{'from_file'} = esc_html($file_name);
3070 + $diffinfo{'to_file'} = esc_html($file_name);
3071 }
3072 } else { # no filename given
3073 $diffinfo{'status'} = '2';
@@ -3126,7 +3116,7 @@ sub git_blobdiff {
3116 -type => 'text/plain',
3117 -charset => 'utf-8',
3118 -expires => $expires,
3129 - -content_disposition => qq(inline; filename="${file_name}.patch"));
3119 + -content_disposition => qq(inline; filename=") . quotemeta($file_name) . qq(.patch"));
3120
3121 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3122
@@ -3576,7 +3566,7 @@ XML
3566 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3567 next;
3568 }
3579 - my $file = validate_input(unquote($7));
3569 + my $file = esc_html(unquote($7));
3570 $file = decode("utf8", $file, Encode::FB_DEFAULT);
3571 print "$file<br/>\n";
3572 }