]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1090275: WebServices modules should maintain a whitelist of methods that are...
authorDavid Lawrence <dkl@mozilla.com>
Wed, 21 Jan 2015 20:41:58 +0000 (20:41 +0000)
committerDavid Lawrence <dkl@mozilla.com>
Wed, 21 Jan 2015 20:41:58 +0000 (20:41 +0000)
r=dylan,a=glob

Bugzilla/WebService.pm
Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Bugzilla.pm
Bugzilla/WebService/Group.pm
Bugzilla/WebService/Product.pm
Bugzilla/WebService/Server/JSONRPC.pm
Bugzilla/WebService/Server/XMLRPC.pm
Bugzilla/WebService/User.pm
extensions/Example/lib/WebService.pm

index 16670762661c2427a90c283e734a5b087b15f727..610ca539c8ea9aa6e73b382db8eb4085604a2a54 100644 (file)
@@ -33,6 +33,10 @@ use constant LOGIN_EXEMPT => { };
 # Methods that can modify data MUST not be listed here.
 use constant READ_ONLY => ();
 
+# Whitelist of methods that a client is allowed to access when making
+# an API call.
+use constant PUBLIC_METHODS => ();
+
 sub login_exempt {
     my ($class, $method) = @_;
     return $class->LOGIN_EXEMPT->{$method};
index eb76b413194d9bae1f415da23e43269ace2f3ae3..76f688dbce2ddebf99f45889ae9e5a595cdde9e5 100644 (file)
@@ -64,6 +64,22 @@ use constant READ_ONLY => qw(
     search
 );
 
+use constant PUBLIC_METHODS => qw(
+    add_attachment
+    add_comment
+    attachments
+    comments
+    create
+    fields
+    get
+    history
+    legal_values
+    possible_duplicates
+    search
+    update
+    update_see_also
+);
+
 ######################################################
 # Add aliases here for old method name compatibility #
 ######################################################
index efc82231122ba151b94dbd212d343d63d9c050a5..f2acdbe7e5cffa9655427da4119a4b59ca2c19b6 100644 (file)
@@ -38,6 +38,13 @@ use constant READ_ONLY => qw(
     version
 );
 
+use constant PUBLIC_METHODS => qw(
+    extensions
+    time
+    timezone
+    version
+);
+
 sub version {
     my $self = shift;
     return { version => $self->type('string', BUGZILLA_VERSION) };
index 65feb7a1aaf008d5a5a14cf31632a912c18e491a..91ae16903ff80d64c9a27d13019c4006b8a54890 100644 (file)
@@ -22,6 +22,10 @@ use base qw(Bugzilla::WebService);
 use Bugzilla::Constants;
 use Bugzilla::Error;
 
+use constant PUBLIC_METHODS => qw(
+    create
+);
+
 sub create {
     my ($self, $params) = @_;
 
index 3cd0d0a6c04db8e63e3c7cce21ccd30d7b6ecb1b..a99755814ba4a1b28efbc2f579642556bca939b0 100644 (file)
@@ -34,6 +34,14 @@ use constant READ_ONLY => qw(
     get_selectable_products
 );
 
+use constant PUBLIC_METHODS => qw(
+    create
+    get
+    get_accessible_products
+    get_enterable_products
+    get_selectable_products
+);
+
 use constant FIELD_MAP => {
     has_unconfirmed => 'allows_unconfirmed',
     is_open         => 'isactive',
index 373aa4fe03851cba82e1cc495568fba7e99b63e5..f1b31cfd036a58199d9cb6e99a9f68a55cee4923 100644 (file)
@@ -42,6 +42,7 @@ use Bugzilla::Util qw(correct_urlbase trim disable_utf8);
 
 use HTTP::Message;
 use MIME::Base64 qw(decode_base64 encode_base64);
+use List::MoreUtils qw(none);
 
 #####################################
 # Public JSON::RPC Method Overrides #
@@ -388,6 +389,11 @@ sub _argument_type_check {
         }
     }
 
+    # Only allowed methods to be used from our whitelist
+    if (none { $_ eq $method} $pkg->PUBLIC_METHODS) {
+        ThrowUserError('unknown_method', { method => $self->bz_method_name });
+    }
+
     # This is the best time to do login checks.
     $self->handle_login();
 
index fc297421a20baaf1f64ed4f59132c94c15ceab19..da96df7dcaaa0ed3e61c226edb9e6fe68b8bb0ee 100644 (file)
@@ -30,6 +30,9 @@ if ($ENV{MOD_PERL}) {
 }
 
 use Bugzilla::WebService::Constants;
+use Bugzilla::Error;
+
+use List::MoreUtils qw(none);
 
 # Allow WebService methods to call XMLRPC::Lite's type method directly
 BEGIN {
@@ -78,6 +81,14 @@ sub handle_login {
     my ($self, $classes, $action, $uri, $method) = @_;
     my $class = $classes->{$uri};
     my $full_method = $uri . "." . $method;
+    # Only allowed methods to be used from the module's whitelist
+    my $file = $class;
+    $file =~ s{::}{/}g;
+    $file .= ".pm";
+    require $file;
+    if (none { $_ eq $method } $class->PUBLIC_METHODS) {
+        ThrowCodeError('unknown_method', { method => $full_method });
+    }
     $self->SUPER::handle_login($class, $method, $full_method);
     return;
 }
index deb7518ec83151eb76548de1921639d697daaa00..de3c4473fc07aa0b29000b119631ab3a6d1742f4 100644 (file)
@@ -40,6 +40,14 @@ use constant READ_ONLY => qw(
     get
 );
 
+use constant PUBLIC_METHODS => qw(
+    create
+    get
+    login
+    logout
+    offer_account_by_email
+);
+
 ##############
 # User Login #
 ##############
index 8563ec7f07f238c9ba09f6946d67b05f679690b3..bb83436e3ef295fb874e339d198956022eb5b196 100644 (file)
@@ -24,6 +24,11 @@ use warnings;
 use base qw(Bugzilla::WebService);
 use Bugzilla::Error;
 
+use constant PUBLIC_METHODS => qw(
+    hello
+    throw_an_error
+);
+
 # This can be called as Example.hello() from the WebService.
 sub hello { return 'Hello!'; }