]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/remotesubscribe.php
allow doc and api calls from private
[quix0rs-gnu-social.git] / actions / remotesubscribe.php
index 407c5babbe4938bd5a4e2eb2098fd4e64ede6cb2..0adcc08481a30038f6d2c6ec139bce3350e22776 100644 (file)
@@ -33,6 +33,14 @@ class RemotesubscribeAction extends Action {
                }
 
                if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+                       
+                       # CSRF protection
+                       $token = $this->trimmed('token');
+                       if (!$token || $token != common_session_token()) {
+                               $this->show_form(_('There was a problem with your session token. Try again, please.'));
+                               return;
+                       }
+                       
                        $this->remote_subscription();
                } else {
                        $this->show_form();
@@ -68,6 +76,7 @@ class RemotesubscribeAction extends Action {
                # button on profile page
                common_element_start('form', array('id' => 'remsub', 'method' => 'post',
                                                                                   'action' => common_local_url('remotesubscribe')));
+               common_hidden('token', common_session_token());
                common_input('nickname', _('User nickname'), $nickname,
                                         _('Nickname of the user you want to follow'));
                common_input('profile_url', _('Profile URL'), $profile,
@@ -121,6 +130,18 @@ class RemotesubscribeAction extends Action {
                        return;
                }
 
+               if (omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]) ==
+                       common_local_url('requesttoken'))
+               {
+                       $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+                       return;
+               }
+
+               if (User::staticGet('uri', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]))) {
+                       $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+                       return;
+               }
+               
                list($token, $secret) = $this->request_token($omb);
 
                if (!$token || !$secret) {
@@ -304,7 +325,14 @@ class RemotesubscribeAction extends Action {
                $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname));
                $req->set_parameter('omb_listenee_nickname', $user->nickname);
                $req->set_parameter('omb_listenee_license', $config['license']['url']);
+
                $profile = $user->getProfile();
+               if (!$profile) {
+                       common_log_db_error($user, 'SELECT', __FILE__);
+                       $this->server_error(_('User without matching profile'));
+                       return;
+               }
+               
                if ($profile->fullname) {
                        $req->set_parameter('omb_listenee_fullname', $profile->fullname);
                }