]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1139755: Allow API authentication with X-Headers
authorByron Jones <glob@mozilla.com>
Mon, 9 Mar 2015 06:29:44 +0000 (14:29 +0800)
committerByron Jones <glob@mozilla.com>
Mon, 9 Mar 2015 06:29:44 +0000 (14:29 +0800)
r=dkl,a=glob

Bugzilla/WebService/Server/JSONRPC.pm
Bugzilla/WebService/Server/REST.pm
Bugzilla/WebService/Util.pm

index 70b8fd96c5e4cc8423f1f196c50f986981d6157b..2b5c7ec9b2eeb9c0f2c06cc0fb8f4edf4a04ab37 100644 (file)
@@ -379,7 +379,7 @@ sub _argument_type_check {
 
     # Update the params to allow for several convenience key/values
     # use for authentication
-    fix_credentials($params);
+    fix_credentials($params, $self->cgi);
 
     Bugzilla->input_params($params);
 
index 940045b26c7df2609587524c86a651a39bf69936..d02ba5523a1fdd6eca49cea1986924e42e1279eb 100644 (file)
@@ -76,7 +76,7 @@ sub handle {
 
     my $params = $self->_retrieve_json_params;
 
-    fix_credentials($params);
+    fix_credentials($params, $self->cgi);
 
     # Fix includes/excludes for each call
     rest_include_exclude($params);
index a0a51a8de23fb84cdf9d263cf939f6c6fc538fbb..5d7dd7dd67ecf2707b62c986541c08c822c5ba51 100644 (file)
@@ -16,6 +16,7 @@ use Bugzilla::FlagType;
 use Bugzilla::Error;
 
 use Storable qw(dclone);
+use URI::Escape qw(uri_unescape);
 
 use parent qw(Exporter);
 
@@ -260,8 +261,25 @@ sub params_to_objects {
     return \@objects;
 }
 
+use constant X_HEADERS => {
+    X_BUGZILLA_LOGIN    => 'Bugzilla_login',
+    X_BUGZILLA_PASSWORD => 'Bugzilla_password',
+    X_BUGZILLA_API_KEY  => 'Bugzilla_api_key',
+    X_BUGZILLA_TOKEN    => 'Bugzilla_token',
+};
+
 sub fix_credentials {
-    my ($params) = @_;
+    my ($params, $cgi) = @_;
+
+    # Allow user to pass in authentication details in X-Headers
+    # This allows callers to keep credentials out of GET request query-strings
+    if ($cgi) {
+        foreach my $field (keys %{ X_HEADERS() }) {
+            next if exists $params->{X_HEADERS->{$field}} || $cgi->http($field) eq '';
+            $params->{X_HEADERS->{$field}} = uri_unescape($cgi->http($field));
+        }
+    }
+
     # Allow user to pass in login=foo&password=bar as a convenience
     # even if not calling GET /login. We also do not delete them as
     # GET /login requires "login" and "password".