Commit 211464d9 authored by David Lawrence's avatar David Lawrence

Bug 1090275: WebServices modules should maintain a whitelist of methods that are…

Bug 1090275: WebServices modules should maintain a whitelist of methods that are allowed instead of allowing access to any function imported into its namespace r=dylan,a=glob
parent 19117cc3
...@@ -27,6 +27,10 @@ use constant LOGIN_EXEMPT => { }; ...@@ -27,6 +27,10 @@ use constant LOGIN_EXEMPT => { };
# Methods that can modify data MUST not be listed here. # Methods that can modify data MUST not be listed here.
use constant READ_ONLY => (); 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 { sub login_exempt {
my ($class, $method) = @_; my ($class, $method) = @_;
return $class->LOGIN_EXEMPT->{$method}; return $class->LOGIN_EXEMPT->{$method};
......
...@@ -62,6 +62,27 @@ use constant READ_ONLY => qw( ...@@ -62,6 +62,27 @@ use constant READ_ONLY => qw(
search search
); );
use constant PUBLIC_METHODS => qw(
add_attachment
add_comment
attachments
comments
create
fields
get
history
legal_values
possible_duplicates
render_comment
search
search_comment_tags
update
update_attachment
update_comment_tags
update_see_also
update_tags
);
use constant ATTACHMENT_MAPPED_SETTERS => { use constant ATTACHMENT_MAPPED_SETTERS => {
file_name => 'filename', file_name => 'filename',
summary => 'description', summary => 'description',
......
...@@ -18,6 +18,11 @@ use Bugzilla::Error; ...@@ -18,6 +18,11 @@ use Bugzilla::Error;
use Bugzilla::WebService::Util qw( validate filter ); use Bugzilla::WebService::Util qw( validate filter );
use Bugzilla::Constants; use Bugzilla::Constants;
use constant PUBLIC_METHODS => qw(
get
update
);
sub update { sub update {
my ($self, $params) = validate(@_, 'ids'); my ($self, $params) = validate(@_, 'ids');
my $user = Bugzilla->user; my $user = Bugzilla->user;
......
...@@ -34,6 +34,15 @@ use constant READ_ONLY => qw( ...@@ -34,6 +34,15 @@ use constant READ_ONLY => qw(
version version
); );
use constant PUBLIC_METHODS => qw(
extensions
last_audit_time
parameters
time
timezone
version
);
# Logged-out users do not need to know more than that. # Logged-out users do not need to know more than that.
use constant PARAMETERS_LOGGED_OUT => qw( use constant PARAMETERS_LOGGED_OUT => qw(
maintainer maintainer
......
...@@ -21,6 +21,10 @@ use constant READ_ONLY => qw( ...@@ -21,6 +21,10 @@ use constant READ_ONLY => qw(
get get
); );
use constant PUBLIC_METHODS => qw(
get
);
sub get { sub get {
my ($self, $params) = validate(@_, 'names', 'ids'); my ($self, $params) = validate(@_, 'names', 'ids');
......
...@@ -19,6 +19,10 @@ use Bugzilla::Error; ...@@ -19,6 +19,10 @@ use Bugzilla::Error;
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
use Bugzilla::WebService::Util qw(translate params_to_objects validate); use Bugzilla::WebService::Util qw(translate params_to_objects validate);
use constant PUBLIC_METHODS => qw(
create
);
use constant MAPPED_FIELDS => { use constant MAPPED_FIELDS => {
default_assignee => 'initialowner', default_assignee => 'initialowner',
default_qa_contact => 'initialqacontact', default_qa_contact => 'initialqacontact',
......
...@@ -21,6 +21,12 @@ use Bugzilla::Util qw(trim); ...@@ -21,6 +21,12 @@ use Bugzilla::Util qw(trim);
use List::MoreUtils qw(uniq); use List::MoreUtils qw(uniq);
use constant PUBLIC_METHODS => qw(
create
get
update
);
sub get { sub get {
my ($self, $params) = @_; my ($self, $params) = @_;
my $dbh = Bugzilla->switch_to_shadow_db(); my $dbh = Bugzilla->switch_to_shadow_db();
......
...@@ -16,6 +16,12 @@ use Bugzilla::Constants; ...@@ -16,6 +16,12 @@ use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Util qw(validate translate params_to_objects); use Bugzilla::WebService::Util qw(validate translate params_to_objects);
use constant PUBLIC_METHODS => qw(
create
get
update
);
use constant MAPPED_RETURNS => { use constant MAPPED_RETURNS => {
userregexp => 'user_regexp', userregexp => 'user_regexp',
isactive => 'is_active' isactive => 'is_active'
......
...@@ -26,6 +26,15 @@ use constant READ_ONLY => qw( ...@@ -26,6 +26,15 @@ use constant READ_ONLY => qw(
get_selectable_products get_selectable_products
); );
use constant PUBLIC_METHODS => qw(
create
get
get_accessible_products
get_enterable_products
get_selectable_products
update
);
use constant MAPPED_FIELDS => { use constant MAPPED_FIELDS => {
has_unconfirmed => 'allows_unconfirmed', has_unconfirmed => 'allows_unconfirmed',
is_open => 'is_active', is_open => 'is_active',
......
...@@ -31,6 +31,7 @@ use Bugzilla::Util; ...@@ -31,6 +31,7 @@ use Bugzilla::Util;
use HTTP::Message; use HTTP::Message;
use MIME::Base64 qw(decode_base64 encode_base64); use MIME::Base64 qw(decode_base64 encode_base64);
use List::MoreUtils qw(none);
##################################### #####################################
# Public JSON::RPC Method Overrides # # Public JSON::RPC Method Overrides #
...@@ -404,6 +405,11 @@ sub _argument_type_check { ...@@ -404,6 +405,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. # This is the best time to do login checks.
$self->handle_login(); $self->handle_login();
......
...@@ -20,8 +20,11 @@ if ($ENV{MOD_PERL}) { ...@@ -20,8 +20,11 @@ if ($ENV{MOD_PERL}) {
} }
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
use Bugzilla::Error;
use Bugzilla::Util; use Bugzilla::Util;
use List::MoreUtils qw(none);
BEGIN { BEGIN {
# Allow WebService methods to call XMLRPC::Lite's type method directly # Allow WebService methods to call XMLRPC::Lite's type method directly
*Bugzilla::WebService::type = sub { *Bugzilla::WebService::type = sub {
...@@ -96,6 +99,14 @@ sub handle_login { ...@@ -96,6 +99,14 @@ sub handle_login {
my ($self, $classes, $action, $uri, $method) = @_; my ($self, $classes, $action, $uri, $method) = @_;
my $class = $classes->{$uri}; my $class = $classes->{$uri};
my $full_method = $uri . "." . $method; 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); $self->SUPER::handle_login($class, $method, $full_method);
return; return;
} }
......
...@@ -32,6 +32,16 @@ use constant READ_ONLY => qw( ...@@ -32,6 +32,16 @@ use constant READ_ONLY => qw(
get get
); );
use constant PUBLIC_METHODS => qw(
create
get
login
logout
offer_account_by_email
update
valid_login
);
use constant MAPPED_FIELDS => { use constant MAPPED_FIELDS => {
email => 'login', email => 'login',
full_name => 'name', full_name => 'name',
......
...@@ -13,6 +13,11 @@ use warnings; ...@@ -13,6 +13,11 @@ use warnings;
use parent qw(Bugzilla::WebService); use parent qw(Bugzilla::WebService);
use Bugzilla::Error; use Bugzilla::Error;
use constant PUBLIC_METHODS => qw(
hello
throw_an_error
);
# This can be called as Example.hello() from the WebService. # This can be called as Example.hello() from the WebService.
sub hello { return 'Hello!'; } sub hello { return 'Hello!'; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment