From e2252835e8e96371d6536af5dbd72a79e6ed05b5 Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Thu, 12 May 2005 09:07:09 +0000 Subject: Bug 287109: [SECURITY] Names of private products/components can be exposed on certain CGIs Patch By Frederic Buclin r=myk, r=joel, a=justdave --- globals.pl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'globals.pl') diff --git a/globals.pl b/globals.pl index d0e819f02..009f93ee9 100644 --- a/globals.pl +++ b/globals.pl @@ -436,12 +436,16 @@ sub IsInClassification { } } -# -# This function determines if a user can enter bugs in the named -# product. +# This function determines whether or not a user can enter +# bugs into the named product. sub CanEnterProduct { - my ($productname) = @_; + my ($productname, $verbose) = @_; my $dbh = Bugzilla->dbh; + + return unless defined($productname); + trick_taint($productname); + + # First check whether or not the user has access to that product. my $query = "SELECT group_id IS NULL " . "FROM products " . "LEFT JOIN group_control_map " . @@ -451,13 +455,53 @@ sub CanEnterProduct { $query .= "AND group_id NOT IN(" . join(',', values(%{Bugzilla->user->groups})) . ") "; } - $query .= "WHERE products.name = " . SqlQuote($productname) . " " . + $query .= "WHERE products.name = ? " . $dbh->sql_limit(1); - PushGlobalSQLState(); - SendSQL($query); - my ($ret) = FetchSQLData(); - PopGlobalSQLState(); - return ($ret); + + my $has_access = $dbh->selectrow_array($query, undef, $productname); + if (!$has_access) { + # Do we require the exact reason why we cannot enter + # bugs into that product? Returning -1 explicitely + # means the user has no access to the product or the + # product does not exist. + return (defined($verbose)) ? -1 : 0; + } + + # Check if the product is open for new bugs and has + # at least one component. + my $allow_new_bugs = + $dbh->selectrow_array("SELECT CASE WHEN disallownew = 0 THEN 1 ELSE 0 END + FROM products INNER JOIN components + ON components.product_id = products.id + WHERE products.name = ? " . + $dbh->sql_limit(1), + undef, $productname); + + # Return 1 if the user can enter bugs into that product; + # return 0 if the product is closed for new bug entry; + # return undef if the product has no component. + return $allow_new_bugs; +} + +# Call CanEnterProduct() and display an error message +# if the user cannot enter bugs into that product. +sub CanEnterProductOrWarn { + my ($product) = @_; + + if (!defined($product)) { + ThrowUserError("no_products"); + } + my $status = CanEnterProduct($product, 1); + trick_taint($product); + + if (!defined($status)) { + ThrowUserError("no_components", { product => $product}); + } elsif (!$status) { + ThrowUserError("product_disabled", { product => $product}); + } elsif ($status < 0) { + ThrowUserError("entry_access_denied", { product => $product}); + } + return $status; } sub GetEnterableProducts { -- cgit v1.2.3-24-g4f1b